util/StringView: add method Compare()
This commit is contained in:
parent
bb7f7bd3e5
commit
79d1004544
|
@ -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 &&
|
||||
|
|
Loading…
Reference in New Issue