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).
* Delegate constant string construction to SetStringRaw
* Delegate "const Ch*" overloads to GenericValue variants
of operator[], FindMember and RemoveMember
* Remove repeated template arguments in nested struct Array
(cherry-picked from ca9b0332d)
Instead of hard-coding the value 0 for the parseFlags in the
various parsing overloads, explicitly use kParseDefaultFlags
to provide more self-documenting code.
In order to activate the suppression of "-Weffc++" warnings in the
template meta function classes (non-virtual destructor), move the
inclusion of the meta-function header `internal/meta.h` after the
suppression pragma.
Add dedicated class-based member iterator to prepare the switch to a
(safe) API change to return MemberEnd() from FindMember().
Pointer-based iterator can be kept by defining
RAPIDJSON_NOMEMBERITERATORCLASS. This may be useful for platforms without
a working <iterator> header.
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.
Parse errors is represented as enum type `ParseErrorCode`.
Error texts are optional for user.
Added `GetParseError_En()` in `error/en.h`, user can localize this file
into other files. User may dynamically change the locale in runtime.
Compound types (object and array) call ParseString() and ParseValue()
for key and values. If there is parse errors inside those calls, it
should stop continue parsing. Otherwise, it may be possible to continue
parsing and calling handler incorrectly.
For example, in ["a\u,","b"], \u generates an error (it should follow
but 4 hex digits), the parser continues to treat the first comma as
element separator, and treat "," as a JSON string and call the handler.
It may be unacceptable in the application code.
The C++ standard does not include the C99 macros used to set the (U)INT64
constants in document.h and reader.h (see adf66292 and ce1fece2).
Many implementations include their definition when the
__STDC_CONSTANT_MACROS preprocessor symbol is defined.
See e.g. http://www.cprogramdevelop.com/5272623/,
needed to successfully build in travis-ci.org's environment.
To allow deep copying from an existing GenericValue, an
explicit "copy constructor" (with required Allocator param)
and an "CopyFrom" assignment function are added.
Document d; Document::AllocatorType& a = d.GetAllocator();
Value v1("foo");
// Value v2(v1); // not allowed
Value v2(v1,a); // make a copy
RAPIDJSON_ASSERT(v1.IsString()); // v1 untouched
d.SetArray().PushBack(v1,a).PushBack(v2,a);
RAPIDJSON_ASSERT(v1.Empty() && v2.Empty());
v2.CopyFrom(d,a); // copy whole document
RAPIDJSON_ASSERT(d.IsArray() && d.Size()); // d untouched
v1.SetObject().AddMember( "array", v2, a );
d.PushBack(v1,a);
Additionally, the Handler implementation in GenericDocument is made
private again, restricting access to GenericReader and GenericValue.
Instead of always just shallowly referencing the potentially allocated
strings when calling the Handler::String function, request a copy in
case the string has been allocated from an Allocator before.
This is necessary to avoid double free()s of the string memory,
especially when using the Handler to create a deep copy of a Value.
The explicit comparison against '0' is done to suppress the warning
C4800 on MSVC, see pah/rapidjson#5.
As proposed in other patches, it is convenient to pass a user-defined
precision for the (programmatic) output of a single double value
to an OutputStream.
This patch adds an additional overload with an explicit precision
argument to the (Pretty)Writer class templates.
Writing a double to an OutputStream current prints at most 6 significant
digits (according to the C standard).
The function SetDoublePrecision(), added to the Writer classes
can be used to fluently set the precision, i.e. the number of
significant digits to use for writing the double:
Writer<...> writer(...);
d.Accept(writer.SetDoublePrecision(12));