231
231
232
232
233
233
local function parse_string (str , i )
234
- local res = " "
234
+ local res = {}
235
235
local j = i + 1
236
236
local k = j
237
237
@@ -242,32 +242,33 @@ local function parse_string(str, i)
242
242
decode_error (str , j , " control character in string" )
243
243
244
244
elseif x == 92 then -- `\`: Escape
245
- res = res .. str :sub (k , j - 1 )
245
+ res [ # res + 1 ] = str :sub (k , j - 1 )
246
246
j = j + 1
247
247
local c = str :sub (j , j )
248
248
if c == " u" then
249
249
local hex = str :match (" ^[dD][89aAbB]%x%x\\ u%x%x%x%x" , j + 1 )
250
250
or str :match (" ^%x%x%x%x" , j + 1 )
251
251
or decode_error (str , j - 1 , " invalid unicode escape in string" )
252
- res = res .. parse_unicode_escape (hex )
252
+ res [ # res + 1 ] = parse_unicode_escape (hex )
253
253
j = j + # hex
254
254
else
255
255
if not escape_chars [c ] then
256
256
decode_error (str , j - 1 , " invalid escape char '" .. c .. " ' in string" )
257
257
end
258
- res = res .. escape_char_map_inv [c ]
258
+ res [ # res + 1 ] = escape_char_map_inv [c ]
259
259
end
260
260
k = j + 1
261
261
262
262
elseif x == 34 then -- `"`: End of string
263
- res = res .. str :sub (k , j - 1 )
264
- return res , j + 1
263
+ res [ # res + 1 ] = str :sub (k , j - 1 )
264
+ return table.concat ( res ) , j + 1
265
265
end
266
266
267
267
j = j + 1
268
268
end
269
269
270
270
decode_error (str , i , " expected closing quote for string" )
271
+ return table.concat (res )
271
272
end
272
273
273
274
0 commit comments