19#include <initializer_list>
33inline std::string_view string_from_token(std::string_view token, std::false_type is_escaped
JSONV_UNUSED)
35 return std::string_view(token.data() + 1, token.size() - 2U);
39std::string string_from_token(std::string_view token, std::true_type is_escaped);
137 expected_key_delimiter,
167 template <
typename TSelf, ast_node_type KIndexToken>
182 return std::string_view(_token_begin,
static_cast<const TSelf&
>(*this).token_size());
195 const char* _token_begin;
198 template <
typename TSelf, ast_node_type KIndexToken, std::
size_t KTokenSize>
207 constexpr std::size_t token_size()
const
213 template <
typename TSelf, ast_node_type KIndexToken>
219 _token_size(token_size)
223 constexpr std::size_t token_size()
const
229 std::size_t _token_size;
259 return _element_count;
263 std::size_t _element_count;
286 return _element_count;
290 std::size_t _element_count;
300 template <
typename TSelf, ast_node_type KIndexToken,
bool KEscaped>
306 using value_type = std::conditional_t<KEscaped, std::string, std::string_view>;
311 _token_size(token_size)
332 constexpr std::size_t token_size()
const
340 return detail::string_from_token(this->
token_raw(), std::integral_constant<bool, KEscaped>());
344 std::size_t _token_size;
377 bool value()
const noexcept
389 bool value()
const noexcept
410 std::int64_t
value()
const;
419 double value()
const;
427 _error_code(error_code)
463 template <
typename T,
typename...
TArgs>
478 template <
typename FVisitor>
481 return std::visit(std::forward<FVisitor>(
visitor), _impl);
485 template <
typename FVisitor>
488 return std::visit(std::forward<FVisitor>(
visitor),
as_key());
495 return visit([](
const auto&
x) {
return x.type(); });
519 return visit([](
const auto&
x) {
return x.token_raw(); });
525 template <
typename T>
529 return std::get<T>(_impl);
536 std::variant<key_canonical, key_escaped>
as_key()
const
538 if (
type() == ast_node_type::key_canonical)
548template <
typename TSelf, ast_node_type KIndexToken>
551 return ast_node(ast_node::storage_type(
static_cast<const TSelf&
>(*
this)));
ast_error
Error code encountered while building the AST.
@ close_after_comma
A ] or } arrived where the structure still owed a value – after a , in either kind of structure,...
The beginning of an kind::array ([).
constexpr std::size_t element_count() const
Get the number of elements in the array this token starts. This is useful for reserving memory.
The end of an kind::array (]).
static constexpr ast_node_type type()
Get the ast_node_type type.
std::string_view token_raw() const
constexpr bool escaped() const noexcept
Did the source JSON for this string contain escape sequences? If this is true, JSON escape sequences ...
constexpr bool canonical() const noexcept
Was the source JSON for this string encoded in the canonical UTF-8 representation?...
std::conditional_t< KEscaped, std::string, std::string_view > value_type
The return type of value is based on if the string is canonical or escaped.
The beginning of an kind::object ({).
constexpr std::size_t element_count() const
Get the number of elements in the object this token starts. This is useful for reserving memory.
The end of an kind::object (}).
Represents an entry in a JSON AST.
std::variant< key_canonical, key_escaped > as_key() const
Get the underlying data of this node as one of the key types: key_canonical or key_escaped.
JSONV_PUBLIC std::expected< void, ast_node_type > expect(ast_node_type type) const
ast_node_type type() const
Get the ast_node_type that tells the underlying type of this instance.
auto visit_key(FVisitor &&visitor) const
Convenience function for calling std::visit on a key (see as_key).
auto visit(FVisitor &&visitor) const
Convenience function for calling std::visit on the underlying storage of this node.
std::string_view token_raw() const
Get a view of the raw token.
const storage_type & storage() const
Get the std::variant that backs this type.
const T & as() const
Get the underlying data of this node as T.
An adapter for enumeration types.
Represents a single JSON value, which can be any one of a potential kind, each behaving slightly diff...
Copyright (c) 2014-2020 by Travis Gockel.
#define JSONV_UNUSED
Note that you know the variable is unused, but make the compiler stop complaining about it.
#define JSONV_NODISCARD
Warn if the caller discards the result of this function.
#define JSONV_PUBLIC
This function or class is part of the public API for JSON Voorhees.
ast_node_type
Marker type for an encountered token type.
Copyright (c) 2019-2020 by Travis Gockel.