Igor Gariev (gariev) wrote in changelog,
Igor Gariev
gariev
changelog

[livejournal] r20218: LJSUP-10009: [internal]: show detailed s...

Committer: gariev
LJSUP-10009: [internal]: show detailed server info (svn revision, date of last commit)
U   trunk/cgi-bin/LJ/Text.pm
Modified: trunk/cgi-bin/LJ/Text.pm
===================================================================
--- trunk/cgi-bin/LJ/Text.pm	2011-10-04 07:38:02 UTC (rev 20217)
+++ trunk/cgi-bin/LJ/Text.pm	2011-10-04 07:50:26 UTC (rev 20218)
@@ -41,7 +41,7 @@
 
 package LJ::Text;
 
-use Encode qw(encode_utf8 decode_utf8);
+use Encode qw(encode_utf8 decode_utf8 is_utf8);
 use Carp qw(confess cluck);
 use UNIVERSAL qw(isa);
 use strict;
@@ -82,6 +82,34 @@
     return encode_utf8($str);
 }
 
+#
+# LJ::Text->remove_utf8_flag($tree);
+# input: a string or any complex structure (hash, array etc)
+# output: the same structure without utf8 flag on any string in it.
+#
+sub remove_utf8_flag {
+    my $class = shift;
+    my $tree = shift;
+
+    unless (ref $tree) {
+        $tree = encode_utf8($tree) if $tree && is_utf8($tree);
+    }
+    
+    if (ref $tree eq 'ARRAY') {
+        foreach (@$tree) {
+            $_ = $class->remove_utf8_flag($_);
+        }
+    }
+
+    if (ref $tree eq 'HASH') {
+        foreach (values %$tree) {
+            $_ = $class->remove_utf8_flag($_);
+        }
+    }
+
+    return $tree;    
+}
+
 # given a string, returns its longest UTF-8 "prefix" (that is, its
 # 'substr($str, 0, $something)' kind of substring) that doesn't exceed the given
 # number of bytes.

Tags: gariev, livejournal, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments