sajson
High-Performance JSON Parser
Public Member Functions | Friends | List of all members
sajson::document Class Reference

Represents the result of a JSON parse: either is_valid() and the document contains a root value or parse error information is available. More...

#include <sajson.h>

Public Member Functions

 document (document &&rhs)
 
bool is_valid () const
 Returns true if the document was parsed successfully. More...
 
value get_root () const
 If is_valid(), returns the document's root value. More...
 
size_t get_error_line () const
 If not is_valid(), returns the one-based line number where the parse failed. More...
 
size_t get_error_column () const
 If not is_valid(), returns the one-based column number where the parse failed. More...
 
std::string get_error_message_as_string () const
 If not is_valid(), returns a std::string indicating why the parse failed. More...
 
const char * get_error_message_as_cstring () const
 If not is_valid(), returns a null-terminated C string indicating why the parse failed. More...
 

Friends

template<typename Allocator >
class parser
 
template<typename AllocationStrategy , typename StringType >
document parse (const AllocationStrategy &strategy, const StringType &string)
 Parses a string of JSON bytes into a document, given an allocation strategy instance. More...
 

Detailed Description

Represents the result of a JSON parse: either is_valid() and the document contains a root value or parse error information is available.

Note that the document holds a strong reference to any memory allocated: any mutable copy of the input text and any memory allocated for the AST data structure. Thus, the document must not be deallocated while any value is in use.

Member Function Documentation

bool sajson::document::is_valid ( ) const
inline

Returns true if the document was parsed successfully.

If true, call get_root() to access the document's root value. If false, call get_error_line(), get_error_column(), and get_error_message_as_cstring() to see why the parse failed.

value sajson::document::get_root ( ) const
inline

If is_valid(), returns the document's root value.

size_t sajson::document::get_error_line ( ) const
inline

If not is_valid(), returns the one-based line number where the parse failed.

size_t sajson::document::get_error_column ( ) const
inline

If not is_valid(), returns the one-based column number where the parse failed.

std::string sajson::document::get_error_message_as_string ( ) const
inline

If not is_valid(), returns a std::string indicating why the parse failed.

const char* sajson::document::get_error_message_as_cstring ( ) const
inline

If not is_valid(), returns a null-terminated C string indicating why the parse failed.

Friends And Related Function Documentation

template<typename AllocationStrategy , typename StringType >
document parse ( const AllocationStrategy &  strategy,
const StringType &  string 
)
friend

Parses a string of JSON bytes into a document, given an allocation strategy instance.

Any kind of string type is valid as long as a mutable_string_view can be constructed from it.

Valid allocation strategies are single_allocation, dynamic_allocation, and bounded_allocation.

A document is returned whether or not the parse succeeds: success state is available by calling document::is_valid().


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