Module: TOML::BasicString
- Defined in:
- lib/toml/string.rb
Overview
Used in primitive.citrus
Class Method Summary collapse
-
.decode_special_char(str) ⇒ Object
Replace special characters such as line feed and tabs.
-
.decode_unicode(str) ⇒ Object
Replace the unicode escaped characters with the corresponding character e.g.
- .transform_escaped_chars(str) ⇒ Object
Instance Method Summary collapse
Class Method Details
.decode_special_char(str) ⇒ Object
Replace special characters such as line feed and tabs.
19 20 21 22 23 24 25 26 27 |
# File 'lib/toml/string.rb', line 19 def self.decode_special_char(str) str.gsub(/\\0/, "\0") .gsub(/\\t/, "\t") .gsub(/\\b/, "\b") .gsub(/\\f/, "\f") .gsub(/\\n/, "\n") .gsub(/\\\"/, '"') .gsub(/\\r/, "\r") end |
.decode_unicode(str) ⇒ Object
Replace the unicode escaped characters with the corresponding character e.g. u03B4 => ?
12 13 14 15 16 |
# File 'lib/toml/string.rb', line 12 def self.decode_unicode(str) str.gsub(/([^\\](?:\\\\)*\\u[\da-f]{4})/i) do |m| m[0...-6] + [m[-4..-1].to_i(16)].pack('U') end end |
.transform_escaped_chars(str) ⇒ Object
29 30 31 32 33 |
# File 'lib/toml/string.rb', line 29 def self.transform_escaped_chars(str) str = decode_special_char(str) str = decode_unicode(str) str.gsub(/\\\\/, '\\').encode('utf-8') end |
Instance Method Details
#value ⇒ Object
4 5 6 7 8 |
# File 'lib/toml/string.rb', line 4 def value aux = TOML::BasicString.transform_escaped_chars first.value aux[1...-1] end |