Rewrite of keyword matching code. This fixes #20

Uses new iterator based tagged string functions.
This commit is contained in:
Twan van Laarhoven
2020-05-17 20:37:53 +02:00
parent 0b653938cc
commit b3ddb295fc
8 changed files with 528 additions and 267 deletions
+36
View File
@@ -220,3 +220,39 @@ String regex_escape(const String& s);
/** Basicly replaces "(" with "(?:" */
String make_non_capturing(const String& re);
// ----------------------------------------------------------------------------- : Iterator utilities
struct end_sentinel_t {} end_sentinel;
// Iterate over a string, removing all matching substrings.
// match.operator(it,end) should return false or return true and advance it past the substring
template <typename It, typename End, typename Match>
struct SkipSubstringIterator {
public:
SkipSubstringIterator(It it, End end, Match const& match) : it(it), end(end), match(match) {
while (match(it, end));
}
bool operator == (end_sentinel_t) const {
return it == end;
}
bool operator != (end_sentinel_t) const {
return it != end;
}
auto operator * () const {
return *it;
}
auto& operator ++ () {
++it;
while (match(it, end));
return *this;
}
private:
It it;
End end;
Match match;
};
template <typename It, typename End, typename Match>
inline SkipSubstringIterator<It,End,Match> skip_substring_iterator(It it, End end, Match const& match) {
return SkipSubstringIterator<It,End,Match>(it, end, match);
}