string_constraint.h 880 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include <string>
  3. #include <jvalidate/constraint/constraint.h>
  4. #include <jvalidate/detail/string.h>
  5. #include <jvalidate/forward.h>
  6. namespace jvalidate::constraint {
  7. class MinLengthConstraint : public SimpleConstraint<MinLengthConstraint> {
  8. private:
  9. int64_t value_;
  10. public:
  11. MinLengthConstraint(int64_t value) : value_(value) {}
  12. bool operator()(std::string_view arg) const { return detail::length(arg) >= value_; }
  13. };
  14. class MaxLengthConstraint : public SimpleConstraint<MaxLengthConstraint> {
  15. private:
  16. int64_t value_;
  17. public:
  18. MaxLengthConstraint(int64_t value) : value_(value) {}
  19. bool operator()(std::string_view arg) const { return detail::length(arg) <= value_; }
  20. };
  21. class PatternConstraint : public SimpleConstraint<PatternConstraint> {
  22. public:
  23. std::string regex;
  24. public:
  25. PatternConstraint(std::string const & regex) : regex(regex) {}
  26. };
  27. }