Software /
code /
prosody
Comparison
util/json.lua @ 5561:52eef11cd8af
util.json: Optimize long string parsing.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 05 May 2013 15:02:33 -0400 |
parent | 5517:9d7349bbe4d2 |
child | 5562:a6b8fb827e2a |
comparison
equal
deleted
inserted
replaced
5553:7baf59444b31 | 5561:52eef11cd8af |
---|---|
256 checkandskip(c); | 256 checkandskip(c); |
257 end | 257 end |
258 return val; | 258 return val; |
259 end | 259 end |
260 local function readstring() | 260 local function readstring() |
261 local s = ""; | 261 local s = {}; |
262 checkandskip("\""); | 262 checkandskip("\""); |
263 while ch do | 263 while ch do |
264 while ch and ch ~= "\\" and ch ~= "\"" do | 264 while ch and ch ~= "\\" and ch ~= "\"" do |
265 s = s..ch; next(); | 265 t_insert(s, ch); next(); |
266 end | 266 end |
267 if ch == "\\" then | 267 if ch == "\\" then |
268 next(); | 268 next(); |
269 if unescapes[ch] then | 269 if unescapes[ch] then |
270 s = s..unescapes[ch]; | 270 t_insert(s, unescapes[ch]); |
271 next(); | 271 next(); |
272 elseif ch == "u" then | 272 elseif ch == "u" then |
273 local seq = ""; | 273 local seq = ""; |
274 for i=1,4 do | 274 for i=1,4 do |
275 next(); | 275 next(); |
276 if not ch then error("unexpected eof in string"); end | 276 if not ch then error("unexpected eof in string"); end |
277 if not ch:match("[0-9a-fA-F]") then error("invalid unicode escape sequence in string"); end | 277 if not ch:match("[0-9a-fA-F]") then error("invalid unicode escape sequence in string"); end |
278 seq = seq..ch; | 278 seq = seq..ch; |
279 end | 279 end |
280 s = s..codepoint_to_utf8(tonumber(seq, 16)); | 280 t_insert(s, codepoint_to_utf8(tonumber(seq, 16))); |
281 next(); | 281 next(); |
282 else error("invalid escape sequence in string"); end | 282 else error("invalid escape sequence in string"); end |
283 end | 283 end |
284 if ch == "\"" then | 284 if ch == "\"" then |
285 next(); | 285 next(); |
286 return s; | 286 return t_concat(s); |
287 end | 287 end |
288 end | 288 end |
289 error("eof while reading string"); | 289 error("eof while reading string"); |
290 end | 290 end |
291 local function readnumber() | 291 local function readnumber() |