From b9a8b0d146447b198d46767695160f53bef473e4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 6 Nov 2015 09:31:49 +0100 Subject: util/StringView: add method Literal() --- src/util/StringView.hxx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/util') diff --git a/src/util/StringView.hxx b/src/util/StringView.hxx index dd6c4dc77..b2456a945 100644 --- a/src/util/StringView.hxx +++ b/src/util/StringView.hxx @@ -54,6 +54,16 @@ struct StringView : ConstBuffer { return StringView("", size_t(0)); } + template + static constexpr StringView Literal(const char (&_data)[n]) { + static_assert(n > 0, ""); + return {_data, n - 1}; + } + + static constexpr StringView Literal() { + return StringView("", size_t(0)); + } + void SetEmpty() { data = ""; size = 0; @@ -90,7 +100,7 @@ struct StringView : ConstBuffer { template bool EqualsLiteral(const char (&other)[n]) const { - return Equals({other, n - 1}); + return Equals(Literal(other)); } gcc_pure @@ -101,7 +111,7 @@ struct StringView : ConstBuffer { template bool EqualsLiteralIgnoreCase(const char (&other)[n]) const { - return EqualsIgnoreCase({other, n - 1}); + return EqualsIgnoreCase(Literal(other)); } /** -- cgit v1.2.3