22 #ifndef GEARS_STRING_PREDICATE_HPP
23 #define GEARS_STRING_PREDICATE_HPP
37 template<
typename CharT =
char>
43 bool operator()(CharT s)
const {
70 template<
typename String>
71 inline bool iequal(
const String& lhs,
const String& rhs,
const std::locale& loc = std::locale()) {
72 if(lhs.length() != rhs.length())
74 auto i = lhs.cbegin();
75 auto j = rhs.cbegin();
76 for(; i != lhs.cend() && j != rhs.cend(); ++i, ++j) {
77 if(std::toupper(*i, loc) != std::toupper(*j, loc))
98 template<
typename String>
99 inline bool starts_with(
const String& str,
const String& other) {
100 return str.find(other) == 0;
120 template<
typename String>
121 inline bool istarts_with(
const String& str,
const String& other,
const std::locale& loc = std::locale()) {
122 if(other.length() > str.length())
124 for(
unsigned i = 0; i < other.length(); ++i) {
125 if(std::toupper(str[i], loc) != std::toupper(other[i], loc))
146 template<
typename String>
147 inline bool ends_with(
const String& str,
const String& other) {
148 if(str.length() >= other.length())
149 return str.compare(str.length() - other.length(), other.length(), other) == 0;
171 template<
typename String>
172 inline bool iends_with(
const String& str,
const String& other,
const std::locale& loc = std::locale()) {
173 if(str.length() >= other.length()) {
174 for(
unsigned start = str.length() - other.length(), i = 0; i < other.length(); ++i, ++start) {
175 if(std::toupper(str[start], loc) != std::toupper(other[i], loc))
195 template<
typename String>
196 inline bool contains(
const String& str,
const String& other) {
197 return str.find(other) != String::npos;
212 template<
typename String>
213 inline bool icontains(
const String& str,
const String& other,
const std::locale& loc = std::locale()) {
214 auto first = str.cbegin();
215 auto last = str.cend();
216 auto other_last = other.cend();
219 for(
auto i = other.cbegin(); ; ++i, ++it) {
224 if(std::toupper(*it, loc) != std::toupper(*i, loc))
239 template<
typename String,
typename UnaryPredicate>
240 inline bool all(
const String& str, UnaryPredicate&& pred) {
241 for(
auto&& c : str) {
250 #endif // GEARS_STRING_PREDICATE_HPP