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
 The output encoding for multi-byte characters in strings. The default value is encoding::utf8.
 
parse_options & string_encoding (encoding)
 The output encoding for multi-byte characters in strings. The default value is encoding::utf8.
 
std::optional< size_type > max_structure_depth () const
 The maximum allowed nesting depth of any structure in the JSON document.
 
parse_options & max_structure_depth (std::optional< size_type > depth)
 The maximum allowed nesting depth of any structure in the JSON document.
 
bool require_document () const
 If set to true, the result of a parse is required to have kind of kind::object or kind::array.
 
parse_options & require_document (bool)
 If set to true, the result of a parse is required to have kind of kind::object or kind::array.
 
bool comments () const
 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;/.
 
parse_options & comments (bool)
 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;/.
 

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 parameter and should respect your settings.

Definition at line 57 of file parse.hpp.

Member Typedef Documentation

◆ size_type

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

Definition at line 60 of file parse.hpp.

Member Enumeration Documentation

◆ encoding

enum class jsonv::parse_options::encoding
strong

The encoding format for strings.

Enumerator
utf8 

Default UTF-8 encoding scheme.

Strings must be well-formed UTF-8 as Unicode defines it, which is the same as RFC 3629: every sequence is at most 4 bytes long and is the shortest encoding of its codepoint, and no codepoint is a UTF-16 surrogate (U+D800 through U+DFFF) or above U+10FFFF. A string which breaks any of these is a parse_error, as is an escape sequence naming an unpaired surrogate.

See also
http://www.unicode.org/versions/Unicode6.2.0/ch03.pdf#G7404
utf8_strict 

Like utf8, but also reject unprintable ASCII characters in strings (see std::isprint).

Where utf8 accepts a raw tab or newline character inside a string, this mode rejects it. UTF-8 validation is identical in both modes – the extra strictness is about ASCII control characters only.

Definition at line 63 of file parse.hpp.

Member Function Documentation

◆ comments() [1/2]

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. This is off by default, since RFC 8259 has no comments and a conforming parser rejects them; turn it on for configuration files and other input written in that dialect.

Definition at line 146 of file parse.hpp.

◆ comments() [2/2]

parse_options & jsonv::parse_options::comments ( bool  )

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. This is off by default, since RFC 8259 has no comments and a conforming parser rejects them; turn it on for configuration files and other input written in that dialect.

◆ 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:

comments() == false
encoding string_encoding() const
The output encoding for multi-byte characters in strings. The default value is encoding::utf8.
Definition parse.hpp:113
bool require_document() const
If set to true, the result of a parse is required to have kind of kind::object or kind::array.
Definition parse.hpp:135
bool comments() const
Are JSON comments allowed? While there is no official syntax for JSON comments, this uses the de-fact...
Definition parse.hpp:146
std::optional< size_type > max_structure_depth() const
The maximum allowed nesting depth of any structure in the JSON document.
Definition parse.hpp:125
@ utf8_strict
Like utf8, but also reject unprintable ASCII characters in strings (see std::isprint).

◆ max_structure_depth() [1/2]

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

The maximum allowed nesting depth of any structure in the JSON document.

RFC 8259 lets each implementation choose its own nesting limit, so a document that is valid JSON can still be rejected by a low 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 will cause std::invalid_argument to be thrown from parse functions.

Definition at line 125 of file parse.hpp.

◆ max_structure_depth() [2/2]

parse_options & jsonv::parse_options::max_structure_depth ( std::optional< size_type >  depth)

The maximum allowed nesting depth of any structure in the JSON document.

RFC 8259 lets each implementation choose its own nesting limit, so a document that is valid JSON can still be rejected by a low 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 will cause std::invalid_argument to be thrown from parse functions.

◆ require_document() [1/2]

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 135 of file parse.hpp.

◆ require_document() [2/2]

parse_options & jsonv::parse_options::require_document ( bool  )

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.

◆ 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 113 of file parse.hpp.


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