A growing implementation of RFC 6901 JSON Pointer. More...
Typedefs | |
| using | sourcemeta::core::Pointer = GenericPointer<JSON::String, PropertyHashJSON<JSON::String>> |
| using | sourcemeta::core::WeakPointer |
| using | sourcemeta::core::PointerWalker = GenericPointerWalker<WeakPointer> |
Functions | |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::get (const JSON &document, const Pointer &pointer) -> const JSON & |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::get (const JSON &document, const WeakPointer &pointer) -> const JSON & |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::get (JSON &document, const WeakPointer &pointer) -> JSON & |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::try_get (const JSON &document, const Pointer &pointer) -> const JSON * |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::try_get (const JSON &document, const WeakPointer &pointer) -> const JSON * |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::get (JSON &document, const Pointer &pointer) -> JSON & |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::get (const JSON &document, const Pointer::Token &token) -> const JSON & |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::get (JSON &document, const Pointer::Token &token) -> JSON & |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::set (JSON &document, const Pointer &pointer, const JSON &value) -> void |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::set (JSON &document, const Pointer &pointer, JSON &&value) -> void |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::remove (JSON &document, const Pointer &pointer) -> bool |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::remove (JSON &document, const WeakPointer &pointer) -> bool |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::to_pointer (const JSON &document) -> Pointer |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::to_pointer (const std::basic_string_view< JSON::Char, JSON::CharTraits > input) -> Pointer |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::fragment_to_pointer (const URI &uri) -> std::optional< Pointer > |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::to_pointer (const WeakPointer &pointer) -> Pointer |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::is_pointer (std::string_view input) noexcept -> bool |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::is_relative_pointer (std::string_view input) noexcept -> bool |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::to_weak_pointer (const Pointer &pointer) -> WeakPointer |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::stringify (const Pointer &pointer, std::basic_ostream< JSON::Char, JSON::CharTraits > &stream) -> void |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::stringify (const WeakPointer &pointer, std::basic_ostream< JSON::Char, JSON::CharTraits > &stream) -> void |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::to_string (const Pointer &pointer) -> std::basic_string< JSON::Char, JSON::CharTraits, std::allocator< JSON::Char > > |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::to_string (const WeakPointer &pointer) -> std::basic_string< JSON::Char, JSON::CharTraits, std::allocator< JSON::Char > > |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::to_uri (const Pointer &pointer) -> URI |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::to_uri (const Pointer &pointer, const URI &base) -> URI |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::to_uri (const WeakPointer &pointer) -> URI |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::to_uri (const WeakPointer &pointer, const URI &base) -> URI |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto | sourcemeta::core::to_uri (const WeakPointer &pointer, const std::string_view base) -> URI |
Variables | |
| const Pointer | sourcemeta::core::empty_pointer |
| const WeakPointer | sourcemeta::core::empty_weak_pointer |
A growing implementation of RFC 6901 JSON Pointer.
This functionality is included as follows:
| class sourcemeta::core::PointerParseError |
This class represents a parsing error.
Public Member Functions | |
| PointerParseError (const std::uint64_t column) | |
| Create a parsing error. | |
| Public Member Functions inherited from sourcemeta::core::JSONParseError | |
| JSONParseError (const std::uint64_t line, const std::uint64_t column) | |
| Create a parsing error. | |
| JSONParseError (const std::uint64_t line, const std::uint64_t column, const char *message) | |
| Create a parsing error with a custom error. | |
| JSONParseError (const std::uint64_t line, const std::uint64_t column, std::string message)=delete | |
| JSONParseError (const std::uint64_t line, const std::uint64_t column, std::string &&message)=delete | |
| JSONParseError (const std::uint64_t line, const std::uint64_t column, std::string_view message)=delete | |
| auto | line () const noexcept -> std::uint64_t |
| Get the line number of the error. | |
| auto | column () const noexcept -> std::uint64_t |
| Get the column number of the error. | |
| class sourcemeta::core::GenericPointer |
A sequence of reference tokens that identifies a location within a JSON document.
Public Types | |
| using | Token = GenericToken<PropertyT, Hash> |
| A single reference token within this pointer. | |
| using | Value = typename Token::Value |
| The JSON value type used for serialisation. | |
| using | Container = std::vector<Token> |
| The underlying sequence container of tokens. | |
Public Member Functions | |
| GenericPointer () noexcept | |
| GenericPointer (std::initializer_list< Token > tokens) | |
| auto | at (const size_type index) const -> const_reference |
| SOURCEMETA_FORCEINLINE auto | back () const -> const_reference |
| SOURCEMETA_FORCEINLINE auto | size () const noexcept -> size_type |
| SOURCEMETA_FORCEINLINE auto | empty () const noexcept -> bool |
| template<class... Args> | |
| SOURCEMETA_FORCEINLINE auto | emplace_back (Args &&...args) -> reference |
| auto | reserve (const typename Container::size_type capacity) -> void |
| SOURCEMETA_FORCEINLINE auto | push_back (const GenericPointer< PropertyT, Hash > &other) -> void |
| SOURCEMETA_FORCEINLINE auto | push_back (GenericPointer< PropertyT, Hash > &&other) -> void |
| template<typename OtherT> requires std::is_same_v<PropertyT, std::reference_wrapper<const OtherT>> | |
| SOURCEMETA_FORCEINLINE auto | push_back (const GenericPointer< OtherT, Hash > &other) -> void |
| SOURCEMETA_FORCEINLINE auto | push_back (const typename Token::Property &property) -> void |
| SOURCEMETA_FORCEINLINE auto | push_back (typename Token::Property &&property) -> void |
| SOURCEMETA_FORCEINLINE auto | push_back (const typename Token::Index &index) -> void |
| auto | pop_back () -> void |
| auto | pop_back (const size_type count) -> void |
| auto | initial () const -> GenericPointer< PropertyT, Hash > |
| auto | slice (const std::size_t index) const -> GenericPointer< PropertyT, Hash > |
| auto | slice (const std::size_t start, const std::size_t end) const -> GenericPointer< PropertyT, Hash > |
| auto | concat (const GenericPointer< PropertyT, Hash > &other) const -> GenericPointer< PropertyT, Hash > |
| auto | concat (const typename Token::Property &property) const -> GenericPointer< PropertyT, Hash > |
| auto | concat (const typename Token::Index &index) const -> GenericPointer< PropertyT, Hash > |
| auto | starts_with (const GenericPointer< PropertyT, Hash > &other) const -> bool |
| auto | starts_with (const GenericPointer< PropertyT, Hash > &other, const Token &tail) const -> bool |
| template<typename StringT> | |
| auto | starts_with (const GenericPointer< PropertyT, Hash > &other, const StringT &tail) const -> bool |
| template<typename StringLeftT, typename StringRightT> | |
| auto | starts_with (const GenericPointer< PropertyT, Hash > &other, const StringLeftT &tail_left, const StringRightT &tail_right) const -> bool |
| auto | shares_prefix (const GenericPointer< PropertyT, Hash > &other, const size_type prefix_size) const -> bool |
| auto | starts_with_strict (const GenericPointer< PropertyT, Hash > &other) const -> bool |
| auto | starts_with_initial (const GenericPointer< PropertyT, Hash > &other) const -> bool |
| auto | rebase (const GenericPointer< PropertyT, Hash > &prefix, const GenericPointer< PropertyT, Hash > &replacement) const -> GenericPointer< PropertyT, Hash > |
| auto | resolve_from (const GenericPointer< PropertyT, Hash > &base) const -> GenericPointer< PropertyT, Hash > |
| auto | to_json () const -> Value |
| Serialise a JSON Pointer as a JSON array of tokens. | |
Static Public Member Functions | |
| static auto | from_json (const Value &value) -> std::optional< GenericPointer< PropertyT, Hash > > |
| Deserialise a JSON Pointer from a JSON array of tokens. | |
|
inlinenoexcept |
This constructor creates an empty JSON Pointer. For example:
|
inline |
This constructor is the preferred way of creating a pointer. For example:
|
inlinenodiscard |
|
inlinenodiscard |
|
inlinenodiscard |
Concatenate a JSON Pointer with another JSON Pointer, getting a new pointer as a result. For example:
|
inlinenodiscard |
|
inlinenodiscard |
|
inline |
Emplace a token into the back of a JSON Pointer. For example:
|
inlinenodiscardnoexcept |
Check if a JSON Pointer is the empty pointer. For example:
|
inlinenodiscard |
Get a copy of the JSON Pointer including every token except the last. This method is undefined if the JSON Pointer is empty. For example:
|
inline |
|
inline |
|
inline |
Push a JSON Pointer into the back of a JSON WeakPointer. Make sure that the pointer you are pushing remains alive for the duration of the WeakPointer. For example:
|
inline |
Push a copy of a JSON Pointer into the back of a JSON Pointer. For example:
|
inline |
Push an index token into the back of a JSON Pointer. For example:
|
inline |
Push a property token into the back of a JSON Pointer. For example:
|
inline |
Move a JSON Pointer into the back of a JSON Pointer. For example:
|
inline |
Move a property token into the back of a JSON Pointer. For example:
|
inlinenodiscard |
Replace a base of a JSON Pointer with another JSON Pointer. For example:
|
inline |
|
inlinenodiscard |
Resolve a JSON Pointer relative to another JSON Pointer. For example:
If the JSON Pointer is not relative to the base, a copy of the original input pointer is returned.
|
inlinenodiscard |
Check whether two JSON Pointers are equal up to a given number of leading tokens. For example:
|
inlinenodiscardnoexcept |
|
inlinenodiscard |
Get a copy of the JSON Pointer starting from a given token index. This method is undefined if the index is greater than the pointer size. For example:
|
inlinenodiscard |
Get a copy of the JSON Pointer starting from a given token index up to (but not including) a given end index. This method is undefined if the start index is greater than the end index or if the end index is greater than the pointer size. For example:
|
inlinenodiscard |
Check whether a JSON Pointer starts with another JSON Pointer. For example:
|
inlinenodiscard |
|
inlinenodiscard |
Check whether a JSON Pointer starts with another JSON Pointer followed by a property token. This is useful for checking container membership without allocating a new pointer. For example:
|
inlinenodiscard |
Check whether a JSON Pointer plus a given tail starts with another JSON Pointer. For example:
|
inlinenodiscard |
Check whether a JSON Pointer starts with the initial part of another JSON Pointer. For example:
|
inlinenodiscard |
Check whether a JSON Pointer starts with another JSON Pointer without the two being equal. For example:
| class sourcemeta::core::PointerPositionTracker |
A convenient parsing callback to obtain JSON document line/column information using JSON Pointer. For example:
The tracker keeps references to the property names of the document it was populated from, so that document must outlive every query against the tracker. Reading the tracker after the source document has been destroyed is undefined behavior.
Public Types | |
| using | Pointer = GenericPointer<JSON::String, PropertyHashJSON<JSON::String>> |
| The pointer type used to look up positions. | |
| using | Position |
| The start and end line and column numbers of a value. | |
Public Member Functions | |
| auto | get (const Pointer &pointer) const -> std::optional< Position > |
| Get the position of the value at a given pointer. | |
| auto | size () const -> std::size_t |
| Get the number of tracked positions. | |
| auto | to_json () const -> JSON |
| Serialise the tracked positions as a JSON document. | |
The start and end line and column numbers of a value.
| class sourcemeta::core::GenericToken |
A single reference token of a JSON Pointer, holding either an object property or an array index.
Public Types | |
| using | Value = JSON |
| The JSON value type these tokens convert to. | |
| using | Property = PropertyT |
| The stored type of an object property token. | |
| using | Index = typename Value::Array::size_type |
| The stored type of an array index token. | |
Public Member Functions | |
| GenericToken (Property value, const typename Hash::hash_type property_hash) | |
| GenericToken (const Property &value) | |
| GenericToken (Property &&value) | |
| GenericToken (const JSON::Char *const value) | |
| GenericToken (const JSON::Char value) | |
| GenericToken (const Index value) | |
| GenericToken (const int value) | |
| auto | is_property () const noexcept -> bool |
| auto | is_hyphen () const noexcept -> bool |
| auto | is_index () const noexcept -> bool |
| auto | to_property () const noexcept -> const auto & |
| auto | property_hash () const noexcept -> typename Hash::hash_type |
| auto | property_equals (const JSON::StringView value, const typename Hash::hash_type value_hash) const noexcept -> bool |
| auto | to_property () noexcept -> auto & |
| auto | to_index () const noexcept -> Index |
| auto | to_json () const -> JSON |
|
inline |
|
inline |
|
inline |
This constructor creates an JSON Pointer token by taking ownership of a string. For example:
|
inline |
|
inline |
|
inline |
This constructor creates an JSON Pointer token from an item index. For example:
|
inline |
This constructor creates an JSON Pointer token from an item index. For example:
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
Check if a JSON Pointer token represents an array index. For example:
|
inlinenodiscardnoexcept |
Check if a JSON Pointer token represents an object property. For example:
|
inlinenodiscardnoexcept |
Check whether a JSON Pointer property token equals the given string, comparing the precomputed hashes first and only falling back to a string comparison when the hash is not perfect. For example:
|
inlinenodiscardnoexcept |
If the JSON Pointer token is a property, get its pre-computed string hash. For example:
|
inlinenodiscardnoexcept |
Get the underlying value of a JSON Pointer array index token For example:
|
inlinenodiscard |
Convert a JSON Pointer token into a JSON document, whether it represents a property or an index. For example:
|
inlinenodiscardnoexcept |
Get the underlying value of a JSON Pointer object property token (const overload). For example:
|
inlinenoexcept |
Get the underlying value of a JSON Pointer object property token (non-const overload). For example:
| class sourcemeta::core::GenericPointerWalker |
A walker to get every JSON Pointer in a JSON document. Note that no specific ordering is guaranteed. If you expect any ordering, sort afterwards.
Public Member Functions | |
| GenericPointerWalker (const JSON &document) | |
| Construct a walker over every location in a JSON document. | |
Walk over every element of a JSON document, top-down, using weak pointers. Note that the resulting weak pointers hold references to strings in the JSON document, so the document must outlive the walker and any pointers obtained from it. For example:
A JSON Pointer whose object property tokens reference externally owned strings.
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::fragment_to_pointer | ( | const URI & | uri | ) | -> std::optional< Pointer > |
Parse the URI fragment representation of a JSON Pointer, percent-decoding the fragment data before interpretation as mandated by RFC 3986, Section 2.4 and RFC 6901, Section 6. The result is not set if the URI has no fragment or if its fragment is not a valid JSON Pointer. For example:
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::get | ( | const JSON & | document, |
| const Pointer & | pointer ) -> const JSON & |
Get a value from a JSON document using a JSON Pointer (const overload).
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::get | ( | const JSON & | document, |
| const Pointer::Token & | token ) -> const JSON & |
Get a value from a JSON document using a JSON Pointer token (const overload).
Get a value from a JSON document using a JSON WeakPointer token (const overload).
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::get | ( | const JSON & | document, |
| const WeakPointer & | pointer ) -> const JSON & |
Get a value from a JSON document using a JSON WeakPointer (const overload).
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::get | ( | JSON & | document, |
| const Pointer & | pointer ) -> JSON & |
Get a value from a JSON document using a JSON Pointer (non-const overload).
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::get | ( | JSON & | document, |
| const Pointer::Token & | token ) -> JSON & |
Get a value from a JSON document using a JSON Pointer token (non-const overload).
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::get | ( | JSON & | document, |
| const WeakPointer & | pointer ) -> JSON & |
Get a value from a JSON document using a JSON WeakPointer (non-const overload). For example:
|
noexcept |
Check if the given string is a valid JSON Pointer per RFC 6901 without constructing a JSON Pointer object. For example:
|
noexcept |
Check if the given string is a valid Relative JSON Pointer per draft-handrews-relative-json-pointer-01 without constructing a pointer object. The grammar is a non-negative integer prefix (no leading zeros, no sign) followed by either a "#" or an RFC 6901 JSON Pointer suffix. For example:
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::remove | ( | JSON & | document, |
| const Pointer & | pointer ) -> bool |
Remove a value from a JSON document using a JSON Pointer. Returns true if a value is removed, false otherwise.
Removing an empty pointer Pointer{}, i.e. the root, is a noop.
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::remove | ( | JSON & | document, |
| const WeakPointer & | pointer ) -> bool |
Remove a value from a JSON document using a JSON WeakPointer. Returns true if a value is removed, false otherwise.
Removing an empty pointer WeakPointer{}, i.e. the root, is a noop.
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::set | ( | JSON & | document, |
| const Pointer & | pointer, | ||
| const JSON & | value ) -> void |
Set a value in a JSON document using a JSON Pointer (const overload).
If the last token of the JSON Pointer is the constant - and the tail instance is an array, then the operation is equivalent to sourcemeta::core::JSON::push_back.
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::set | ( | JSON & | document, |
| const Pointer & | pointer, | ||
| JSON && | value ) -> void |
Set a value in a JSON document using a JSON Pointer (non-const overload).
If the last token of the JSON Pointer is the constant - and the tail instance is an array, then the operation is equivalent to sourcemeta::core::JSON::push_back.
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::stringify | ( | const Pointer & | pointer, |
| std::basic_ostream< JSON::Char, JSON::CharTraits > & | stream ) -> void |
Stringify the input JSON Pointer into a given C++ standard output stream. For example:
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::stringify | ( | const WeakPointer & | pointer, |
| std::basic_ostream< JSON::Char, JSON::CharTraits > & | stream ) -> void |
Stringify the input JSON WeakPointer into a given C++ standard output stream. For example:
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::to_pointer | ( | const JSON & | document | ) | -> Pointer |
Create a JSON Pointer from a JSON string value. For example:
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::to_pointer | ( | const std::basic_string_view< JSON::Char, JSON::CharTraits > | input | ) | -> Pointer |
Create a JSON Pointer from a standard C++ string. For example:
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::to_pointer | ( | const WeakPointer & | pointer | ) | -> Pointer |
Convert a JSON WeakPointer into a JSON Pointer. For example:
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::to_string | ( | const Pointer & | pointer | ) | -> std::basic_string< JSON::Char, JSON::CharTraits, std::allocator< JSON::Char > > |
Stringify the input JSON Pointer into a C++ standard string. For example:
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::to_string | ( | const WeakPointer & | pointer | ) | -> std::basic_string< JSON::Char, JSON::CharTraits, std::allocator< JSON::Char > > |
Stringify the input JSON WeakPointer into a C++ standard string. For example:
Stringify the input JSON Pointer into a properly escaped URI fragment. For example:
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::to_uri | ( | const Pointer & | pointer, |
| const URI & | base ) -> URI |
Stringify the input JSON Pointer into a properly escaped URI fragment alongside a base URI. For example:
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::to_uri | ( | const WeakPointer & | pointer | ) | -> URI |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::to_uri | ( | const WeakPointer & | pointer, |
| const std::string_view | base ) -> URI |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::to_uri | ( | const WeakPointer & | pointer, |
| const URI & | base ) -> URI |
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::to_weak_pointer | ( | const Pointer & | pointer | ) | -> WeakPointer |
Convert a JSON Pointer into a JSON WeakPointer. For example:
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::try_get | ( | const JSON & | document, |
| const Pointer & | pointer ) -> const JSON * |
Get a value from a JSON document using a Pointer, returning an optional that is not set if the path does not exist in the document. For example:
| SOURCEMETA_CORE_JSONPOINTER_EXPORT auto sourcemeta::core::try_get | ( | const JSON & | document, |
| const WeakPointer & | pointer ) -> const JSON * |
Get a value from a JSON document using a WeakPointer, returning an optional that is not set if the path does not exist in the document. For example:
| const WeakPointer sourcemeta::core::empty_weak_pointer |
A global constant instance of the empty JSON WeakPointer.