Changeset 4865

Show
Ignore:
Timestamp:
01/18/08 14:24:41 (5 years ago)
Author:
miyagawa
Message:

added charname

Location:
lang/perl/autobox-Encode/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/autobox-Encode/trunk/lib/autobox/Encode.pm

    r4777 r4865  
    11package autobox::Encode; 
    22use strict; 
     3use charnames (); 
    34use warnings; 
    45use autobox; 
     
    1213sub is_utf8 { Encode::is_utf8($_[0]) } 
    1314sub from_to { Encode::from_to($_[0], $_[1], $_[2]); $_[0] } 
     15 
     16sub charname { 
     17    my $string = shift; 
     18    join '', map charnames::viacode(ord), split //, $string; 
     19} 
    1420 
    15211; 
     
    2733 
    2834  "Foo"->decode('utf-8')->encode('utf-8') 
     35 
     36  my $latin1_bytes = ...; 
     37  my $utf8_bytes   = $latin1_bytes->from_to('latin-1' => 'utf-8'); 
     38 
     39  "\x{1234}"->charname; # "ETHIOPIC SYLLABLE SEE" 
    2940 
    3041=head1 DESCRIPTION 
  • lang/perl/autobox-Encode/trunk/t/01_simple.t

    r4777 r4865  
    44use autobox::Encode; 
    55use Encode (); 
    6 use Test::More tests => 7; 
     6use Test::More tests => 8; 
    77 
    88ok Encode::is_utf8('あいうえお'->decode('utf-8')); 
     
    1515my $x = 'あいうえお'; 
    1616is uc(unpack "H*", $x->from_to('utf-8' => 'euc-jp')), "A4A2A4A4A4A6A4A8A4AA"; 
     17 
     18is "\x{1234}"->charname, "ETHIOPIC SYLLABLE SEE";