@@ -264,16 +264,16 @@ struct ParsedJson {
264264 printf (" false\n " );
265265 break ;
266266 case ' {' : // we have an object
267- printf (" {\n " );
267+ printf (" {\t // pointing to next tape location %llu \n " , payload );
268268 break ;
269269 case ' }' : // we end an object
270- printf (" }\n " );
270+ printf (" }\t // pointing to previous tape location %llu \n " , payload );
271271 break ;
272272 case ' [' : // we start an array
273- printf (" [\n " );
273+ printf (" [\t // pointing to next tape location %llu \n " , payload );
274274 break ;
275275 case ' ]' : // we end an array
276- printf (" ]\n " );
276+ printf (" ]\t // pointing to previous tape location %llu \n " , payload );
277277 break ;
278278 case ' r' : // we start and end with the root node
279279 printf (" end of root\n " );
@@ -368,7 +368,7 @@ struct ParsedJson {
368368 current_val (o.current_val), depthindex(o.depthindex) {
369369 o.depthindex = NULL ;// we take ownship
370370 }
371-
371+ WARN_UNUSED
372372 bool isOk () const {
373373 return location < tape_length;
374374 }
@@ -384,7 +384,9 @@ struct ParsedJson {
384384 // return true if we can do the navigation, false
385385 // otherwise
386386
387- // valid if we're not at the end of a scope
387+ // withing a give scope, we move forward
388+ // valid if we're not at the end of a scope (returns true)
389+ WARN_UNUSED
388390 really_inline bool next () {
389391 if ((current_type == ' [' ) || (current_type == ' {' )){
390392 // we need to jump
@@ -417,6 +419,7 @@ struct ParsedJson {
417419 }
418420
419421 // valid if we're not at the start of a scope
422+ WARN_UNUSED
420423 really_inline bool prev () {
421424 if (location - 1 < depthindex[depth]) return false ;
422425 location -= 1 ;
@@ -437,6 +440,7 @@ struct ParsedJson {
437440
438441
439442 // valid unless we are at the first level of the document
443+ WARN_UNUSED
440444 really_inline bool up () {
441445 if (depth == 1 ) {
442446 return false ; // don't allow moving back to root
@@ -451,11 +455,16 @@ struct ParsedJson {
451455 }
452456
453457
454- // valid if we're at a [ or { call site; moves us to start of
455- // that scope
458+ // valid if we're at a [ or { and it starts a non-empty scope; moves us to start of
459+ // that deeper scope if it not empty
460+ WARN_UNUSED
456461 really_inline bool down () {
457462 if (location + 1 >= tape_length) return false ;
458463 if ((current_type == ' [' ) || (current_type == ' {' )) {
464+ size_t npos = (current_val & JSONVALUEMASK);
465+ if (npos == location + 2 ) {
466+ return false ; // we have an empty scope
467+ }
459468 depth++;
460469 location = location + 1 ;
461470 depthindex[depth] = location;
@@ -477,17 +486,24 @@ struct ParsedJson {
477486 // the start of our current scope; always succeeds
478487
479488 // print the thing we're currently pointing at
480- bool print (std::ostream &os) const {
489+ bool print (std::ostream &os, bool escape_strings = true ) const {
481490 if (!isOk ()) return false ;
482491 switch (current_type) {
483492 case ' "' : // we have a string
484- os << ' "' << get_string () << ' "' ;
493+ os << ' "' ;
494+ if (escape_strings) {
495+ print_with_escapes (get_string (), os);
496+ } else {
497+ os << get_string ();
498+ }
499+ os << ' "' ;
485500 break ;
486501 case ' l' : // we have a long int
487502 os << get_integer ();
488503 break ;
489504 case ' d' :
490- os << get_double ();
505+ os << get_double ();
506+ break ;
491507 case ' n' : // we have a null
492508 os << " null" ;
493509 break ;
0 commit comments