aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-11-06 09:31:49 +0100
committerMax Kellermann <max@duempel.org>2015-11-06 10:03:45 +0100
commitb9a8b0d146447b198d46767695160f53bef473e4 (patch)
treed6bf7835953ab956719f03c55a4ccfb4c32a8cbc
parent4d15db01346a4c1e7b2c25b9c36f40a27783851e (diff)
downloadmpd-b9a8b0d146447b198d46767695160f53bef473e4.tar.gz
mpd-b9a8b0d146447b198d46767695160f53bef473e4.tar.xz
mpd-b9a8b0d146447b198d46767695160f53bef473e4.zip
util/StringView: add method Literal()
-rw-r--r--src/util/StringView.hxx14
1 files changed, 12 insertions, 2 deletions
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<char> {
return StringView("", size_t(0));
}
+ template<size_t n>
+ 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<char> {
template<size_t n>
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<char> {
template<size_t n>
bool EqualsLiteralIgnoreCase(const char (&other)[n]) const {
- return EqualsIgnoreCase({other, n - 1});
+ return EqualsIgnoreCase(Literal(other));
}
/**