util/StringView: add SkipPrefix(), RemoveSuffix()
This commit is contained in:
@@ -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> {
|
|||||||
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> {
|
||||||
|
Reference in New Issue
Block a user