JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
jsonv::parse_options Class Reference

Configuration for various parsing options. More...

#include <jsonv/parse.hpp>

Classes

struct  k
 

Public Types

enum class  encoding { utf8 , utf8_strict }
 The encoding format for strings. More...
 
using size_type = value::size_type
 

Public Member Functions

 parse_options ()
 Create an instance with the default options.
 
encoding string_encoding () const
 
parse_optionsstring_encoding (encoding)
 
std::optional< size_type > max_structure_depth () const
 
parse_optionsmax_structure_depth (std::optional< size_type > depth)
 
bool require_document () const
 
parse_optionsrequire_document (bool)
 
bool complete_parse () const
 
parse_optionscomplete_parse (bool)
 
bool comments () const
 
parse_optionscomments (bool)
 

Static Public Member Functions

static parse_options create_default ()
 Create a parser with the default options – this is the same result as the default constructor, but might be helpful if you like to be more explicit.
 
static parse_options create_strict ()
 Create a strict parser.
 

Detailed Description

Configuration for various parsing options.

All parse functions should take in a parse_options as a paramter and should respect your settings.

Definition at line 62 of file parse.hpp.

Member Typedef Documentation

◆ size_type

using jsonv::parse_options::size_type = value::size_type

Definition at line 65 of file parse.hpp.

Member Enumeration Documentation

◆ encoding

The encoding format for strings.

Enumerator
utf8 

Default UTF-8 encoding scheme.

    \see http://www.unicode.org/versions/Unicode6.2.0/ch03.pdf#G7404 
utf8_strict 

Like utf8, but check that there are no unprintable characters in the input stream (see std::isprint).

To contrast this with utf8, this mode will reject things such as the tab and newline characters, while this will reject them.

Definition at line 68 of file parse.hpp.

Member Function Documentation

◆ comments()

bool jsonv::parse_options::comments ( ) const
inline

Are JSON comments allowed? While there is no official syntax for JSON comments, this uses the de-facto standard of ECMAScript-style block comments: /* comment *&zwj;/. If this is enabled, comments are treated exactly like whitespace.

Definition at line 144 of file parse.hpp.

◆ complete_parse()

bool jsonv::parse_options::complete_parse ( ) const
inline

Should the input be completely parsed to consider the parsing a success? This is on by default. Disabling this option can be useful for situations where JSON input is coming from some stream and you wish to process distinct objects separately.

Definition at line 136 of file parse.hpp.

◆ create_strict()

static parse_options jsonv::parse_options::create_strict ( )
static

Create a strict parser.

In general, these options are meant to fail on anything that is not a 100% valid JSON document. More specifically:

complete_parse() == true
comments() == false
encoding string_encoding() const
Definition parse.hpp:110
bool require_document() const
Definition parse.hpp:128
bool comments() const
Definition parse.hpp:144
std::optional< size_type > max_structure_depth() const
Definition parse.hpp:120
@ utf8_strict
Like utf8, but check that there are no unprintable characters in the input stream (see std::isprint).
bool complete_parse() const
Definition parse.hpp:136

◆ max_structure_depth()

std::optional< size_type > jsonv::parse_options::max_structure_depth ( ) const
inline

The maximum allowed nesting depth of any structure in the JSON document. The JSON specification technically limits the depth to 20, but very few implementations actually conform to this, so it is fairly dangerous to set this value. By default, the value is nullopt, which means implementations should limit structure depth to k::max_structure_depth. Setting depth to a value above k::max_structure_depth is will cause std::invalid_argument to be thrown from parse functions.

Definition at line 120 of file parse.hpp.

◆ require_document()

bool jsonv::parse_options::require_document ( ) const
inline

If set to true, the result of a parse is required to have kind of kind::object or kind::array. By default, this is turned off, which will allow parse to return values with kind::string or kind::integer.

Definition at line 128 of file parse.hpp.

◆ string_encoding()

encoding jsonv::parse_options::string_encoding ( ) const
inline

The output encoding for multi-byte characters in strings. The default value is encoding::utf8.

Definition at line 110 of file parse.hpp.


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