Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
pretty.cpp
Go to the documentation of this file.
1
// JSON pretty formatting example
2
// This example can only handle UTF-8. For handling other encodings, see prettyauto example.
3
4
#include "
rapidjson/reader.h
"
5
#include "
rapidjson/prettywriter.h
"
6
#include "
rapidjson/filereadstream.h
"
7
#include "
rapidjson/filewritestream.h
"
8
#include "
rapidjson/error/en.h
"
9
10
using namespace
rapidjson
;
11
12
int
main
(
int
,
char
*[]) {
13
// Prepare reader and input stream.
14
Reader
reader;
15
char
readBuffer[65536];
16
FileReadStream
is(stdin, readBuffer,
sizeof
(readBuffer));
17
18
// Prepare writer and output stream.
19
char
writeBuffer[65536];
20
FileWriteStream
os(stdout, writeBuffer,
sizeof
(writeBuffer));
21
PrettyWriter<FileWriteStream>
writer(os);
22
23
// JSON reader parse from the input stream and let writer generate the output.
24
if
(!reader.
Parse
<
kParseValidateEncodingFlag
>(is, writer)) {
25
fprintf(stderr,
"\nError(%u): %s\n"
,
static_cast<
unsigned
>
(reader.
GetErrorOffset
()),
GetParseError_En
(reader.
GetParseErrorCode
()));
26
return
1;
27
}
28
29
return
0;
30
}
main
int main()
Definition
archivertest.cpp:283
FileReadStream
File byte stream for input using fread().
Definition
filereadstream.h:34
FileWriteStream
Wrapper of C file stream for output using fwrite().
Definition
filewritestream.h:32
GenericReader::Parse
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition
reader.h:557
GenericReader::GetParseErrorCode
ParseErrorCode GetParseErrorCode() const
Get the ParseErrorCode of last parsing.
Definition
reader.h:683
GenericReader::GetErrorOffset
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
Definition
reader.h:686
PrettyWriter
Writer with indentation and spacing.
Definition
prettywriter.h:48
en.h
Reader
GenericReader< UTF8< char >, UTF8< char >, CrtAllocator > Reader
Definition
fwd.h:90
filereadstream.h
filewritestream.h
GetParseError_En
RAPIDJSON_NAMESPACE_BEGIN const RAPIDJSON_ERROR_CHARTYPE * GetParseError_En(ParseErrorCode parseErrorCode)
Maps error code of parsing into error message.
Definition
en.h:36
rapidjson
main RapidJSON namespace
prettywriter.h
reader.h
kParseValidateEncodingFlag
@ kParseValidateEncodingFlag
Validate encoding of JSON strings.
Definition
reader.h:148
external
rapidjson
example
pretty
pretty.cpp
Generated on
for Electroneum by
1.17.0