Changeset 18389
- Timestamp:
- 08/28/08 16:32:45 (4 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Acme-Encode-WhiteSpace8/trunk/lib/Acme/Encode/WhiteSpace8.pm
r18385 r18389 15 15 and $specials .= quotemeta "!\"#$%&*;<=>@[]^_`{|}"; 16 16 17 my @whitespaces = (' ', "\t"); 18 my %whitespaces = do { 19 my $i = 0; 20 map { $_ => $i++ } @whitespaces; 21 }; 17 my %whitespaces2bit = ( 18 "\t" => "00", 19 "\r" => "01", 20 "\n" => "10", 21 " " => "11", 22 ); 23 my %bit2whitespaces = map { $whitespaces2bit{$_} => $_ } keys %whitespaces2bit; 22 24 23 25 sub encode($$;$) { … … 25 27 26 28 my $bytes = Encode::encode('utf8', $str); 27 28 my @spaces = (); 29 for my $byte (split //, $bytes) { 30 push @spaces, map { 31 $whitespaces[$_] 32 } split //, unpack('B*', $byte); 33 } 34 35 my $ret = join '', @spaces; 36 return '' unless $ret; 37 38 Encode::encode('utf8', $whitespaces[0]x8 . $ret . $whitespaces[1]x8); 29 my $bits = unpack('B*', $bytes); 30 $bits =~ s/([01][01])/$bit2whitespaces{$1}/g; 31 $bits; 39 32 } 40 33 … … 42 35 my ($obj, $bytes, $chk) = @_; 43 36 return '' unless $bytes; 37 return $bytes unless $bytes =~ /^[\t\r\n ]{4,}$/; 44 38 45 $bytes = Encode::decode('utf8', $bytes); 46 return $bytes unless $bytes =~ /^ ([ \t]{8,})\t\t\t\t\t\t\t\t$/; 47 my $body = $1; 48 49 my @bits = grep { defined $_ } map { 50 $whitespaces{$_} 51 } split //, $body; 52 warn join('', @bits, "\n"); 39 my @bits = map { 40 $whitespaces2bit{$_} 41 } split //, $bytes; 53 42 54 43 my $ret = ''; 55 while (my @byte = splice @bits, 0, 8) {44 while (my @byte = splice @bits, 0, 4) { 56 45 $ret .= pack('B8', join '', @byte); 57 46 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)