summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2010-09-26 18:59:53 +0200
committerJonas Smedegaard <dr@jones.dk>2010-09-26 18:59:53 +0200
commit8f6bf384c28276b6f05f9679e9a4e690bdc79803 (patch)
treedc90b2154befc35c65421ff06bab32872e5ebbd4
parent6ff2caadc23016b1ad8b2a669916fed6a5329e36 (diff)
Fix UTF-8 IO handling.
-rwxr-xr-xlocalkannel-dispatch4
-rwxr-xr-xlocalmarkdown2sms11
2 files changed, 8 insertions, 7 deletions
diff --git a/localkannel-dispatch b/localkannel-dispatch
index 5f96b36..dc003d8 100755
--- a/localkannel-dispatch
+++ b/localkannel-dispatch
@@ -27,9 +27,9 @@ lctransliterate() {
echo "$1" | perl -n \
-e 'use Text::Unidecode;' \
-e 'use Encode 2.12 qw(encode decode _utf8_off);' \
- -e 'print lc(encode("UTF-8", decode("GSM0338", encode("GSM0338", $_,' \
+ -e 'print lc(decode("GSM0338", encode("GSM0338", decode("UTF-8", $_),' \
-e 'sub {$a=unidecode(chr $_[0]); _utf8_off($a); $a;}' \
- -e '))));'
+ -e ')));'
return $res;
}
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 || "";
}