util/StringView: add method Compare()

This commit is contained in:
Max Kellermann 2019-08-16 13:29:47 +02:00
parent bb7f7bd3e5
commit 79d1004544
1 changed files with 17 additions and 0 deletions

View File

@ -121,6 +121,23 @@ struct BasicStringView : ConstBuffer<T> {
needle.data, needle.size);
}
gcc_pure
int Compare(BasicStringView<T> other) const noexcept {
if (size < other.size) {
int result = StringCompare(data, other.data, size);
if (result == 0)
result = -1;
return result;
} else if (size > other.size) {
int result = StringCompare(data, other.data,
other.size);
if (result == 0)
result = 1;
return result;
} else
return StringCompare(data, other.data, size);
}
gcc_pure
bool Equals(BasicStringView<T> other) const noexcept {
return this->size == other.size &&