|
|
@@ -41,32 +41,13 @@ public:
|
|
|
Pointer(std::vector<Token> const & tokens) : tokens_(tokens) {}
|
|
|
|
|
|
/**
|
|
|
- * @brief Parse a JSON-Pointer from a serialized JSON-Pointer-String. In
|
|
|
- * principle, this should either be a factory function returning an optional/
|
|
|
- * throwing on error - but we'll generously assume that all JSON-Pointers are
|
|
|
- * valid - and therefore that an invalidly formatter pointer string will
|
|
|
- * point to somewhere non-existant (since it will be used in schema handling)
|
|
|
+ * @brief Parse a JSON-Pointer from a serialized JSON-Pointer-String.
|
|
|
+ *
|
|
|
+ * @param path A string representation of the Pointer
|
|
|
+ *
|
|
|
+ * @returns A Pointer, if the string is considered valid, else an error
|
|
|
+ * message describing the problem.
|
|
|
*/
|
|
|
- Pointer(std::string_view path) {
|
|
|
- if (path.empty()) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // JSON-Pointers are required to start with a '/' although we only enforce
|
|
|
- // that rule in Reference.
|
|
|
- path.remove_prefix(1);
|
|
|
- // The rules of JSON-Pointer is that if a token were to contain a '/' as a
|
|
|
- // strict character: then that character would be escaped, using the above
|
|
|
- // rules. We take advantage of string_view's sliding view to make iteration
|
|
|
- // easy.
|
|
|
- for (size_t p = path.find('/'); p != std::string::npos;
|
|
|
- path.remove_prefix(p + 1), p = path.find('/')) {
|
|
|
- tokens_.push_back(parse_token(std::string(path.substr(0, p))).value());
|
|
|
- }
|
|
|
-
|
|
|
- tokens_.push_back(parse_token(std::string(path)).value());
|
|
|
- }
|
|
|
-
|
|
|
static expected<Pointer, std::string> parse(std::string_view path) {
|
|
|
if (path.empty()) {
|
|
|
return Pointer();
|