Module: JsonKpeg::StringEscaper

Included in:
Parser
Defined in:
lib/json-kpeg/escaper.rb

Instance Method Summary collapse

Instance Method Details

#process_escapes(str) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/json-kpeg/escaper.rb', line 2

def process_escapes (str)
  str.gsub! /\\(u\d{4}|\D)/m do
    seq = $1
    case seq
      when '/' then "\/"
      when 'b' then "\b"
      when 'f' then "\f"
      when 'n' then "\n"
      when 'r' then "\r"
      when 't' then "\t"
      when '"' then '"'
      when '\\' then '\\'
      when /u\d{4}/ then seq[1..-1].to_i.chr
      else seq
    end
  end
  
  str
end