mirror of
https://github.com/xoseperez/espurna.git
synced 2026-03-06 16:27:12 +01:00
system: fix view comparison
note that it is equality, not byte comparison based on memcmp or strcmp return values
This commit is contained in:
@@ -308,15 +308,17 @@ void setup() {
|
||||
|
||||
} // namespace
|
||||
|
||||
bool StringView::compare(StringView other) const {
|
||||
bool StringView::equals(StringView other) const {
|
||||
if (other._len == _len) {
|
||||
if (inFlash(_ptr)) {
|
||||
if (inFlash(_ptr) && inFlash(other._ptr)) {
|
||||
return _ptr == other._ptr;
|
||||
} else if (inFlash(_ptr)) {
|
||||
return memcmp_P(other._ptr, _ptr, _len) == 0;
|
||||
} else if (inFlash(other._ptr)) {
|
||||
return memcmp_P(_ptr, other._ptr, _len) == 0;
|
||||
}
|
||||
|
||||
return __builtin_memcmp(_ptr, other._ptr, _len);
|
||||
return __builtin_memcmp(_ptr, other._ptr, _len) == 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -161,7 +161,7 @@ struct StringView {
|
||||
return toString();
|
||||
}
|
||||
|
||||
bool compare(StringView other) const;
|
||||
bool equals(StringView other) const;
|
||||
|
||||
private:
|
||||
static bool inFlash(const char* ptr) {
|
||||
@@ -177,11 +177,11 @@ private:
|
||||
};
|
||||
|
||||
inline bool operator==(StringView lhs, StringView rhs) {
|
||||
return lhs.compare(rhs);
|
||||
return lhs.equals(rhs);
|
||||
}
|
||||
|
||||
inline bool operator!=(StringView lhs, StringView rhs) {
|
||||
return !lhs.compare(rhs);
|
||||
return !lhs.equals(rhs);
|
||||
}
|
||||
|
||||
inline String operator+(String&& lhs, StringView rhs) {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
namespace espurna {
|
||||
|
||||
// no special cases for flash strings
|
||||
bool StringView::compare(espurna::StringView other) const {
|
||||
bool StringView::equals(espurna::StringView other) const {
|
||||
return _ptr == other._ptr
|
||||
|| (_len == other._len && (0 == __builtin_memcmp(_ptr, other._ptr, _len)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user