From 8f6bf384c28276b6f05f9679e9a4e690bdc79803 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sun, 26 Sep 2010 18:59:53 +0200 Subject: Fix UTF-8 IO handling. --- localmarkdown2sms | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'localmarkdown2sms') diff --git a/localmarkdown2sms b/localmarkdown2sms index 7d03df2..86b0f6d 100755 --- a/localmarkdown2sms +++ b/localmarkdown2sms @@ -22,6 +22,7 @@ use strict; use warnings; +use utf8; # this document itself is UTF-8 encoded. use Env qw[$debug $info $warn $dummy $nosleep $urldecode]; use Log::Log4perl qw(:easy); @@ -68,8 +69,8 @@ if ($urldecode) { @ARGV = uri_unescape(@ARGV); } my ($phone) = shift @ARGV; -my $inputstring = join(' ', @ARGV); -my ($key) = lc (shift @ARGV); +my $inputstring = decode('UTF-8', join(' ', @ARGV)); +my ($key) = lc(decode('UTF-8', shift @ARGV)); # strip international prefix # (prefix is optional some places and illegal at other places - forgot where) @@ -107,8 +108,8 @@ foreach my $file (read_dir( $path )) { my ($warn_nonkey_delay, $warn_nonkey_content); next unless ($file =~ /\.mdwn$/); foreach my $line (read_file( File::Spec->catfile($path, $file))) { + $line = &transliterate(decode('UTF-8', $line)); chomp $line; - $line = &transliterate($line); my $content; # headline if ($line =~ /^(#+)\s*(.*?)\s*$/) { @@ -207,11 +208,11 @@ sub tidymsg { sub transliterate { my $string = shift @_; - my $res = encode('UTF-8', decode('GSM0338', encode('GSM0338', $string, sub { + my $res = decode('GSM0338', encode('GSM0338', $string, sub { my $ascii = unidecode(chr $_[0]); _utf8_off($ascii); $ascii; - }))); + })); return $res || ""; } -- cgit v1.2.3