34#ifndef HPP_UTIL_STRING_HH
35#define HPP_UTIL_STRING_HH
46template <
typename InputIt,
typename Predicate>
47bool string_split(InputIt first, InputIt last,
const char& c, Predicate p) {
49 InputIt next = std::find(first, last, c);
50 if (p(first, next))
return true;
51 if (next == last)
return false;
52 first = std::next(next);
56template <
typename InputIt,
typename Predicate>
57bool string_split(InputIt first, InputIt last,
const char* c, Predicate p) {
58 auto n = std::strlen(c);
60 InputIt next = std::find_if(first, last, [&c, &n](
char l) ->
bool {
61 return c + n != std::find(c, c + n, l);
63 if (p(first, next))
return true;
64 if (next == last)
return false;
65 first = std::next(next);
69template <
typename InputIt>
72 std::vector<std::string> strings;
73 string_split(first, last, c, [&strings](InputIt begin, InputIt end) {
74 strings.emplace_back(&(*begin), std::distance(begin, end));
80template <
typename InputIt>
83 std::vector<std::string> strings;
84 string_split(first, last, c, [&strings](InputIt begin, InputIt end) {
85 strings.emplace_back(&(*begin), std::distance(begin, end));
91inline bool iequal(
const std::string& a,
const std::string& b) {
92 return (a.size() == b.size()) &&
93 std::equal(a.begin(), a.end(), b.begin(), [](
char a,
char b) ->
bool {
94 return std::tolower(a) == std::tolower(b);
bool iequal(const std::string &a, const std::string &b)
Definition: string.hh:91
bool string_split(InputIt first, InputIt last, const char &c, Predicate p)
Definition: string.hh:47
Definition: assertion.hh:45