Changeset 18391

Show
Ignore:
Timestamp:
08/28/08 17:24:47 (6 years ago)
Author:
yappo
Message:

サイズがでかくならんようにした

Files:
1 modified

Legend:

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

    r18389 r18391  
    1616 
    1717my %whitespaces2bit = ( 
    18     "\t" => "00", 
    19     "\r" => "01", 
    20     "\n" => "10", 
    21     " "  => "11", 
     18    " "    => "0000", 
     19    "\001" => "0001", 
     20    "\002" => "0010", 
     21    "\003" => "0011", 
     22    "\004" => "0100", 
     23    "\005" => "0101", 
     24    "\006" => "0110", 
     25    "\007" => "0111", 
     26 
     27    "\010" => "1000", 
     28    "\011" => "1001", 
     29    "\013" => "1010", 
     30    "\014" => "1011", 
     31    "\016" => "1100", 
     32    "\017" => "1101", 
     33    "\020" => "1110", 
     34    "\021" => "1111", 
    2235); 
    2336my %bit2whitespaces = map { $whitespaces2bit{$_} => $_ } keys %whitespaces2bit; 
     
    2841    my $bytes = Encode::encode('utf8', $str); 
    2942    my $bits = unpack('B*', $bytes); 
    30     $bits =~ s/([01][01])/$bit2whitespaces{$1}/g; 
     43    $bits =~ s/([01][01][01][01])/$bit2whitespaces{$1}/g; 
    3144    $bits; 
    3245} 
     
    3548    my ($obj, $bytes, $chk) = @_; 
    3649    return '' unless $bytes; 
    37     return $bytes unless $bytes =~ /^[\t\r\n ]{4,}$/; 
     50    return $bytes unless $bytes =~ /^[ \001\002\003\004\005\006\007\010\011\013\014\016\017\020\021]{2,}$/; 
    3851 
    3952    my @bits = map { 
     
    4255 
    4356    my $ret = ''; 
    44     while (my @byte = splice @bits, 0, 4) { 
     57    while (my @byte = splice @bits, 0, 2) { 
    4558        $ret .= pack('B8', join '', @byte); 
    4659    } 
    47  
    4860    $ret; 
    4961}