mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
This commit was generated by cvs2svn to compensate for changes in r372,
which included commits to RCS files with non-trunk default branches. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9c5b1986a3
commit
210367ec88
140 changed files with 25635 additions and 14037 deletions
|
@ -1,50 +1,25 @@
|
|||
def decode64(str)
|
||||
string = ''
|
||||
for line in str.split("\n")
|
||||
line.delete!('^A-Za-z0-9+/') # remove non-base64 chars
|
||||
line.tr!('A-Za-z0-9+/', ' -_') # convert to uuencoded format
|
||||
len = ["#{32 + line.length * 3 / 4}"].pack("c")
|
||||
# compute length byte
|
||||
string += "#{len}#{line}".unpack("u") # uudecode and concatenate
|
||||
end
|
||||
return string
|
||||
end
|
||||
require "kconv"
|
||||
|
||||
def j2e(str)
|
||||
while str =~ /\033\$B([^\033]*)\033\(B/
|
||||
s = $1
|
||||
pre, post = $`, $'
|
||||
s.gsub!(/./) { |ch|
|
||||
(ch[0]|0x80).chr
|
||||
}
|
||||
str = pre + s + post
|
||||
end
|
||||
# str.gsub!(/\033\$B([^\033]*)\033\(B/) {
|
||||
# $1.gsub!(/./) { |ch|
|
||||
# (ch[0]|0x80).chr
|
||||
# }
|
||||
# }
|
||||
str
|
||||
def decode64(str)
|
||||
str.unpack("m")[0]
|
||||
end
|
||||
|
||||
def decode_b(str)
|
||||
str.gsub!(/=\?ISO-2022-JP\?B\?([!->@-~]+)\?=/i) {
|
||||
decode64($1)
|
||||
}
|
||||
str = Kconv::toeuc(str)
|
||||
str.gsub!(/=\?SHIFT_JIS\?B\?([!->@-~]+)\?=/i) {
|
||||
decode64($1)
|
||||
}
|
||||
str = Kconv::toeuc(str)
|
||||
str.gsub!(/\n/, ' ')
|
||||
str.gsub!(/\0/, '')
|
||||
j2e(str)
|
||||
str
|
||||
end
|
||||
|
||||
def encode64(bin)
|
||||
encode = ""
|
||||
pad = 0
|
||||
[bin].pack("u").each do |uu|
|
||||
len = (2 + (uu[0] - 32)* 4) / 3
|
||||
encode << uu[1, len].tr('` -_', 'AA-Za-z0-9+/')
|
||||
pad += uu.length - 2 - len
|
||||
end
|
||||
encode + "=" * (pad % 3)
|
||||
[bin].pack("m")
|
||||
end
|
||||
|
||||
def b64encode(bin, len = 60)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue