11 #ifndef HPP_UTIL_STRING_HH 12 # define HPP_UTIL_STRING_HH 24 template<
typename InputIt,
typename Predicate>
25 bool string_split(InputIt first, InputIt last,
const char& c, Predicate p)
28 InputIt next = std::find(first, last, c);
29 if (p(first, next))
return true;
30 if (next == last)
return false;
31 first = std::next(next);
35 template<
typename InputIt,
typename Predicate>
36 bool string_split(InputIt first, InputIt last,
const char* c, Predicate p)
38 auto n = std::strlen(c);
40 InputIt next = std::find_if(first, last,
41 [&c, &n](
char l)->
bool{
return c+n != std::find(c, c+n, l); });
42 if (p(first, next))
return true;
43 if (next == last)
return false;
44 first = std::next(next);
48 template<
typename InputIt>
49 std::vector<std::string>
52 std::vector<std::string> strings;
53 string_split(first, last, c, [&strings](InputIt begin, InputIt end) {
54 strings.emplace_back(&(*begin), std::distance(begin, end));
60 template<
typename InputIt>
61 std::vector<std::string>
64 std::vector<std::string> strings;
65 string_split(first, last, c, [&strings](InputIt begin, InputIt end) {
66 strings.emplace_back(&(*begin), std::distance(begin, end));
72 inline bool iequal(
const std::string& a,
const std::string& b)
74 return (a.size() == b.size()) && std::equal(a.begin(), a.end(), b.begin(),
75 [](
char a,
char b)->
bool {
return std::tolower(a) == std::tolower(b); });
Definition: assertion.hh:22
bool iequal(const std::string &a, const std::string &b)
Definition: string.hh:72
bool string_split(InputIt first, InputIt last, const char &c, Predicate p)
Definition: string.hh:25