From 21eef55907c968985a5a75e2421c96be0bad38ff Mon Sep 17 00:00:00 2001 From: Tyler Kennedy Date: Wed, 6 Mar 2019 12:13:55 -0500 Subject: [PATCH] Changes to the behaviour of move_forward to make it suitable for iteration. (Closes #73) (#103) --- src/parsedjsoniterator.cpp | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/parsedjsoniterator.cpp b/src/parsedjsoniterator.cpp index f5657b3ab..3ba8c8c58 100644 --- a/src/parsedjsoniterator.cpp +++ b/src/parsedjsoniterator.cpp @@ -73,31 +73,30 @@ uint8_t ParsedJson::iterator::get_scope_type() const { } bool ParsedJson::iterator::move_forward() { - if(location + 1 >= tape_length) { - return false; // we are at the end! - } - // we are entering a new scope - if ((current_type == '[') || (current_type == '{')){ - depth++; - depthindex[depth].start_of_scope = location; - depthindex[depth].scope_type = current_type; - } - location = location + 1; - current_val = pj.tape[location]; - current_type = (current_val >> 56); - // if we encounter a scope closure, we need to move up - while ((current_type == ']') || (current_type == '}')) { if(location + 1 >= tape_length) { return false; // we are at the end! } - depth--; - if(depth == 0) { - return false; // should not be necessary + + if ((current_type == '[') || (current_type == '{')){ + // We are entering a new scope + depth++; + depthindex[depth].start_of_scope = location; + depthindex[depth].scope_type = current_type; + } else if ((current_type == ']') || (current_type == '}')) { + // Leaving a scope. + depth--; + if(depth == 0) { + // Should not be necessary + return false; + } + } else if ((current_type == 'd') || (current_type == 'l')) { + // d and l types use 2 locations on the tape, not just one. + location += 1; } - location = location + 1; + + location += 1; current_val = pj.tape[location]; current_type = (current_val >> 56); - } return true; }