util/StringView: add method substr()

This commit is contained in:
Max Kellermann 2020-02-03 20:45:58 +01:00 committed by Max Kellermann
parent d4135935e4
commit a63d0ee8fc
1 changed files with 13 additions and 0 deletions

View File

@ -88,6 +88,19 @@ struct BasicStringView : ConstBuffer<T> {
using ConstBuffer<T>::pop_back; using ConstBuffer<T>::pop_back;
using ConstBuffer<T>::skip_front; using ConstBuffer<T>::skip_front;
constexpr BasicStringView<T> substr(size_type pos,
size_type count) const noexcept {
return {data + pos, count};
}
constexpr BasicStringView<T> substr(size_type pos) const noexcept {
return {data + pos, size - pos};
}
constexpr BasicStringView<T> substr(const char *start) const noexcept {
return {start, size_t(data + size - start)};
}
gcc_pure gcc_pure
pointer Find(value_type ch) const noexcept { pointer Find(value_type ch) const noexcept {
return StringFind(data, ch, this->size); return StringFind(data, ch, this->size);