Commit 05aa9f72 authored by Max Kellermann's avatar Max Kellermann

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

parent 281461f0
...@@ -69,6 +69,7 @@ struct BasicStringView : ConstBuffer<T> { ...@@ -69,6 +69,7 @@ struct BasicStringView : ConstBuffer<T> {
using ConstBuffer<T>::back; using ConstBuffer<T>::back;
using ConstBuffer<T>::pop_front; using ConstBuffer<T>::pop_front;
using ConstBuffer<T>::pop_back; using ConstBuffer<T>::pop_back;
using ConstBuffer<T>::skip_front;
gcc_pure gcc_pure
pointer_type Find(value_type ch) const noexcept { pointer_type Find(value_type ch) const noexcept {
...@@ -114,6 +115,20 @@ struct BasicStringView : ConstBuffer<T> { ...@@ -114,6 +115,20 @@ struct BasicStringView : ConstBuffer<T> {
StripLeft(); StripLeft();
StripRight(); 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> { struct StringView : BasicStringView<char> {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment