module CGI::Util

def escapeURIComponent(string)

# => "%27Stop%21%27%20said%20Fred"
url_encoded_string = CGI.escape("'Stop!' said Fred")
Space characters (+" "+) are encoded with (+"%20"+)
URL-encode a string following RFC 3986
def escapeURIComponent(string)
  encoding = string.encoding
  buffer = string.b
  buffer.gsub!(/([^a-zA-Z0-9_.\-~]+)/) do |m|
    '%' + m.unpack('H2' * m.bytesize).join('%').upcase
  end
  buffer.force_encoding(encoding)
end