3#ifndef PRAVEENJSON_PARSER_H
4#define PRAVEENJSON_PARSER_H
9 struct pJsonParserImpl;
77 virtual bool onInt(int64_t aValue);
79 virtual bool onUInt(uint64_t aValue);
83 virtual bool onString(
const std::string& aValue);
91 virtual bool onKey(
const std::string& aKey);
114 pjson::Allocator& allocator() const noexcept;
117 pjson parse(const std::
string& aInput) const;
119 pjson parse(const
char* aInput,
size_t aSize) const;
123 pjson parse(const
char* aInput,
size_t aSize,
Error& aError) const;
125 pjson parseStream(std::istream& aInput) const;
127 pjson parseStream(std::istream& aInput,
Error& aError) const;
130 bool parseSax(const std::
string& aInput,
SaxHandler& aHandler) const;
132 bool parseSax(const
char* aInput,
size_t aSize,
SaxHandler& aHandler) const;
136 bool parseSax(const
char* aInput,
size_t aSize,
SaxHandler& aHandler,
Error& aError) const;
138 bool parseSaxStream(std::istream& aInput,
SaxHandler& aHandler) const;
143 pJsonParserImpl* _impl;
Configured, reusable JSON parser for DOM and SAX input.
pJsonParser & operator=(const pJsonParser &aOther)
Copies parser configuration while borrowing aOther's allocator.
pJsonParser(const pJsonParser &aOther)
Copies the parser configuration while borrowing the same allocator.
pJsonParser(pjson::Allocator &aAllocator, const Options &aOptions=Options())
Uses borrowed aAllocator, which must outlive this parser and its DOM results.
pJsonParser(pJsonParser &&aOther) noexcept
Transfers parser configuration and leaves aOther usable with defaults.
const Options & options() const noexcept
Returns the immutable options used by every parse call.
pJsonParser & operator=(pJsonParser &&aOther) noexcept
Transfers parser configuration and leaves aOther usable with defaults.
~pJsonParser()
Releases the private parser configuration.
pJsonParser(const Options &aOptions=Options())
Uses the default DOM allocator and default parser options.
Owning, mutable JSON value with deep-copy semantics.
Namespace containing the pjson public API.
Structured result for DOM and SAX parsing.
size_t column
One-based byte column.
bool ok
True when the most recent parse succeeded.
std::string message
Human-readable diagnostic; wording is not stable. Constructs the successful start-of-input state.
size_t offset
Zero-based input byte offset.
size_t line
One-based source line.
Code code
Stable machine-facing result category.
Code
Stable categories for programmatic parse-failure handling.
@ Syntax
The input violates JSON grammar.
@ InputLimit
Input exceeded maxInputBytes.
@ CallbackError
A SAX callback cancelled or threw.
@ DepthLimit
Nesting exceeded the effective depth limit.
@ NodeLimit
Values processed exceeded maxNodes.
@ StreamError
Reading from the input stream failed.
@ InvalidEncoding
UTF-8 or an escaped Unicode value is invalid.
@ AllocationFailure
Parser, DOM, or callback allocation failed.
@ DuplicateKey
A repeated object name was rejected.
@ NumberRange
A number is outside the configured representation policy.
Bounds parsing work and selects duplicate-key and number policies.
NumberPolicy
Controls numeric tokens that cannot be represented exactly.
@ RejectUnrepresentableNumbers
Reject range overflow and nonzero underflow.
NumberPolicy numberPolicy
Unrepresentable-number policy. Selects strict defaults and bounded parser resources.
size_t maxNodes
Maximum values processed; zero is unlimited.
int maxDepth
Nesting limit; non-positive means one level.
size_t maxInputBytes
Maximum input bytes; zero is unlimited.
DuplicateKeyPolicy
Controls how repeated object member names are handled.
@ KeepFirstDuplicate
Retain the first value and discard later values.
@ RejectDuplicateKeys
Fail when a name occurs more than once.
DuplicateKeyPolicy duplicateKeys
Duplicate object-name policy.
Event sink for non-owning SAX parsing.
virtual bool onBool(bool aValue)
Receives a boolean; return false to cancel.
virtual bool onKey(const std::string &aKey)
Receives a borrowed decoded key; return false to cancel.
virtual bool onNull()
Receives null; return false to cancel.
virtual bool onUInt(uint64_t aValue)
Receives an unsigned integer above the signed range; return false to cancel.
virtual bool onEndArray()
Marks the end of an array; return false to cancel.
virtual ~SaxHandler()
Enables destruction through a handler base pointer.
virtual bool onStartArray()
Marks the beginning of an array; return false to cancel.
virtual bool onInt(int64_t aValue)
Receives a signed integer; return false to cancel.
virtual bool onStartObject()
Marks the beginning of an object; return false to cancel.
virtual bool onString(const std::string &aValue)
Receives a borrowed decoded string; return false to cancel.
virtual bool onEndObject()
Marks the end of an object; return false to cancel.
virtual bool onDouble(double aValue)
Receives a floating-point number; return false to cancel.
Runtime allocator for persistent DOM storage.