Method: JSONX.normalize_quotes

Defined in:
lib/json/next/parser/jsonx.rb

.normalize_quotes(text) ⇒ Object

note: same as hanson (see parser/hanson.rb)



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/json/next/parser/jsonx.rb', line 44

def self.normalize_quotes( text )  ## pass 2

   text.gsub( /#{BACKTICK_ML_QUOTE}|#{SINGLE_QUOTE}|#{DOUBLE_QUOTE}/ox ) do |match|
     ## puts "match: >>#{match}<< : #{match.class.name}"


     m = Regexp.last_match
     if m[:backtick_ml_quote]
       ## puts "!!! ml_quote -- convert to double quotes"

       str = m[:backtick_ml_quote]
       str = str.gsub( /\\./ ) {|r| UNESCAPE_MAP[r] || r }
       str = str.gsub( /[\n\r\t"]/ ) { |r| ML_ESCAPE_MAP[r] }
       '"' + str + '"'
     elsif m[:single_quote]
       ## puts "!!! single_quote -- convert to double quotes"

       str = m[:single_quote]
       str = str.gsub( /\\./ ) {|r| UNESCAPE_MAP[r] || r }
       str = str.gsub( /"/, %{\\"} )
       '"' + str + '"'
     else
       match
     end
  end
end