diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2013-09-23 21:16:57 +0200 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2013-09-23 21:17:16 +0200 |
| commit | bab10f5b93abaf9f75a538f291576d4789c30926 (patch) | |
| tree | 25ec817a5c0e41539a70297826ea50cca30fc254 /src/string.cc | |
| parent | 5ae43acf945c6574cebccb6c5d1b3b5427deed70 (diff) | |
add subsequence_match(str, subseq) utility function
Diffstat (limited to 'src/string.cc')
| -rw-r--r-- | src/string.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/string.cc b/src/string.cc index 870cdf9e..23457413 100644 --- a/src/string.cc +++ b/src/string.cc @@ -94,4 +94,21 @@ bool prefix_match(const String& str, const String& prefix) return true; } +bool subsequence_match(const String& str, const String& subseq) +{ + auto it = str.begin(); + for (auto& c : subseq) + { + if (it == str.end()) + return false; + while (*it != c) + { + if (++it == str.end()) + return false; + } + ++it; + } + return true; +} + } |
