From a420ba2fd04bb2adce1c693fc8d296f332bdd95c Mon Sep 17 00:00:00 2001 From: Andreas Brachold Date: Sat, 8 Mar 2008 14:30:15 +0000 Subject: Charset UTF8 Support. Run 'xxvd --utf8' to use encoding utf8 as data charset. --- lib/Tools.pm | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'lib/Tools.pm') diff --git a/lib/Tools.pm b/lib/Tools.pm index a6e9e8c..44823cc 100644 --- a/lib/Tools.pm +++ b/lib/Tools.pm @@ -5,6 +5,10 @@ package Tools; use FindBin qw($RealBin); use lib sprintf("%s", $RealBin); use lib sprintf("%s/../lib", $RealBin); +use Locale::gettext qw/!gettext/; +use utf8; +#use encoding 'utf8'; +use Encode; use Data::Dumper; $Data::Dumper::Indent = 1; @@ -21,6 +25,8 @@ our $LOG = sub{ warn @_ }; our $BENCH = {}; our $LOGCALLB = sub{ }; our $DBH = {}; +our $LOCALE; +our $CHARSET; # PAL use 25, NTFS use 30 frames per seconds use constant FRAMESPERSECOND => 25; @@ -29,7 +35,7 @@ use constant FRAMESPERSECOND => 25; &getFromSocket &fields &load_file &save_file &tableUpdated &buildsearch &deleteDir &getip &convert &int &entities &reentities &bench &fmttime &getDataByTable &getDataById &getDataBySearch &getDataByFields &touch &url - &con_err &con_msg &text2frame &frame2hms); + &con_err &con_msg &text2frame &frame2hms &gettext &setcharset); # ------------------ @@ -624,7 +630,9 @@ sub entities { $s =~ s/>/>/g; $s =~ s//g; return $s; @@ -635,7 +643,9 @@ sub reentities { # ------------------ my $s = shift || return ''; - $s =~ s/\&\#x([a-fA-F0-9][a-fA-F0-9])\;/pack("C", hex($1))/eg; + if($CHARSET ne 'UTF-8') { + $s =~ s/\&\#x([a-fA-F0-9][a-fA-F0-9])\;/pack("C", hex($1))/eg; + } $s =~ s/&/&/g; $s =~ s/>/>/g; $s =~ s/</domain_raw("xxv"); + $LOCALE->codeset($CHARSET); + } + if($CHARSET eq 'UTF-8') { + return $LOCALE->get($text); + } else { + $text = $LOCALE->get($text); + return encode($CHARSET,$text); + } +} + 1; -- cgit v1.2.3