Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/miloyip/rapidjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilo Yip <miloyip@gmail.com>2014-07-28 14:45:06 +0400
committerMilo Yip <miloyip@gmail.com>2014-07-28 14:45:06 +0400
commite6f344637b3163e74f0f1bd5f94d5595ed36d9d1 (patch)
treeae5e21fe32ef88a63461cb53dafd486604082139 /include
parentc5458953687d5390cd4084eb2051eb373187565f (diff)
parent3d106085c102739a23cfd73a6e2797bebacfd791 (diff)
Merge pull request #83 from miloyip/issue75stopwhendone
Issue75stopwhendone
Diffstat (limited to 'include')
-rw-r--r--include/rapidjson/reader.h18
1 files changed, 13 insertions, 5 deletions
diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h
index aa8ca017..084cb1e4 100644
--- a/include/rapidjson/reader.h
+++ b/include/rapidjson/reader.h
@@ -65,7 +65,8 @@ enum ParseFlag {
kParseDefaultFlags = 0, //!< Default parse flags. Non-destructive parsing. Text strings are decoded into allocated buffer.
kParseInsituFlag = 1, //!< In-situ(destructive) parsing.
kParseValidateEncodingFlag = 2, //!< Validate encoding of JSON strings.
- kParseIterativeFlag = 4 //!< Iterative(constant complexity in terms of function call stack size) parsing.
+ kParseIterativeFlag = 4, //!< Iterative(constant complexity in terms of function call stack size) parsing.
+ kParseStopWhenDoneFlag = 8 //!< After parsing a complete JSON root from stream, stop further processing the rest of stream. When this flag is used, parser will not generate kParseErrorDocumentRootNotSingular error.
};
///////////////////////////////////////////////////////////////////////////////
@@ -309,11 +310,13 @@ public:
}
RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
- SkipWhitespace(is);
+ if (!(parseFlags & kParseStopWhenDoneFlag)) {
+ SkipWhitespace(is);
- if (is.Peek() != '\0') {
- RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorDocumentRootNotSingular, is.Tell());
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
+ if (is.Peek() != '\0') {
+ RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorDocumentRootNotSingular, is.Tell());
+ RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
+ }
}
}
@@ -1192,6 +1195,11 @@ private:
}
state = d;
+
+ // Do not further consume streams if a root JSON has been parsed.
+ if ((parseFlags & kParseStopWhenDoneFlag) && state == IterativeParsingFinishState)
+ break;
+
SkipWhitespace(is);
}