string_constraint.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include <string>
  3. #include <jvalidate/detail/string.h>
  4. #include <jvalidate/forward.h>
  5. namespace jvalidate::constraint {
  6. /**
  7. * @brief A constraint on the String type with the following characteristic(s):
  8. * @code{.cpp}
  9. * arg.size() >= value
  10. * @endcode
  11. *
  12. * https://json-schema.org/draft/2020-12/json-schema-validation#section-6.3.2
  13. */
  14. struct MinLengthConstraint {
  15. int64_t value;
  16. };
  17. /**
  18. * @brief A constraint on the String type with the following characteristic(s):
  19. * @code{.cpp}
  20. * arg.size() <= value
  21. * @endcode
  22. *
  23. * https://json-schema.org/draft/2020-12/json-schema-validation#section-6.3.1
  24. */
  25. struct MaxLengthConstraint {
  26. int64_t value;
  27. };
  28. /**
  29. * @brief A constraint on the String type with the following characteristic(s):
  30. * @code{.py}
  31. * re.match(regex, arg)
  32. * @endcode
  33. *
  34. * https://json-schema.org/draft/2020-12/json-schema-validation#section-6.3.3
  35. */
  36. struct PatternConstraint {
  37. std::string regex;
  38. };
  39. /**
  40. * @brief A constraint on the String type that describes a string format using
  41. * a human friendly name. The implementation of the regular expression, ABNF
  42. * grammer, or state-machine parser that checks the validity of the string
  43. * (for the standard list of formats respected by the JSON schema RPC) is
  44. * implemented in {@see include/jvalidate/format.h}.
  45. *
  46. * https://json-schema.org/draft/2020-12/json-schema-validation#section-7
  47. */
  48. struct FormatConstraint {
  49. std::string format;
  50. bool is_assertion;
  51. };
  52. }