33 return string_view(token.data() + 1, token.size() - 2U);
36std::string string_from_token(string_view token, std::true_type is_escaped);
134 expected_key_delimiter,
162 template <
typename TSelf, ast_node_type KIndexToken>
175 return string_view(_token_begin,
static_cast<const TSelf&
>(*this).token_size());
187 const char* _token_begin;
190 template <
typename TSelf, ast_node_type KIndexToken, std::
size_t KTokenSize>
198 constexpr std::size_t token_size()
const
204 template <
typename TSelf, ast_node_type KIndexToken>
210 _token_size(token_size)
213 constexpr std::size_t token_size()
const
219 std::size_t _token_size;
248 return _element_count;
252 std::size_t _element_count;
274 return _element_count;
278 std::size_t _element_count;
288 template <
typename TSelf, ast_node_type KIndexToken,
bool KEscaped>
294 using value_type = std::conditional_t<KEscaped, std::string, string_view>;
299 _token_size(token_size)
317 constexpr std::size_t token_size()
const
324 return detail::string_from_token(this->
token_raw(), std::integral_constant<bool, KEscaped>());
328 std::size_t _token_size;
360 bool value()
const noexcept
371 bool value()
const noexcept
390 std::int64_t
value()
const;
398 double value()
const;
406 _error_code(error_code)
441 template <
typename T,
typename...
TArgs>
455 template <
typename FVisitor>
458 return std::visit(std::forward<FVisitor>(
visitor), _impl);
462 template <
typename FVisitor>
465 return std::visit(std::forward<FVisitor>(
visitor),
as_key());
471 return visit([](
const auto&
x) {
return x.type(); });
478 return visit([](
const auto&
x) {
return x.token_raw(); });
484 template <
typename T>
487 return std::get<T>(_impl);
493 std::variant<key_canonical, key_escaped>
as_key()
const
495 if (
type() == ast_node_type::key_canonical)
505template <
typename TSelf, ast_node_type KIndexToken>
508 return ast_node(ast_node::storage_type(
static_cast<const TSelf&
>(*
this)));
ast_error
Error code encountered while building the AST.
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 (]).
string_view token_raw() const
static constexpr ast_node_type type()
Get the ast_node_type type.
constexpr bool escaped() const noexcept
Did the source JSON for this string contain escape sequences? If this is true, JSON escape sequences ...
std::conditional_t< KEscaped, std::string, string_view > value_type
The return type of value is based on if the string is canonical or escaped.
constexpr bool canonical() const noexcept
Was the source JSON for this string encoded in the canonical UTF-8 representation?...
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.
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.
const storage_type & storage() const
Get the std::variant that backs this type.
string_view token_raw() const
Get a view of the raw token.
const T & as() const
Get the underlying data of this node as T.
An adapter for enumeration types.
A wrapper type for creating a result with result_state::error.
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_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.
Pulls in an implementation of optional.
Pulls in an implementation of string_view.
std::string_view string_view
A non-owning reference to a string.