Bladeren bron

refactor: renaming in FormatValidator

Sam Jaffe 2 weken geleden
bovenliggende
commit
1f274c425d
1 gewijzigde bestanden met toevoegingen van 10 en 6 verwijderingen
  1. 10 6
      include/jvalidate/format.h

+ 10 - 6
include/jvalidate/format.h

@@ -679,9 +679,12 @@ public:
   enum class Status { Unknown, Unimplemented, Valid, Invalid };
 
 private:
-  std::unordered_map<std::string, Predicate> user_formats_{{"regex", nullptr}};
+  // This isn't actually a user format, but we don't generate any special
+  // annotations for user-defined format codes, so it doesn't really matter that
+  // we're putting it here. It simply reduces the number of LoC when setting up.
+  std::unordered_map<std::string, Predicate> formats_{{"regex", nullptr}};
 
-  std::unordered_map<std::string, Predicate> supported_formats_{
+  std::unordered_map<std::string, Predicate> builtin_formats_{
       {"date", &format::date},
       {"date-time", &format::date_time},
       {"duration", &format::duration},
@@ -695,6 +698,7 @@ private:
       {"iri-reference", UTF32(uri_reference)},
       {"json-pointer", CONSTRUCTS(Pointer)},
       {"relative-json-pointer", CONSTRUCTS(RelativePointer)},
+      {"regex", nullptr},
       {"time", &format::time},
       {"uri", &format::uri},
       {"uri-reference", &format::uri_reference},
@@ -702,7 +706,7 @@ private:
       {"uuid", &format::uuid},
   };
 
-  std::unordered_map<std::string, Predicate> draft03_supported_formats_{
+  std::unordered_map<std::string, Predicate> draft03_formats_{
       {"date", &format::date},
       // One of the weird things about draft03 - date-time allows for timezone
       // and fraction-of-second in the argument, but time only allows hh:mm:ss.
@@ -721,16 +725,16 @@ private:
 
 public:
   FormatValidator() = default;
-  FormatValidator(Predicate is_regex) { user_formats_.insert_or_assign("regex", is_regex); }
+  FormatValidator(Predicate is_regex) { formats_.insert_or_assign("regex", is_regex); }
 
   Status operator()(std::string const & format, schema::Version for_version,
                     std::string_view text) const {
     auto const & supported =
-        for_version == schema::Version::Draft03 ? draft03_supported_formats_ : supported_formats_;
+        for_version == schema::Version::Draft03 ? draft03_formats_ : builtin_formats_;
     if (Status rval = (*this)(supported, format, text); rval != Status::Unknown) {
       return rval;
     }
-    return (*this)(user_formats_, format, text);
+    return (*this)(formats_, format, text);
   }
 
 private: