Fix expected alphanumeric comparison logic in string.

This commit is contained in:
Relintai 2022-02-04 16:13:54 +01:00
parent 3a5487b2ab
commit c827f6fe64

View File

@ -325,12 +325,9 @@ void String::replace(const String &find_str, const String &with, const int count
} }
int String::compare(const String &other) const { int String::compare(const String &other) const {
if (size() < other.size()) { int cmp_size = MIN(size(), other.size());
return 1;
} else if (size() > other.size()) { for (int i = 0; i < cmp_size; ++i) {
return 2;
} else {
for (int i = 0; i < _size; ++i) {
if (_data[i] < other._data[i]) { if (_data[i] < other._data[i]) {
return 1; return 1;
} else if (_data[i] > other._data[i]) { } else if (_data[i] > other._data[i]) {
@ -338,6 +335,11 @@ int String::compare(const String &other) const {
} }
} }
if (size() < other.size()) {
return 1;
} else if (size() > other.size()) {
return 2;
} else {
return 0; return 0;
} }
} }