util/StringView: add SkipPrefix(), RemoveSuffix()

This commit is contained in:
Max Kellermann 2019-02-19 11:51:32 +01:00
parent 281461f0f0
commit 05aa9f72a9

View File

@ -69,6 +69,7 @@ struct BasicStringView : ConstBuffer<T> {
using ConstBuffer<T>::back;
using ConstBuffer<T>::pop_front;
using ConstBuffer<T>::pop_back;
using ConstBuffer<T>::skip_front;
gcc_pure
pointer_type Find(value_type ch) const noexcept {
@ -114,6 +115,20 @@ struct BasicStringView : ConstBuffer<T> {
StripLeft();
StripRight();
}
bool SkipPrefix(BasicStringView<T> needle) noexcept {
bool match = StartsWith(needle);
if (match)
skip_front(needle.size);
return match;
}
bool RemoveSuffix(BasicStringView<T> needle) noexcept {
bool match = EndsWith(needle);
if (match)
size -= needle.size;
return match;
}
};
struct StringView : BasicStringView<char> {