From 0b1e7db502645d98af36ced66532eef06c5c3797 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 11 Sep 2008 01:50:14 +0000 Subject: [PATCH] added a common entityize function to prevent the contining spread git-svn-id: svn://svn.open-ils.org/ILS/trunk@10573 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/AppUtils.pm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm index e76bab0870..8f6be2dc5b 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm @@ -11,6 +11,7 @@ use OpenILS::Event; use Data::Dumper; use OpenILS::Utils::CStoreEditor; use OpenILS::Const qw/:const/; +use Unicode::Normalize; # --------------------------------------------------------------------------- # Pile of utilty methods used accross applications. @@ -1474,5 +1475,22 @@ sub get_user_locale { return 'en-US'; } + +# xml-escape non-ascii characters +sub entityize { + my($self, $string, $form) = @_; + $form ||= ""; + + if ($form eq 'D') { + $string = NFD($string); + } else { + $string = NFC($string); + } + + $string =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe; + return $string; +} + + 1; -- 2.43.2