a TT2 wrapper to Unicode::Normalize
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Template / Plugin / Unicode.pm
1 package OpenILS::Template::Plugin::Unicode;
2 use Unicode::Normalize;
3
4 sub new { return bless {}, __PACKAGE__ }
5 sub load { return __PACKAGE__ }
6
7 sub C { shift; return NFC(@_); }
8 sub D { shift; return NFD(@_); }
9 sub entityDecode { shift; $_ = shift; s/&#x([0-9a-fA-F]+);/chr(hex($1))/egos; return $_ }
10 sub entityEncode { shift; $_ = shift; s/(\PM\pM+)/sprintf('&#x%0.4x;',ord(NFC($1)))/sgoe; return $_ }
11
12 1;