23 RAPIDJSON_DIAG_OFF(c++98-compat)
28 static const char kJson[] =
"{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3,-1],\"u64\":1234567890123456789,\"i64\":-1234567890123456789}";
29 static const char kPrettyJson[] =
31 " \"hello\": \"world\",\n"
43 " \"u64\": 1234567890123456789,\n"
44 " \"i64\": -1234567890123456789\n"
47 static const char kPrettyJson_FormatOptions_SLA[] =
49 " \"hello\": \"world\",\n"
55 " \"a\": [1, 2, 3, -1],\n"
56 " \"u64\": 1234567890123456789,\n"
57 " \"i64\": -1234567890123456789\n"
65 reader.
Parse(s, writer);
75 reader.
Parse(s, writer);
85 reader.
Parse(s, writer);
88 "\t\"hello\": \"world\",\n"
100 "\t\"u64\": 1234567890123456789,\n"
101 "\t\"i64\": -1234567890123456789\n"
115 #if RAPIDJSON_HAS_STDSTRING
134 Ch Peek()
const { assert(
false);
return '\0'; }
135 Ch Take() { assert(
false);
return '\0'; }
136 size_t Tell()
const {
return 0; }
154 std::stringstream ss;
160 reader.
Parse(s, writer);
168 char filename[L_tmpnam];
176 reader.
Parse(s, writer);
179 fp = fopen(filename,
"rb");
180 fseek(fp, 0, SEEK_END);
181 size_t size =
static_cast<size_t>(ftell(fp));
182 fseek(fp, 0, SEEK_SET);
183 char*
json =
static_cast<char*
>(malloc(size + 1));
184 size_t readLength = fread(
json, 1, size, fp);
185 json[readLength] =
'\0';
199 const char json[] =
"[\"Hello\\nWorld\", 123.456]";
206 " \"raw\": [\"Hello\\nWorld\", 123.456]\n"
263 double nan = std::numeric_limits<double>::quiet_NaN();
282 double inf = std::numeric_limits<double>::infinity();
306 char buf[100] =
"Hello";
319 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
323 writer.StartObject();
connection< TProtocol > & operator=(const connection< TProtocol > &obj)
C-runtime library allocator.
Wrapper of C file stream for output using fwrite().
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
const Ch * GetString() const
OStreamWrapper(std::ostream &os)
Writer with indentation and spacing.
bool EndArray(SizeType memberCount=0)
PrettyWriter & SetFormatOptions(PrettyFormatOptions options)
Set pretty writer formatting options.
bool Key(const Ch *str, SizeType length, bool copy=false)
bool RawValue(const Ch *json, size_t length, Type type)
Write a raw JSON value.
bool EndObject(SizeType memberCount=0)
PrettyWriter & SetIndent(Ch indentChar, unsigned indentCharCount)
Set custom indentation.
bool String(const Ch *str, SizeType length, bool copy=false)
bool IsComplete() const
Checks whether the output is a complete JSON.
#define EXPECT_THROW(statement, expected_exception)
#define EXPECT_TRUE(condition)
#define EXPECT_STREQ(s1, s2)
#define ASSERT_TRUE(condition)
#define EXPECT_FALSE(condition)
BasicOStreamWrapper< std::ostream > OStreamWrapper
@ kFormatSingleLineArray
Format arrays on a single line.
TEST(PrettyWriter, Basic)
FILE * TempFile(char *filename)
@ kWriteNanAndInfFlag
Allow writing of Infinity, -Infinity and NaN.