Changeset 6283 for lang/perl/Encode

Show
Ignore:
Timestamp:
02/06/08 14:51:24 (5 years ago)
Author:
tomi-ru
Message:

lang/perl/Encode: add 2 args idea: encoding->name, (encode|decode)

Location:
lang/perl/Encode/branches/callback-args
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Encode/branches/callback-args/Encode.xs

    r1747 r6283  
    6565 
    6666static SV * 
    67 do_fallback_cb(pTHX_ UV ch, SV *fallback_cb) 
     67do_fallback_cb(pTHX_ UV ch, SV *fallback_cb, const encode_t * enc, const method) 
    6868{ 
    6969    dSP; 
     
    7474    PUSHMARK(sp); 
    7575    XPUSHs(sv_2mortal(newSVnv((UV)ch))); 
     76    XPUSHs(sv_2mortal(newSVpv(enc->name[0], 0))); 
     77    XPUSHs(sv_2mortal(newSVpv(method, 0))); 
    7678    PUTBACK; 
    7779    argc = call_sv(fallback_cb, G_SCALAR); 
     
    196198            SV* subchar =  
    197199            (fallback_cb != &PL_sv_undef) 
    198                 ? do_fallback_cb(aTHX_ ch, fallback_cb) 
     200                ? do_fallback_cb(aTHX_ ch, fallback_cb, enc, "encode") 
    199201                : newSVpvf(check & ENCODE_PERLQQ ? "\\x{%04"UVxf"}" : 
    200202                 check & ENCODE_HTMLCREF ? "&#%" UVuf ";" : 
     
    231233            SV* subchar =  
    232234            (fallback_cb != &PL_sv_undef) 
    233                 ? do_fallback_cb(aTHX_ (UV)s[slen], fallback_cb)  
     235                ? do_fallback_cb(aTHX_ (UV)s[slen], fallback_cb, enc, "decode")  
    234236                : newSVpvf("\\x%02" UVXf, (UV)s[slen]); 
    235237            sdone += slen + 1; 
  • lang/perl/Encode/branches/callback-args/t/fallback.t

    r1747 r6283  
    1818use strict; 
    1919#use Test::More qw(no_plan); 
    20 use Test::More tests => 48; 
     20use Test::More tests => 50; 
    2121use Encode q(:all); 
    2222 
     
    176176$dst = decode("ascii", (pack "C*", 0xFF), sub{ $_[0] }); 
    177177is $dst, 0xFF."", qq{decode("ascii", (pack "C*", 0xFF), sub{ \$_[0] })}; 
     178 
     179$src = "\x{3000}"; 
     180$dst = $ascii->encode($src, sub{ join "-", @_ }); 
     181is $dst, 0x3000."-ascii-encode", "encode fallback with encoding name"; 
     182 
     183$src = pack "C*", 0xFF; 
     184$dst = $ascii->decode($src, sub{ join "-", @_ }); 
     185is $dst, 0xFF."-ascii-decode", "decode fallback with encoding name";