In case of a user-defined RAPIDJSON_PARSE_ERROR_NORETURN that throws
an exception instead of using the Rapidjson ParseError API, the early
return paths performing the stack unwinding manually can be omitted as
well.
This patch provides a customizable RAPIDJSON_PARSE_ERROR_EARLY_RETURN
macro to remove these (then unneeded) control paths from the parsing
implementation (with and without a return value).
Secondly, clearing the parse stack is moved to a small helper struct
that calls stack_.Clear() from its destructor. This avoids the need
for the 'goto' in the ParseStream function and ensures proper cleanup
even if e.g. a user-defined Allocator throws an exception.
In order to enable the customization of the error macros
- RAPIDJSON_PARSE_ERROR_NORETURN
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN
the user may need to have access to the ParseErrorCode enum
already. This requires a separate header location than the
GenericReader.
MSVC with enabled RAPIDJSON_SSE2/RAPIDJSON_SSE42 requires the explicit
definition of the `_BitScanForward` intrinsic. This can be reliably
ensured by including "intrin.h" and properly marking '_BitScanForward'
as intrinsic.
Confirmed on MSVC 2005, 2008.
Should fix https://code.google.com/p/rapidjson/issues/detail?id=96
The error messages in ParseNumber used `is.Tell` to report the
position of the number parsing error. Depending on the copy
optimization of the current stream, this can lead to different
behaviour (beginning of number vs. position of error).
Instead of hard-coding the value 0 for the parseFlags in the
various parsing overloads, explicitly use kParseDefaultFlags
to provide more self-documenting code.
rapidjson.h:
* StreamLocalCopy: add default argument to copy optimization selector
based on StreamTraits of Stream parameter
* drop operator->, operator*
* make Stream (reference) member public
* drop empty destructor
reader.h:
* add local references, initialized from "copy"
(reverts algorithmic bodies back to plain 's.xx()')
The previous optimization #32 has problem that restoration requires
assignment operator.
Change the backup/restore process using a template wrapper class to
select code path.