class Tomlrb::StringUtils

Constants

SPECIAL_CHARS

Public Class Methods

multiline_replacements(str) click to toggle source
# File lib/tomlrb/string_utils.rb, line 14
def self.multiline_replacements(str)
  strip_spaces(str).gsub(/\\+\s*\n\s*/) {|matched|
    if matched.match(/\\+/)[0].length.odd?
      matched.gsub(/\\\s*\n\s*/, '')
    else
      matched
    end
  }
end
replace_escaped_chars(str) click to toggle source
# File lib/tomlrb/string_utils.rb, line 24
def self.replace_escaped_chars(str)
  str.gsub(/\\(u[\da-fA-F]{4}|U[\da-fA-F]{8}|.)/) do |m|
    if m.size == 2
      SPECIAL_CHARS[m] || (raise Tomlrb::ParseError.new "Escape sequence #{m} is reserved")
    else
      m[2..-1].to_i(16).chr(Encoding::UTF_8)
    end
  end
end
strip_spaces(str) click to toggle source
# File lib/tomlrb/string_utils.rb, line 34
def self.strip_spaces(str)
  str[0] = '' if str[0] == "\n"
  str
end