|
@@ -4,6 +4,7 @@
|
|
|
#include <string>
|
|
#include <string>
|
|
|
#include <string_view>
|
|
#include <string_view>
|
|
|
|
|
|
|
|
|
|
+#include <jvalidate/compat/expected.h>
|
|
|
#include <jvalidate/detail/expect.h>
|
|
#include <jvalidate/detail/expect.h>
|
|
|
#include <jvalidate/detail/pointer.h>
|
|
#include <jvalidate/detail/pointer.h>
|
|
|
#include <jvalidate/forward.h>
|
|
#include <jvalidate/forward.h>
|
|
@@ -11,20 +12,30 @@
|
|
|
namespace jvalidate::detail {
|
|
namespace jvalidate::detail {
|
|
|
class RelativePointer {
|
|
class RelativePointer {
|
|
|
public:
|
|
public:
|
|
|
- RelativePointer(std::string_view path) {
|
|
|
|
|
|
|
+ static expected<RelativePointer, std::string> parse(std::string_view path) {
|
|
|
if (path == "0") {
|
|
if (path == "0") {
|
|
|
- return;
|
|
|
|
|
|
|
+ return RelativePointer();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ RelativePointer rval;
|
|
|
if (auto pos = path.find('/'); pos != path.npos) {
|
|
if (auto pos = path.find('/'); pos != path.npos) {
|
|
|
- pointer_ = Pointer(path.substr(pos));
|
|
|
|
|
|
|
+ expected ptr = Pointer::parse(path.substr(pos));
|
|
|
|
|
+ JVALIDATE_PROPIGATE_UNEXPECTED(ptr);
|
|
|
|
|
+ rval.pointer_ = *std::move(ptr);
|
|
|
path.remove_suffix(path.size() - pos);
|
|
path.remove_suffix(path.size() - pos);
|
|
|
- } else {
|
|
|
|
|
- EXPECT_M(not path.empty() && path.back() == '#',
|
|
|
|
|
- "RelativePointer must end in a pointer, or a '#'");
|
|
|
|
|
- requests_key_ = true;
|
|
|
|
|
|
|
+ } else if (path.back() == '#') {
|
|
|
|
|
+ rval.requests_key_ = true;
|
|
|
path.remove_suffix(1);
|
|
path.remove_suffix(1);
|
|
|
}
|
|
}
|
|
|
- parent_steps_ = std::stoull(std::string(path));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (path.find_first_not_of("0123456789") != std::string_view::npos) {
|
|
|
|
|
+ return unexpected("RelativePointer must end in a pointer, or a '#'");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ expected parent_steps = Pointer::parse_integer<size_t>(path);
|
|
|
|
|
+ JVALIDATE_PROPIGATE_UNEXPECTED(parent_steps);
|
|
|
|
|
+ rval.parent_steps_ = *parent_steps;
|
|
|
|
|
+ return rval;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template <Adapter A>
|
|
template <Adapter A>
|