add subsequence_match(str, subseq) utility function
This commit is contained in:
parent
5ae43acf94
commit
bab10f5b93
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -113,6 +113,7 @@ String to_string(const StronglyTypedNumber<RealType, ValueType>& val)
|
|||
}
|
||||
|
||||
bool prefix_match(const String& str, const String& prefix);
|
||||
bool subsequence_match(const String& str, const String& subseq);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -141,6 +141,11 @@ void test_string()
|
|||
kak_assert(prefix_match("tchou kanaky", "tchou kanaky"));
|
||||
kak_assert(prefix_match("tchou kanaky", "t"));
|
||||
kak_assert(not prefix_match("tchou kanaky", "c"));
|
||||
|
||||
kak_assert(subsequence_match("tchou kanaky", "tknky"));
|
||||
kak_assert(subsequence_match("tchou kanaky", "knk"));
|
||||
kak_assert(subsequence_match("tchou kanaky", "tchou kanaky"));
|
||||
kak_assert(not subsequence_match("tchou kanaky", "tchou kanaky"));
|
||||
}
|
||||
|
||||
void test_keys()
|
||||
|
|
Loading…
Reference in New Issue
Block a user