Commit b9a8b0d1 authored by Max Kellermann's avatar Max Kellermann

util/StringView: add method Literal()

parent 4d15db01
...@@ -54,6 +54,16 @@ struct StringView : ConstBuffer<char> { ...@@ -54,6 +54,16 @@ struct StringView : ConstBuffer<char> {
return StringView("", size_t(0)); 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() { void SetEmpty() {
data = ""; data = "";
size = 0; size = 0;
...@@ -90,7 +100,7 @@ struct StringView : ConstBuffer<char> { ...@@ -90,7 +100,7 @@ struct StringView : ConstBuffer<char> {
template<size_t n> template<size_t n>
bool EqualsLiteral(const char (&other)[n]) const { bool EqualsLiteral(const char (&other)[n]) const {
return Equals({other, n - 1}); return Equals(Literal(other));
} }
gcc_pure gcc_pure
...@@ -101,7 +111,7 @@ struct StringView : ConstBuffer<char> { ...@@ -101,7 +111,7 @@ struct StringView : ConstBuffer<char> {
template<size_t n> template<size_t n>
bool EqualsLiteralIgnoreCase(const char (&other)[n]) const { bool EqualsLiteralIgnoreCase(const char (&other)[n]) const {
return EqualsIgnoreCase({other, n - 1}); return EqualsIgnoreCase(Literal(other));
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment