TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ sax_parse() [2/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename InputType , typename SAX >
static bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::sax_parse ( InputType &&  i,
SAX *  sax,
input_format_t  format = input_format_t::json,
const bool  strict = true,
const bool  ignore_comments = false 
)
inlinestatic

generate SAX events

The SAX event lister must follow the interface of json_sax.

This function reads from a compatible input. Examples are:

  • an std::istream object
  • a FILE pointer
  • a C-style array of characters
  • a pointer to a null-terminated string of single byte characters
  • an object obj for which begin(obj) and end(obj) produces a valid pair of iterators.
Parameters
[in]iinput to read from
[in,out]saxSAX event listener
[in]formatthe format to parse (JSON, CBOR, MessagePack, or UBJSON)
[in]strictwhether the input has to be consumed completely
[in]ignore_commentswhether comments should be ignored and treated like whitespace (true) or yield a parse error (true); (optional, false by default); only applies to the JSON file format.
Returns
return value of the last processed SAX event
Exceptions
parse_error.101if a parse error occurs; example: ""unexpected end of input; expected string literal""
parse_error.102if to_unicode fails or surrogate error
parse_error.103if to_unicode fails

@complexity Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the SAX consumer sax has a super-linear complexity.

Note
A UTF-8 byte order mark is silently ignored.

@liveexample{The example below demonstrates the sax_parse() function reading from string and processing the events with a user-defined SAX event consumer.,sax_parse}

Since
version 3.2.0

Definition at line 24760 of file json.hpp.

24764 {
24765 auto ia = detail::input_adapter(std::forward<InputType>(i));
24766 return format == input_format_t::json
24767 ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)
24768 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
24769 }