From a63d0ee8fcf3028fb4a3b1b4148d31c6f06dbecc Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 3 Feb 2020 20:45:58 +0100 Subject: [PATCH] util/StringView: add method substr() --- src/util/StringView.hxx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/util/StringView.hxx b/src/util/StringView.hxx index 5be9de3ed..aea2423ec 100644 --- a/src/util/StringView.hxx +++ b/src/util/StringView.hxx @@ -88,6 +88,19 @@ struct BasicStringView : ConstBuffer { using ConstBuffer::pop_back; using ConstBuffer::skip_front; + constexpr BasicStringView substr(size_type pos, + size_type count) const noexcept { + return {data + pos, count}; + } + + constexpr BasicStringView substr(size_type pos) const noexcept { + return {data + pos, size - pos}; + } + + constexpr BasicStringView substr(const char *start) const noexcept { + return {start, size_t(data + size - start)}; + } + gcc_pure pointer Find(value_type ch) const noexcept { return StringFind(data, ch, this->size);