string_constraint.h 825 B

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