Ignore:
Timestamp:
1998-12-11T20:59:16+13:00 (25 years ago)
Author:
rjmcnab
Message:

Added support for UTF-8.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/doc.pm

    r65 r73  
    33package doc;
    44
     5use unicode;
    56use util;
    67use html;
     
    463464# are for metadata which can have more than one value.
    464465
     466# set_metadata_element assumes the value is in (extended) ascii form.
     467# For text which hash been already converted to the UTF-8 format use
     468# set_utf8_metadata_element.
    465469sub set_metadata_element {
    466470    my $self = shift (@_);
    467471    my ($section, $field, $value) = @_;
    468472
     473    $self->set_utf8_metadata_element ($section, $field,
     474                      &unicode::ascii2utf8($value));
     475}
     476
     477# set_utf8_metadata_element assumes the text has already been
     478# converted to the UTF-8 encoding.
     479sub set_utf8_metadata_element {
     480    my $self = shift (@_);
     481    my ($section, $field, $value) = @_;
     482
    469483    $self->delete_metadata ($section, $field);
    470     $self->add_metadata ($section, $field, $value);
     484    $self->add_utf8_metadata ($section, $field, $value);
    471485}
    472486
     
    491505}
    492506
     507# add_metadata assumes the text is in (extended) ascii form. For
     508# text which hash been already converted to the UTF-8 format use
     509# add_utf8_metadata.
    493510sub add_metadata {
    494511    my $self = shift (@_);
    495512    my ($section, $field, $value) = @_;
    496513
    497     my $section_ptr = $self->_lookup_section($section);
    498     if (!defined $section_ptr) {
    499     print STDERR "doc::add_metadata couldn't find section " .
     514    $self->add_utf8_metadata ($section, $field,
     515                  &unicode::ascii2utf8($value));
     516}
     517
     518# add_utf8_metadata assumes the text has already been converted
     519# to the UTF-8 encoding.
     520sub add_utf8_metadata {
     521    my $self = shift (@_);
     522    my ($section, $field, $value) = @_;
     523
     524    my $section_ptr = $self->_lookup_section($section);
     525    if (!defined $section_ptr) {
     526    print STDERR "doc::add_utf8_metadata couldn't find section " .
    500527        "$section\n";
    501528    return;
     
    618645# methods for dealing with text
    619646
     647# add_text assumes the text is in (extended) ascii form. For
     648# text which has been already converted to the UTF-8 format
     649# use add_utf8_text.
    620650sub add_text {
    621651    my $self = shift (@_);
    622652    my ($section, $text) = @_;
    623653
    624     my $section_ptr = $self->_lookup_section($section);
    625     if (!defined $section_ptr) {
    626     print STDERR "doc::add_text couldn't find section " .
     654    # convert the text to UTF-8 encoded unicode characters
     655    # and add the text
     656    $self->add_utf8_text($section, &unicode::ascii2utf8($text));
     657}
     658
     659
     660# add_utf8_text assumes the text to be added has already
     661# been converted to the UTF-8 encoding. For ascii text use
     662# add_text
     663sub add_utf8_text {
     664    my $self = shift (@_);
     665    my ($section, $text) = @_;
     666
     667    my $section_ptr = $self->_lookup_section($section);
     668    if (!defined $section_ptr) {
     669    print STDERR "doc::add_utf8_text couldn't find section " .
    627670        "$section\n";
    628671    return;
     
    647690}
    648691
    649 # returns the length of the text for a section
     692# returns the (utf-8 encoded) length of the text for a section
    650693sub get_text_length {
    651694    my $self = shift (@_);
Note: See TracChangeset for help on using the changeset viewer.