added a common entityize function to prevent the contining spread
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 11 Sep 2008 01:50:14 +0000 (01:50 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 11 Sep 2008 01:50:14 +0000 (01:50 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@10573 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm

index e76bab0..8f6be2d 100644 (file)
@@ -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;