30inline std::string_view string_from_token(std::string_view token, std::false_type is_escaped
JSONV_UNUSED)
32 return std::string_view(token.data() + 1, token.size() - 2U);
35std::string string_from_token(std::string_view token, std::true_type is_escaped);
133 expected_key_delimiter,
161 template <
typename TSelf, ast_node_type KIndexToken>
174 return std::string_view(_token_begin,
static_cast<const TSelf&
>(*this).token_size());
186 const char* _token_begin;
189 template <
typename TSelf, ast_node_type KIndexToken, std::
size_t KTokenSize>
197 constexpr std::size_t token_size()
const
203 template <
typename TSelf, ast_node_type KIndexToken>
209 _token_size(token_size)
212 constexpr std::size_t token_size()
const
218 std::size_t _token_size;
247 return _element_count;
251 std::size_t _element_count;
273 return _element_count;
277 std::size_t _element_count;
287 template <
typename TSelf, ast_node_type KIndexToken,
bool KEscaped>
293 using value_type = std::conditional_t<KEscaped, std::string, std::string_view>;
298 _token_size(token_size)
316 constexpr std::size_t token_size()
const
323 return detail::string_from_token(this->
token_raw(), std::integral_constant<bool, KEscaped>());
327 std::size_t _token_size;
359 bool value()
const noexcept
370 bool value()
const noexcept
389 std::int64_t
value()
const;
397 double value()
const;
405 _error_code(error_code)
440 template <
typename T,
typename...
TArgs>
454 template <
typename FVisitor>
457 return std::visit(std::forward<FVisitor>(
visitor), _impl);
461 template <
typename FVisitor>
464 return std::visit(std::forward<FVisitor>(
visitor),
as_key());
470 return visit([](
const auto&
x) {
return x.type(); });
477 return visit([](
const auto&
x) {
return x.token_raw(); });
483 template <
typename T>
486 return std::get<T>(_impl);
492 std::variant<key_canonical, key_escaped>
as_key()
const
494 if (
type() == ast_node_type::key_canonical)
504template <
typename TSelf, ast_node_type KIndexToken>
507 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 (]).
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.
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_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.