class UriEncoding::Decoder
Constants
- EncodedCharRegexp
Public Instance Methods
decode(str, encoding=nil)
click to toggle source
# File lib/uri_encoding/decoder.rb, line 5 def decode(str, encoding=nil) single_byte_expressions = split_encoded_string(str) bytes_string = single_byte_expressions.map{|e| convert_to_byte(e) }.join bytes_string.force_encoding(encoding || str.encoding) end
Private Instance Methods
convert_to_byte(exp)
click to toggle source
# File lib/uri_encoding/decoder.rb, line 23 def convert_to_byte(exp) exp =~ EncodedCharRegexp ? Integer("0x#{$1}").chr : exp end
split_encoded_string(str)
click to toggle source
# File lib/uri_encoding/decoder.rb, line 13 def split_encoded_string(str) arr, pos = [], 0 while pos < str.size step = str[pos] == "%" ? 3 : 1 arr << str[pos...(pos + step)] pos += step end arr end