From 937da63ba6792df3300d5e982078fee771e12370 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 7 Dec 2020 12:06:41 +0100 Subject: [PATCH] util/StringView: add {Starts,Ends}With(char) --- src/util/StringView.hxx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/util/StringView.hxx b/src/util/StringView.hxx index a56cd361e..5d782839f 100644 --- a/src/util/StringView.hxx +++ b/src/util/StringView.hxx @@ -154,6 +154,16 @@ struct BasicStringView : ConstBuffer { 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 other) const noexcept { if (size < other.size) {