Module: URI::WhatwgParser::ParserHelper

Included in:
URI::WhatwgParser, HostParser
Defined in:
lib/uri/whatwg_parser/parser_helper.rb

Constant Summary collapse

C0_CONTROL_PERCENT_ENCODE_SET =

NOTE: This set isn’t accurate, but it’s OK now because greater than ‘0x7e` is checked inside a method.

Set.new((0..0x1f).map(&:chr))

Instance Method Summary collapse

Instance Method Details

#utf8_percent_encode(c, encode_set) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/uri/whatwg_parser/parser_helper.rb', line 10

def utf8_percent_encode(c, encode_set)
  return c unless encode_set.include?(c) || c.ord > 0x7e

  # For ASCII single-byte characters
  return "%%%02X" % c.ord if c.bytesize == 1

  c.bytes.map { |b| "%%%02X" % b }.join
end

#utf8_percent_encode_string(str, encode_set) ⇒ Object



19
20
21
# File 'lib/uri/whatwg_parser/parser_helper.rb', line 19

def utf8_percent_encode_string(str, encode_set)
  str.chars.map { |c| utf8_percent_encode(c, encode_set) }.join
end