Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
condense.cpp
Go to the documentation of this file.
1
// JSON condenser example
2
3
// This example parses JSON text from stdin with validation,
4
// and re-output the JSON content to stdout without whitespace.
5
6
#include "
rapidjson/reader.h
"
7
#include "
rapidjson/writer.h
"
8
#include "
rapidjson/filereadstream.h
"
9
#include "
rapidjson/filewritestream.h
"
10
#include "
rapidjson/error/en.h
"
11
12
using namespace
rapidjson
;
13
14
int
main
(
int
,
char
*[]) {
15
// Prepare JSON reader and input stream.
16
Reader
reader;
17
char
readBuffer[65536];
18
FileReadStream
is(stdin, readBuffer,
sizeof
(readBuffer));
19
20
// Prepare JSON writer and output stream.
21
char
writeBuffer[65536];
22
FileWriteStream
os(stdout, writeBuffer,
sizeof
(writeBuffer));
23
Writer<FileWriteStream>
writer(os);
24
25
// JSON reader parse from the input stream and let writer generate the output.
26
if
(!reader.
Parse
(is, writer)) {
27
fprintf(stderr,
"\nError(%u): %s\n"
,
static_cast<
unsigned
>
(reader.
GetErrorOffset
()),
GetParseError_En
(reader.
GetParseErrorCode
()));
28
return
1;
29
}
30
31
return
0;
32
}
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
Writer
JSON writer.
Definition
writer.h:89
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
reader.h
writer.h
external
rapidjson
example
condense
condense.cpp
Generated on
for Electroneum by
1.17.0