Changeset 9969


Ignore:
Timestamp:
2005-05-26T13:31:30+12:00 (19 years ago)
Author:
jrm21
Message:

better error checking if an encoding conversion failed.

on !windows platforms, look at the locale to choose the best output
encoding.

File:
1 edited

Legend:

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

    r9362 r9969  
    102102
    103103    # If an 8-bit output encoding has been defined, encode the string appropriately
    104     return &unicode::unicode2singlebyte(&unicode::utf82unicode($utf8string), $outputencoding);
     104    my $encoded=unicode::unicode2singlebyte(&unicode::utf82unicode($utf8string), $outputencoding);
     105   
     106    # If we successfully encoded it, return it
     107    if ($encoded) { return $encoded }
     108
     109    # Otherwise, we can't convert to the requested encoding. return the utf8?
     110    $specialoutputencoding='utf8';
     111    return $utf8string;
    105112}
    106113
     
    123130    }
    124131    else {
     132    # see if there is an encoding set in the appropriate locale env var
     133
     134    foreach my $envvar ('LC_ALL', 'LANG') {
     135        if (!exists $ENV{$envvar}) { next }
     136        my $locale=$ENV{$envvar};
     137        if ($locale !~ /^\w+\.(.+)$/) { next }
     138        my $enc=lc($1);
     139        $enc =~ s/-/_/g;
     140        if ($enc eq 'utf_8') { $enc='utf8' } # normalise to this name
     141        $specialoutputencoding = $enc;
     142        return;
     143    }
    125144    $specialoutputencoding = $specialresourcebundle{"{OutputEncoding.unix}"};
    126145    }
Note: See TracChangeset for help on using the changeset viewer.