pjson 2.0.0
A small, owning JSON value for C++11
Loading...
Searching...
No Matches
ByteDance::pJsonParser Class Reference

Configured, reusable JSON parser for DOM and SAX input. More...

#include <pjson_parser.h>

Classes

struct  Error
 Structured result for DOM and SAX parsing. More...
 
struct  Options
 Bounds parsing work and selects duplicate-key and number policies. More...
 
struct  SaxHandler
 Event sink for non-owning SAX parsing. More...
 

Public Member Functions

 pJsonParser (const Options &aOptions=Options())
 Uses the default DOM allocator and default parser options.
 
 pJsonParser (pjson::Allocator &aAllocator, const Options &aOptions=Options())
 Uses borrowed aAllocator, which must outlive this parser and its DOM results.
 
 ~pJsonParser ()
 Releases the private parser configuration.
 
 pJsonParser (const pJsonParser &aOther)
 Copies the parser configuration while borrowing the same allocator.
 
 pJsonParser (pJsonParser &&aOther) noexcept
 Transfers parser configuration and leaves aOther usable with defaults.
 
pJsonParser & operator= (const pJsonParser &aOther)
 Copies parser configuration while borrowing aOther's allocator.
 
pJsonParser & operator= (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.
 
pjson::Allocator & allocator () const noexcept
 Returns the allocator used for DOM results.
 
pjson parse (const std::string &aInput) const
 Parses one string document by value; failure returns JSON null.
 
pjson parse (const char *aInput, size_t aSize) const
 Parses one exact byte span by value; failure returns JSON null.
 
pjson parse (const std::string &aInput, Error &aError) const
 Parses one string document and resets/reports aError.
 
pjson parse (const char *aInput, size_t aSize, Error &aError) const
 Parses one exact byte span and resets/reports aError.
 
pjson parseStream (std::istream &aInput) const
 Buffers and parses one stream document by value.
 
pjson parseStream (std::istream &aInput, Error &aError) const
 Buffers and parses one stream document and resets/reports aError.
 
bool parseSax (const std::string &aInput, SaxHandler &aHandler) const
 Emits events for one string document.
 
bool parseSax (const char *aInput, size_t aSize, SaxHandler &aHandler) const
 Emits events for one exact byte span.
 
bool parseSax (const std::string &aInput, SaxHandler &aHandler, Error &aError) const
 Emits string-document events and resets/reports aError.
 
bool parseSax (const char *aInput, size_t aSize, SaxHandler &aHandler, Error &aError) const
 Emits byte-span events and resets/reports aError.
 
bool parseSaxStream (std::istream &aInput, SaxHandler &aHandler) const
 Incrementally emits events from a stream.
 
bool parseSaxStream (std::istream &aInput, SaxHandler &aHandler, Error &aError) const
 Incrementally emits events from a stream and resets/reports aError.
 

Detailed Description

Configured, reusable JSON parser for DOM and SAX input.

Configured parser that produces pjson values or SAX events.

The parser depends on the pjson DOM, while pjson itself has no parser dependency. A parser borrows its allocator, owns a copy of its options, and keeps no mutable per-call state, so it may be reused for many inputs.

pJsonParser is declared in <pjson_parser.h>. It owns parser options and borrows the selected pjson::Allocator, which must outlive the parser and all DOM values it creates. Parsing returns pjson by value. The parser stores no per-call mutable state and may be reused; callers must provide separate Error objects and SAX handlers for concurrent calls. The dependency is one-way: pJsonParser uses pjson, while the core pjson header and implementation do not include or call the parser.

See also
ByteDance::pJsonParser::Options
ByteDance::pJsonParser::Error
ByteDance::pJsonParser::SaxHandler

Definition at line 15 of file pjson_parser.h.

Constructor & Destructor Documentation

◆ pJsonParser() [1/4]

ByteDance::pJsonParser::pJsonParser ( const Options &  aOptions = Options())
explicit

Uses the default DOM allocator and default parser options.

◆ pJsonParser() [2/4]

ByteDance::pJsonParser::pJsonParser ( pjson::Allocator &  aAllocator,
const Options &  aOptions = Options() 
)
explicit

Uses borrowed aAllocator, which must outlive this parser and its DOM results.

◆ ~pJsonParser()

ByteDance::pJsonParser::~pJsonParser ( )

Releases the private parser configuration.

◆ pJsonParser() [3/4]

ByteDance::pJsonParser::pJsonParser ( const pJsonParser &  aOther)

Copies the parser configuration while borrowing the same allocator.

◆ pJsonParser() [4/4]

ByteDance::pJsonParser::pJsonParser ( pJsonParser &&  aOther)
noexcept

Transfers parser configuration and leaves aOther usable with defaults.

Member Function Documentation

◆ allocator()

pjson::Allocator & ByteDance::pJsonParser::allocator ( ) const
noexcept

Returns the allocator used for DOM results.

◆ operator=() [1/2]

pJsonParser & ByteDance::pJsonParser::operator= ( const pJsonParser &  aOther)

Copies parser configuration while borrowing aOther's allocator.

◆ operator=() [2/2]

pJsonParser & ByteDance::pJsonParser::operator= ( pJsonParser &&  aOther)
noexcept

Transfers parser configuration and leaves aOther usable with defaults.

◆ options()

const Options & ByteDance::pJsonParser::options ( ) const
noexcept

Returns the immutable options used by every parse call.

◆ parse() [1/4]

pjson ByteDance::pJsonParser::parse ( const char *  aInput,
size_t  aSize 
) const

Parses one exact byte span by value; failure returns JSON null.

◆ parse() [2/4]

pjson ByteDance::pJsonParser::parse ( const char *  aInput,
size_t  aSize,
Error &  aError 
) const

Parses one exact byte span and resets/reports aError.

◆ parse() [3/4]

pjson ByteDance::pJsonParser::parse ( const std::string &  aInput) const

Parses one string document by value; failure returns JSON null.

◆ parse() [4/4]

pjson ByteDance::pJsonParser::parse ( const std::string &  aInput,
Error &  aError 
) const

Parses one string document and resets/reports aError.

◆ parseSax() [1/4]

bool ByteDance::pJsonParser::parseSax ( const char *  aInput,
size_t  aSize,
SaxHandler &  aHandler 
) const

Emits events for one exact byte span.

◆ parseSax() [2/4]

bool ByteDance::pJsonParser::parseSax ( const char *  aInput,
size_t  aSize,
SaxHandler &  aHandler,
Error &  aError 
) const

Emits byte-span events and resets/reports aError.

◆ parseSax() [3/4]

bool ByteDance::pJsonParser::parseSax ( const std::string &  aInput,
SaxHandler &  aHandler 
) const

Emits events for one string document.

◆ parseSax() [4/4]

bool ByteDance::pJsonParser::parseSax ( const std::string &  aInput,
SaxHandler &  aHandler,
Error &  aError 
) const

Emits string-document events and resets/reports aError.

◆ parseSaxStream() [1/2]

bool ByteDance::pJsonParser::parseSaxStream ( std::istream &  aInput,
SaxHandler &  aHandler 
) const

Incrementally emits events from a stream.

◆ parseSaxStream() [2/2]

bool ByteDance::pJsonParser::parseSaxStream ( std::istream &  aInput,
SaxHandler &  aHandler,
Error &  aError 
) const

Incrementally emits events from a stream and resets/reports aError.

◆ parseStream() [1/2]

pjson ByteDance::pJsonParser::parseStream ( std::istream &  aInput) const

Buffers and parses one stream document by value.

◆ parseStream() [2/2]

pjson ByteDance::pJsonParser::parseStream ( std::istream &  aInput,
Error &  aError 
) const

Buffers and parses one stream document and resets/reports aError.


The documentation for this class was generated from the following file: