miloyip/rapidjson — pull request #57 by pah (2014-07-08 18:51:14+00:00)
Title: Improved handling of (constant) strings

In order to avoid issues like reported in #38 and partially addressed in #47, this pull-request proposes a new set of APIs to handle non-copied strings more safely.

The basic idea is to allow only string **literals** (e.g. `"foo"`) being passed implicitly to the various "const string parameters". This is achieved by adding a small wrapper `GenericStringRef` that can be implicitly constructed from fixed-size, constant character **arrays**, but **not** from plain character pointers.

Some bells and whistles have been added to `GenericValue` to avoid any implicit use of plain char pointers as constant strings. If users can guarantee, that a char pointer has a sufficient lifetime, they can mark a string via the new `StringRef` function (internally constructing a constant string reference).

Example code:
````cpp
Value v("foo"); // ok, no need to copy & calculate length
const char foo[] = "foo";
v.SetString(foo); // ok

const char* bar = foo;
// Value x(bar); // not ok, can't rely on bar's lifetime
Value x(StringRef(bar)); // lifetime explicitly guaranteed by user
Value y(StringRef(bar, 3)); // ok, explicitly pass length
````

All string-related overloads have been adjusted accordingly:
* constructors
* `operator=`
* `PushBask`
* `AddMember`

See the additions to `valuetest.cpp` for the possible and now forbidden variants.
Extensive documentation has been added.
Looking forward to comments.