]> the.earth.li Git - unicode-expand.git/blobdiff - unicode-expand.pl
Fall back to hex value when we can't look up a character
[unicode-expand.git] / unicode-expand.pl
index 15aa89eef1d68c94bce82a7a64b6412d130db4dd..159d4071aebf3e701b97920dc15d75e2352f4121 100644 (file)
@@ -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;