Changeset 23285


Ignore:
Timestamp:
11/03/10 17:52:09 (10 years ago)
Author:
sjm84
Message:

Moving subroutine committed previously to util.pm to unicode.pm where it belongs: Dr Bainbridge's modification of nice-string subroutine which will print the unicode strings for debugging (printable ASCII chars are shown as-is, other chars are shown with their hex values for their unicode code points.

Location:
main/trunk/greenstone2/perllib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/unicode.pm

    r18410 r23285  
    701701}
    702702
     703# Useful method to print UTF8 (or other unicode) for debugging.
     704# Characters that are easily displayed (that is, printable ASCII)
     705# are shown as-is, whereas hex values of the unicode code points
     706# are shown for all other chars.
     707sub debug_unicode_string
     708{
     709    join("",
     710         map { $_ > 128 ?                      # if wide character...
     711                   sprintf("\\x{%04X}", $_) :  # \x{...}
     712                   chr($_)         
     713               } unpack("U*", $_[0]));         # unpack Unicode characters
     714}
    703715
    7047161;
  • main/trunk/greenstone2/perllib/util.pm

    r23284 r23285  
    13741374}
    13751375
    1376 # To print UTF8 (unicode) for debugging:
    1377 # Characters that are easily displayed (that is, printable ASCII)
    1378 # are shown as-is, whereas hexcodes are shown for all other chars.
    1379 # Useful method for debugging when doing encoding related work.
    1380 sub debug_unicode_string
    1381 {
    1382     join("",
    1383          map { $_ > 128 ?                      # if wide character...
    1384                    sprintf("\\x{%04X}", $_) :  # \x{...}
    1385                    chr($_)         
    1386                } unpack("U*", $_[0]));         # unpack Unicode characters
    1387 }
    1388 
    138913761;
Note: See TracChangeset for help on using the changeset viewer.