string_constraint.h 1.4 KB

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