File tree Expand file tree Collapse file tree 1 file changed +42
-16
lines changed Expand file tree Collapse file tree 1 file changed +42
-16
lines changed Original file line number Diff line number Diff line change @@ -261,8 +261,14 @@ struct Value {
261
261
if (*curr == ' "' ) {
262
262
// String
263
263
curr++;
264
- char * close = strchr (curr, ' "' );
265
- assert (close);
264
+ char * close = curr;
265
+ while (*close && *close != ' "' ) {
266
+ if (*close == ' \\ ' && *(close + 1 )) {
267
+ close++; // Skip escaped character
268
+ }
269
+ close++;
270
+ }
271
+ assert (*close == ' "' );
266
272
*close = 0 ; // end this string, and reuse it straight from the input
267
273
setString (curr);
268
274
curr = close + 1 ;
@@ -305,20 +311,40 @@ struct Value {
305
311
skip ();
306
312
setObject ();
307
313
while (*curr != ' }' ) {
308
- assert (*curr == ' "' );
309
- curr++;
310
- char * close = strchr (curr, ' "' );
311
- assert (close);
312
- *close = 0 ; // end this string, and reuse it straight from the input
313
- IString key (curr);
314
- curr = close + 1 ;
315
- skip ();
316
- assert (*curr == ' :' );
317
- curr++;
318
- skip ();
319
- Ref value = Ref (new Value ());
320
- curr = value->parse (curr);
321
- (*obj)[key] = value;
314
+ if (*curr == ' "' ) {
315
+ curr++;
316
+ char * close = curr;
317
+ while (*close && *close != ' "' ) {
318
+ if (*close == ' \\ ' && *(close + 1 )) {
319
+ close++; // Skip escaped character
320
+ }
321
+ close++;
322
+ }
323
+ assert (*close == ' "' );
324
+ *close = 0 ; // end this string, and reuse it straight from the input
325
+ IString key (curr);
326
+ curr = close + 1 ;
327
+ skip ();
328
+ assert (*curr == ' :' );
329
+ curr++;
330
+ skip ();
331
+ Ref value = Ref (new Value ());
332
+ curr = value->parse (curr);
333
+ (*obj)[key] = value;
334
+ } else {
335
+ // Unquoted key
336
+ char * start = curr;
337
+ while (*curr && *curr != ' :' && !is_json_space (*curr)) {
338
+ curr++;
339
+ }
340
+ assert (*curr == ' :' );
341
+ IString key (std::string (start, curr - start).c_str ());
342
+ curr++;
343
+ skip ();
344
+ Ref value = Ref (new Value ());
345
+ curr = value->parse (curr);
346
+ (*obj)[key] = value;
347
+ }
322
348
skip ();
323
349
if (*curr == ' }' ) {
324
350
break ;
You can’t perform that action at this time.
0 commit comments