Changeset 2237


Ignore:
Timestamp:
2001-04-01T13:21:16+12:00 (23 years ago)
Author:
sjboddie
Message:

Added a unicode2koi8r function to unicode.pm (because I needed one). Should
really have a more generic unicode2otherstuff type function but I don't
need it right now and I'm too lazy to write it ;-)

File:
1 edited

Legend:

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

    r1870 r2237  
    421421}
    422422
     423sub unicode2koi8r {
     424    my ($uniref) = @_;
     425   
     426    my $outtext = "";
     427    my $encodename = "unicode-koi8_r";
     428    my $enc_info = $encodings::encodings->{"koi8_r"};
     429    my $mapfile = &util::filename_cat($ENV{'GSDLHOME'}, "mappings",
     430                      "from_uc", $enc_info->{'mapfile'});
     431    if (!&loadmapencoding ($encodename, $mapfile)) {
     432    print STDERR "unicode: ERROR - could not load encoding $encodename\n";
     433    return "";
     434    }
     435   
     436    foreach my $c (@$uniref) {
     437    if ($c < 0x80) {
     438        # normal ascii character
     439        $outtext .= chr($c);
     440    } else {
     441        # extended ascii character
     442        $c = &transchar ($encodename, $c);
     443
     444        # put a question mark if cannot translate
     445        if ($c == 0) {
     446        $outtext .= "?";
     447        } else {
     448        $outtext .= chr($c);
     449        }
     450    }
     451    }
     452    return $outtext;
     453}
     454
    4234551;
Note: See TracChangeset for help on using the changeset viewer.