util/StringView: add {Starts,Ends}With(char)

This commit is contained in:
Max Kellermann 2020-12-07 12:06:41 +01:00 committed by Max Kellermann
parent 1f312b2e42
commit 937da63ba6

View File

@ -154,6 +154,16 @@ struct BasicStringView : ConstBuffer<T> {
needle.data, needle.size);
}
gcc_pure
bool StartsWith(value_type ch) const noexcept {
return !empty() && front() == ch;
}
gcc_pure
bool EndsWith(value_type ch) const noexcept {
return !empty() && back() == ch;
}
gcc_pure
int Compare(BasicStringView<T> other) const noexcept {
if (size < other.size) {