COMMON: Add comparison operators to U32String

Those operators just compare the numerical value of each character
one by one. This is not idea, but this is better than nothing.
This commit is contained in:
Thierry Crozat 2020-08-30 21:58:13 +01:00 committed by Eugene Sandulenko
parent dd9256502a
commit 9fcc83c09d
2 changed files with 33 additions and 0 deletions

View File

@ -198,6 +198,34 @@ bool U32String::operator!=(const char *x) const {
return !equals(x);
}
bool U32String::operator<(const String &x) const {
for (int i = 0 ; i < _size && i < x.size() ; ++i) {
if (_str[i] < x[i])
return true;
else if (_str[i] > x[i])
return false;
}
return (_size < x.size());
}
bool U32String::operator<=(const String &x) const {
return !operator>(x);
}
bool U32String::operator>(const String &x) const {
for (int i = 0 ; i < _size && i < x.size() ; ++i) {
if (_str[i] > x[i])
return true;
else if (_str[i] < x[i])
return false;
}
return (_size > x.size());
}
bool U32String::operator>=(const String &x) const {
return !operator<(x);
}
bool U32String::equals(const U32String &x) const {
if (this == &x || _str == x._str) {
return true;

View File

@ -136,6 +136,11 @@ public:
bool operator!=(const value_type *x) const;
bool operator!=(const char *x) const;
bool operator<(const String &x) const;
bool operator<=(const String &x) const;
bool operator>(const String &x) const;
bool operator>=(const String &x) const;
/**
* Compares whether two U32String are the same based on memory comparison.
* This does *not* do comparison based on canonical equivalence.