PyukiWiki CVS Commit
pyuki****@lists*****
2012年 1月 29日 (日) 06:07:59 JST
Index: PyukiWiki-Devel-UTF8/build/b64decode.pl diff -u PyukiWiki-Devel-UTF8/build/b64decode.pl:1.1 PyukiWiki-Devel-UTF8/build/b64decode.pl:1.2 --- PyukiWiki-Devel-UTF8/build/b64decode.pl:1.1 Sun Jan 29 05:07:46 2012 +++ PyukiWiki-Devel-UTF8/build/b64decode.pl Sun Jan 29 06:07:58 2012 @@ -1 +1,38 @@ -while(<STDIN>){$i.=$_;}print &bd($i);sub bd{my($_)=@_;my $r;$a='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';$b=q|`!"#$%&'()*+,-./0123456789:;<=>?|.'@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_';($c=" ".$b)=~s/\\/\\\\/;$d="A".$a;eval qq{tr|$d||cd;tr|$d|$c|;};while(s/^(.{60})//){$r.=unpack("u","M".$&);}if($_ ne ""){$r.=unpack("u",substr($b,length($_)*3/4,1).$_);}$r;} +$base64_alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. + 'abcdefghijklmnopqrstuvwxyz'. + '0123456789+/'; +$base64_pad = '='; + +$uuencode_alphabet = q|`!"#$%&'()*+,-./0123456789:;<=>?|. + '@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'; # double that '\\'! +$uuencode_pad = '`'; + + +sub b64decode +{ + local ($_) = @_; + local ($result); + + # zap bad characters and translate others to uuencode alphabet + eval qq{ + tr|$tr_base64||cd; + tr|$tr_base64|$tr_uuencode|; + }; + + # break into lines of 60 encoded chars, prepending "M" for uuencode, + # and then using perl's builtin uudecoder to convert to binary. + while (s/^(.{60})//) { + #warn "chunk :$&:\n"; + $result .= unpack("u", "M" . $&); + } + + # also decode any leftover chars + if ($_ ne "") { + #warn "last chunk :$_:\n"; + $result .= unpack("u", + substr($uuencode_alphabet, length($_)*3/4, 1) . $_); + } + + # return result + $result; +}