Kaynağa Gözat

refactor: cleanup

Sam Jaffe 3 ay önce
ebeveyn
işleme
2720f2f9f2

+ 3 - 4
include/jvalidate/detail/pointer.h

@@ -3,14 +3,14 @@
 #include <algorithm>
 #include <cassert>
 #include <iostream>
-#include <jvalidate/detail/expect.h>
-#include <jvalidate/detail/number.h>
 #include <string>
 #include <string_view>
 #include <variant>
 #include <vector>
 
 #include <jvalidate/compat/compare.h>
+#include <jvalidate/detail/expect.h>
+#include <jvalidate/detail/number.h>
 #include <jvalidate/forward.h>
 
 namespace jvalidate::detail {
@@ -43,7 +43,7 @@ public:
    * valid - and therefore that an invalidly formatter pointer string will
    * point to somewhere non-existant (since it will be used in schema handling)
    */
-  Pointer(std::string_view path, bool strict = false) {
+  Pointer(std::string_view path) {
     if (path.empty()) {
       return;
     }
@@ -88,7 +88,6 @@ public:
 
     // JSON-Pointers are required to start with a '/' although we only enforce
     // that rule in Reference.
-    EXPECT_M(not strict || path.starts_with('/'), "JSON Pointer must start with '/'");
     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

+ 4 - 1
include/jvalidate/format.h

@@ -276,8 +276,11 @@ template <typename T> inline bool ctor_as_valid(std::string_view str) {
 }
 
 inline bool json_pointer(std::string_view ptr) {
+  if (not ptr.empty() && not ptr.starts_with('/')) {
+    return false;
+  }
   try {
-    [[maybe_unused]] ::jvalidate::detail::Pointer _{ptr, true};
+    [[maybe_unused]] ::jvalidate::detail::Pointer _{ptr};
     return true;
   } catch (std::exception const & ex) { return false; }
 }