8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/pbind/minify.rb', line 8
def json(str)
ss = StringScanner.new(str)
buf = ''
until ss.eos?
if s = ss.scan(/\s+/)
elsif s = ss.scan(/[{},:\]\[]/)
buf << s
elsif s = ss.scan(/""|(".*?[^\\])?"/)
buf << s
elsif s = ss.scan(/(true|false|null)/)
buf << s
elsif s = ss.scan(/-?\d+([.]\d+)?([eE][-+]?[0-9]+)?/)
buf << s
elsif s = ss.scan(%r{//})
ss.scan_until(/(\r?\n|$)/)
elsif s = ss.scan(%r{/[*]})
ss.scan_until(%r{[*]/}) || raise(SyntaxError, "Unterminated /*...*/ comment - #{ss.rest}")
else
raise SyntaxError, "Unable to pre-scan string: #{ss.rest}"
end
end
buf
end
|