From: Jonathan McDowell Date: Sat, 5 Jan 2019 15:39:32 +0000 (+0000) Subject: Fall back to hex value when we can't look up a character X-Git-Url: https://the.earth.li/gitweb/?a=commitdiff_plain;h=b3aaed733f8f8717d208287a6da15be08e34b05f;p=unicode-expand.git Fall back to hex value when we can't look up a character We're dependant on Perl for Unicode tables, so if it doesn't have a recent enough set of definitions (e.g. Debian Stretch only has up to Unicode 8) we were getting uninitialized value warnings for Unicode 9/10 characters. Fall back to outputting the hex value for the character. Reported by Lars Wirzenius. --- diff --git a/unicode-expand.pl b/unicode-expand.pl index 15aa89e..159d407 100644 --- a/unicode-expand.pl +++ b/unicode-expand.pl @@ -53,12 +53,21 @@ sub expand_topic { expand($server, $channel, $topic), $nick, $mask); } +sub expand_char { + my ($char) = @_; + + my $name = charnames::viacode(ord $1); + $name = sprintf("{%X}", ord $1) unless defined($name); + + return $name; +} + sub expand { my ($server, $target, $data) = @_; $data = decode_utf8($data); $data =~ s{([^\p{Letter}\p{Punctuation}\p{Control}\p{Space}\p{Sc}[:ascii:]])}{ - "${1} [".charnames::viacode(ord $1)."]" + "${1} [".expand_char($1)."]" }ge; return $data;