88540591 2011-12-06
requirt'cgi'
defto_utf8(unicode_string)
unicode_string.gsub(/\\u\w{4}/)do|s|
str=s.sub(/\\u/,"").hex.to_s(2)
ifstr.length<8
CGI.unescape(str.to_i(2).to_s(16).insert(0,"%"))
else
arr=str.reverse.scan(/\w{0,6}/).reverse.select{|a|a!=""}.map{|b|b.reverse}
hex=lambdado|s|
(arr.first==s?"1"*arr.length+"0"*(8-arr.length-s.length)+s:"10"+s).to_i(2).to_s(16).insert(0,"%")
end
CGI.unescape(arr.map(&hex).join)
end
end
end