18template <
typename OutputHandler>
24 outputHandler_(outputHandler), keyString_(keyString), keyLength_(keyLength), filterValueDepth_(), filteredKeyCount_()
27 bool Null() {
return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Null() && EndValue(); }
28 bool Bool(
bool b) {
return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Bool(b) && EndValue(); }
29 bool Int(
int i) {
return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Int(i) && EndValue(); }
30 bool Uint(
unsigned u) {
return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Uint(u) && EndValue(); }
31 bool Int64(
int64_t i) {
return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Int64(i) && EndValue(); }
32 bool Uint64(
uint64_t u) {
return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Uint64(u) && EndValue(); }
33 bool Double(
double d) {
return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Double(
d) && EndValue(); }
34 bool RawNumber(
const Ch* str,
SizeType len,
bool copy) {
return filterValueDepth_ > 0 ? EndValue() : outputHandler_.RawNumber(str,
len, copy) && EndValue(); }
35 bool String (
const Ch* str,
SizeType len,
bool copy) {
return filterValueDepth_ > 0 ? EndValue() : outputHandler_.String (str,
len, copy) && EndValue(); }
38 if (filterValueDepth_ > 0) {
43 filteredKeyCount_.push(0);
44 return outputHandler_.StartObject();
49 if (filterValueDepth_ > 0)
51 else if (
len == keyLength_ && std::memcmp(str, keyString_,
len) == 0) {
52 filterValueDepth_ = 1;
56 ++filteredKeyCount_.top();
57 return outputHandler_.Key(str,
len, copy);
62 if (filterValueDepth_ > 0) {
68 SizeType memberCount = filteredKeyCount_.top();
69 filteredKeyCount_.pop();
70 return outputHandler_.EndObject(memberCount) && EndValue();
75 if (filterValueDepth_ > 0) {
80 return outputHandler_.StartArray();
84 if (filterValueDepth_ > 0) {
89 return outputHandler_.EndArray(elementCount) && EndValue();
97 if (filterValueDepth_ == 1)
98 filterValueDepth_ = 0;
102 OutputHandler& outputHandler_;
103 const char* keyString_;
105 unsigned filterValueDepth_;
106 std::stack<SizeType> filteredKeyCount_;
110template <
typename InputStream>
116 is_(is), keyString_(keyString), keyLength_(keyLength), parseResult_()
120 template <
typename Handler>
124 parseResult_ = reader.
Parse(is_, filter);
135 const char* keyString_;
142 fprintf(stderr,
"filterkeydom key < input.json > output.json\n");
147 char readBuffer[65536];
163 char writeBuffer[65536];
168 document.Accept(writer);
File byte stream for input using fread().
Wrapper of C file stream for output using fwrite().
bool String(const Ch *str, SizeType len, bool copy)
bool Key(const Ch *str, SizeType len, bool copy)
FilterKeyHandler(OutputHandler &outputHandler, const Ch *keyString, SizeType keyLength)
bool EndArray(SizeType elementCount)
bool RawNumber(const Ch *str, SizeType len, bool copy)
const ParseResult & GetParseResult() const
FilterKeyReader(InputStream &is, const Ch *keyString, SizeType keyLength)
bool operator()(Handler &handler)
GenericDocument & Populate(Generator &g)
Populate this document by a generator which produces SAX events.
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Concept for receiving events from GenericReader upon parsing. The functions return true if no error o...
RAPIDJSON_NAMESPACE_BEGIN const RAPIDJSON_ERROR_CHARTYPE * GetParseError_En(ParseErrorCode parseErrorCode)
Maps error code of parsing into error message.
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
unsigned __int64 uint64_t
Result of parsing (wraps ParseErrorCode)
ParseErrorCode Code() const
Get the error code.
size_t Offset() const
Get the error offset, if IsError(), 0 otherwise.