25RAPIDJSON_DIAG_OFF(c++98-compat)
31 StringStream s(
"{ \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3] } ");
36 reader.
Parse<0>(
s, writer);
37 EXPECT_STREQ(
"{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3]}", buffer.
GetString());
43#define TEST_ROUNDTRIP(json) \
45 StringStream s(json); \
46 StringBuffer buffer; \
47 Writer<StringBuffer> writer(buffer); \
49 reader.Parse<kParseFullPrecisionFlag>(s, writer); \
50 EXPECT_STREQ(json, buffer.GetString()); \
51 EXPECT_TRUE(writer.IsComplete()); \
93#if RAPIDJSON_HAS_STDSTRING
97 writer.
String(std::string(
"Hello\n"));
104 char buf[100] =
"Hello";
117 const char json[] =
"[\" \\\"0123456789ABCDEF\"]";
119 char buffer2[
sizeof(json) + 32];
122 for (
int i = 0; i < 32; i++) {
123 char*
p = buffer2 + i;
143template <
typename TargetEncoding>
155 reader2.
Parse(s2, writer2);
161 const char json[] =
"{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3],\"dollar\":\"\x24\",\"cents\":\"\xC2\xA2\",\"euro\":\"\xE2\x82\xAC\",\"gclef\":\"\xF0\x9D\x84\x9E\"}";
177 for (
size_t i = 0; i < 5; i++) {
190 reader2.
Parse(is, writer2);
205 Ch Peek()
const { assert(
false);
return '\0'; }
206 Ch Take() { assert(
false);
return '\0'; }
207 size_t Tell()
const {
return 0; }
222 StringStream s(
"{ \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3], \"u64\": 1234567890123456789, \"i64\":-1234567890123456789 } ");
224 std::stringstream ss;
230 reader.
Parse<0>(
s, writer);
232 std::string actual = ss.str();
233 EXPECT_STREQ(
"{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3],\"u64\":1234567890123456789,\"i64\":-1234567890123456789}", actual.c_str());
239 StringBuffer buffer;\
240 Writer<StringBuffer> writer(buffer);\
243 T(writer.Bool(
false));
244 T(writer.Bool(
true));
251 T(writer.String(
"foo"));
288 StringBuffer buffer;\
289 Writer<StringBuffer> writer(buffer);\
290 writer.StartObject();\
291 ASSERT_THROW(x, AssertException); \
293 T(writer.Bool(
false));
294 T(writer.Bool(
true));
301 T(writer.StartObject());
302 T(writer.StartArray());
314 writer.
Reset(buffer);
318 writer.
Reset(buffer);
322 writer.
Reset(buffer);
359 StringBuffer buffer;\
360 Writer<StringBuffer> writer(buffer);\
361 EXPECT_FALSE(writer.IsComplete()); \
363 EXPECT_TRUE(writer.IsComplete()); \
366 T(writer.Bool(
true));
367 T(writer.Bool(
false));
373 T(writer.String(
""));
418 EXPECT_STREQ(
"[\"\x24\",\"\xC2\xA2\",\"\xE2\x82\xAC\",\"\xF0\x9D\x84\x9E\",\"\\u0001\",\"\\u001B\"]", buffer.
GetString());
485 double nan = std::numeric_limits<double>::quiet_NaN();
504 double inf = std::numeric_limits<double>::infinity();
534 const char json[] =
"[\"Hello\\nWorld\", 123.456]";
541TEST(Write, RawValue_Issue1152) {
548 EXPECT_EQ(
static_cast<unsigned>(
'n'), out[0]);
549 EXPECT_EQ(
static_cast<unsigned>(
'u'), out[1]);
550 EXPECT_EQ(
static_cast<unsigned>(
'l'), out[2]);
551 EXPECT_EQ(
static_cast<unsigned>(
'l'), out[3]);
552 EXPECT_EQ(
static_cast<unsigned>(0 ), out[4]);
578#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
581 writer.StartObject();
Output stream wrapper with dynamically bound encoding and automatic encoding detection.
C-runtime library allocator.
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
const Ch * GetString() const
size_t GetSize() const
Get the size of string in bytes in the string buffer.
OStreamWrapper(std::ostream &os)
bool EndObject(SizeType memberCount=0)
bool IsComplete() const
Checks whether the output is a complete JSON.
bool Key(const Ch *str, SizeType length, bool copy=false)
bool Double(double d)
Writes the given double value to the stream.
bool String(const Ch *str, SizeType length, bool copy=false)
void Reset(OutputStream &os)
Reset the writer with a new stream.
bool EndArray(SizeType elementCount=0)
bool RawValue(const Ch *json, size_t length, Type type)
Write a raw JSON value.
UTFType
Runtime-specified UTF encoding type of a stream.
@ kUTF32BE
UTF-32 big endian.
@ kUTF16BE
UTF-16 big endian.
@ kUTF32LE
UTF-32 little endian.
@ kUTF16LE
UTF-16 little endian.
#define EXPECT_EQ(val1, val2)
#define EXPECT_THROW(statement, expected_exception)
#define EXPECT_TRUE(condition)
#define EXPECT_STREQ(s1, s2)
#define TEST(test_case_name, test_name)
#define EXPECT_FALSE(condition)
#define ASSERT_THROW(statement, expected_exception)
BasicOStreamWrapper< std::ostream > OStreamWrapper
Dynamically select encoding according to stream's runtime-specified UTF encoding type.
Represents an in-memory output byte stream.
const Ch * GetBuffer() const
Represents an in-memory input byte stream.
@ kWriteNanAndInfFlag
Allow writing of Infinity, -Infinity and NaN.
@ kWriteValidateEncodingFlag
Validate encoding of JSON strings.
#define TEST_ROUNDTRIP(json)
void TestTranscode(const char *json)
memcpy((char *) pInfo->slotDescription, s, l)