sajson
High-Performance JSON Parser
|
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... | |
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.
|
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.
|
inline |
If is_valid(), returns the document's root value.
|
inline |
If not is_valid(), returns the one-based line number where the parse failed.
|
inline |
If not is_valid(), returns the one-based column number where the parse failed.
|
inline |
If not is_valid(), returns a std::string indicating why the parse failed.
|
inline |
If not is_valid(), returns a null-terminated C string indicating why the parse failed.
|
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().