add TT helper to squeeze strings into the UNOB straitjacket
authorgmc <gmc@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 4 Nov 2010 01:03:42 +0000 (01:03 +0000)
committergmc <gmc@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 4 Nov 2010 01:03:42 +0000 (01:03 +0000)
The force_jedi_unob helper strips non-ASCII characters from
template output but does so nicely by converting the string
to NFD first.  This is meant to be used by EDI templates, although
could be useful for A/T output that goes to receipt
printers that cannot print diacritics.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>

git-svn-id: svn://svn.open-ils.org/ILS/trunk@18598 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm

index cc59bbd..4be542b 100644 (file)
@@ -3,6 +3,7 @@ use strict; use warnings;
 use Template;
 use DateTime;
 use DateTime::Format::ISO8601;
+use Unicode::Normalize;
 use OpenSRF::Utils qw/:datetime/;
 use OpenSRF::Utils::Logger qw(:logger);
 use OpenILS::Application::AppUtils;
@@ -48,6 +49,15 @@ my $_TT_helpers = {
         return $str;
     },
 
+    # strip non-ASCII characters after splitting base characters and diacritics
+    # least common denominator for EDIFACT messages using the UNOB character set
+    force_jedi_unob => sub {
+        my $str = shift;
+        $str = NFD($str);
+        $str =~ s/[\x{0080}-\x{fffd}]//g;
+        return $str;
+    },
+
     # returns the calculated user locale
     get_user_locale => sub { 
         my $user_id = shift;