diff --git a/include/tcframe/validator/core.hpp b/include/tcframe/validator/core.hpp index 3770ccc..6189960 100644 --- a/include/tcframe/validator/core.hpp +++ b/include/tcframe/validator/core.hpp @@ -1,9 +1,13 @@ +#pragma once +#include #include +#include using std::enable_if_t; using std::is_arithmetic_v; using std::size_t; +using std::string; using std::vector; namespace tcframe { @@ -52,11 +56,6 @@ VectorElementValidator eachElementOf(const vector& val) { return VectorElementValidator(val); } -template> -VectorElementValidator eachElementOf(vector&& val) { - return VectorElementValidator(val); -} - template> struct VectorElementsValidator { private: @@ -114,4 +113,25 @@ VectorElementsValidator elementsOf(const vector& val) { return VectorElementsValidator(val); } +struct StringElementValidator { +private: + const string& val; + +public: + explicit StringElementValidator(const string& _val) : val(_val) {} + + bool isBetween(char minVal, char maxVal) { + for (char v : val) { + if (!valueOf(v).isBetween(minVal, maxVal)) { + return false; + } + } + return true; + } +}; + +StringElementValidator eachCharacterOf(const string& val) { + return StringElementValidator(val); +} + } diff --git a/test/unit/tcframe/validator/CoreValidatorTests.cpp b/test/unit/tcframe/validator/CoreValidatorTests.cpp index 03034fa..c3cf87f 100644 --- a/test/unit/tcframe/validator/CoreValidatorTests.cpp +++ b/test/unit/tcframe/validator/CoreValidatorTests.cpp @@ -66,4 +66,11 @@ TEST_F(CoreValidatorTests, elementsOf_areUnique) { EXPECT_TRUE(elementsOf(vector{'a', 'x', 'd', 'g', 'h'}).areUnique()); } +TEST_F(CoreValidatorTests, eachCharacterOf_isBetween) { + EXPECT_FALSE(eachCharacterOf("BCDEF").isBetween('B', 'E')); + EXPECT_FALSE(eachCharacterOf("BCDEF").isBetween('C', 'F')); + EXPECT_TRUE(eachCharacterOf("BCDEF").isBetween('B', 'F')); + EXPECT_TRUE(eachCharacterOf("BCDEF").isBetween('A', 'G')); +} + }