Module: TomlRB::BasicString
- Defined in:
- lib/toml-rb/string.rb
Overview
Used in primitive.citrus
Constant Summary collapse
- SPECIAL_CHARS =
{ "\\0" => "\0", "\\t" => "\t", "\\b" => "\b", "\\f" => "\f", "\\n" => "\n", "\\r" => "\r", '\\"' => '"', "\\\\" => "\\" }.freeze
Class Method Summary collapse
-
.decode_unicode(str) ⇒ Object
Replace the unicode escaped characters with the corresponding character e.g.
- .parse_error(m) ⇒ Object
- .transform_escaped_chars(str) ⇒ Object
Instance Method Summary collapse
Class Method Details
.decode_unicode(str) ⇒ Object
Replace the unicode escaped characters with the corresponding character e.g. u03B4 => ?
23 24 25 |
# File 'lib/toml-rb/string.rb', line 23 def self.decode_unicode(str) [str[2..-1].to_i(16)].pack("U") end |
.parse_error(m) ⇒ Object
37 38 39 |
# File 'lib/toml-rb/string.rb', line 37 def self.parse_error(m) fail ParseError.new "Escape sequence #{m} is reserved" end |
.transform_escaped_chars(str) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/toml-rb/string.rb', line 27 def self.transform_escaped_chars(str) str.gsub(/\\(u[\da-fA-F]{4}|U[\da-fA-F]{8}|.)/) do |m| if m.size == 2 SPECIAL_CHARS[m] || parse_error(m) else decode_unicode(m).force_encoding("UTF-8") end end end |
Instance Method Details
#value ⇒ Object
15 16 17 18 19 |
# File 'lib/toml-rb/string.rb', line 15 def value aux = TomlRB::BasicString.transform_escaped_chars first.value aux[1...-1] end |