From e15fc91323dbe6410b7ba6e342967bd2aaa30c47 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Mon, 16 May 2022 14:09:17 +0200 Subject: [PATCH 1/7] WString: overload == --- cores/esp8266/WString.h | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/cores/esp8266/WString.h b/cores/esp8266/WString.h index 88efa0d1f7..991dcfd42d 100644 --- a/cores/esp8266/WString.h +++ b/cores/esp8266/WString.h @@ -230,6 +230,33 @@ class String { bool operator ==(const __FlashStringHelper *rhs) const { return equals(rhs); } + bool operator ==(std::nullptr_t) const { + return length() == 0; + } + bool operator ==(int num) const { + return equals(String(num)); + } + bool operator ==(unsigned int num) const { + return equals(String(num)); + } + bool operator ==(long num) const { + return equals(String(num)); + } + bool operator ==(unsigned long num) const { + return equals(String(num)); + } + bool operator ==(long long num) const { + return equals(String(num)); + } + bool operator ==(unsigned long long num) const { + return equals(String(num)); + } + bool operator ==(float num) const { + return equals(String(num)); + } + bool operator ==(double num) const { + return equals(String(num)); + } bool operator !=(const String &rhs) const { return !equals(rhs); } @@ -239,6 +266,33 @@ class String { bool operator !=(const __FlashStringHelper *rhs) const { return !equals(rhs); } + bool operator !=(std::nullptr_t) const { + return length() != 0; + } + bool operator !=(int num) const { + return !equals(String(num)); + } + bool operator !=(unsigned int num) const { + return !equals(String(num)); + } + bool operator !=(long num) const { + return !equals(String(num)); + } + bool operator !=(unsigned long num) const { + return !equals(String(num)); + } + bool operator !=(long long num) const { + return !equals(String(num)); + } + bool operator !=(unsigned long long num) const { + return !equals(String(num)); + } + bool operator !=(float num) const { + return !equals(String(num)); + } + bool operator !=(double num) const { + return !equals(String(num)); + } bool operator <(const String &rhs) const; bool operator >(const String &rhs) const; bool operator <=(const String &rhs) const; From a5cc3449cacf2ee172cc78a931ed122e58641ce2 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Mon, 16 May 2022 15:52:48 +0200 Subject: [PATCH 2/7] keep only nullptr comparison overload --- cores/esp8266/WString.h | 48 ----------------------------------------- 1 file changed, 48 deletions(-) diff --git a/cores/esp8266/WString.h b/cores/esp8266/WString.h index 991dcfd42d..e6cdc42338 100644 --- a/cores/esp8266/WString.h +++ b/cores/esp8266/WString.h @@ -233,30 +233,6 @@ class String { bool operator ==(std::nullptr_t) const { return length() == 0; } - bool operator ==(int num) const { - return equals(String(num)); - } - bool operator ==(unsigned int num) const { - return equals(String(num)); - } - bool operator ==(long num) const { - return equals(String(num)); - } - bool operator ==(unsigned long num) const { - return equals(String(num)); - } - bool operator ==(long long num) const { - return equals(String(num)); - } - bool operator ==(unsigned long long num) const { - return equals(String(num)); - } - bool operator ==(float num) const { - return equals(String(num)); - } - bool operator ==(double num) const { - return equals(String(num)); - } bool operator !=(const String &rhs) const { return !equals(rhs); } @@ -269,30 +245,6 @@ class String { bool operator !=(std::nullptr_t) const { return length() != 0; } - bool operator !=(int num) const { - return !equals(String(num)); - } - bool operator !=(unsigned int num) const { - return !equals(String(num)); - } - bool operator !=(long num) const { - return !equals(String(num)); - } - bool operator !=(unsigned long num) const { - return !equals(String(num)); - } - bool operator !=(long long num) const { - return !equals(String(num)); - } - bool operator !=(unsigned long long num) const { - return !equals(String(num)); - } - bool operator !=(float num) const { - return !equals(String(num)); - } - bool operator !=(double num) const { - return !equals(String(num)); - } bool operator <(const String &rhs) const; bool operator >(const String &rhs) const; bool operator <=(const String &rhs) const; From e4b47bce14e4b4b9457ebe006fef0331d5a68711 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Mon, 16 May 2022 16:28:26 +0200 Subject: [PATCH 3/7] removing ==(FlashStringHelper) overload: Comparison with `P("test")` will use an implicit temporary `String(P("test"))` and restore warning-less & correct comparison with NULL through `==(const char*)` overload. --- cores/esp8266/WString.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cores/esp8266/WString.h b/cores/esp8266/WString.h index e6cdc42338..b715aa570c 100644 --- a/cores/esp8266/WString.h +++ b/cores/esp8266/WString.h @@ -227,9 +227,6 @@ class String { bool operator ==(const char *cstr) const { return equals(cstr); } - bool operator ==(const __FlashStringHelper *rhs) const { - return equals(rhs); - } bool operator ==(std::nullptr_t) const { return length() == 0; } @@ -239,9 +236,6 @@ class String { bool operator !=(const char *cstr) const { return !equals(cstr); } - bool operator !=(const __FlashStringHelper *rhs) const { - return !equals(rhs); - } bool operator !=(std::nullptr_t) const { return length() != 0; } From a02c21cc7982a1e6610defd6fcefb8e57f633508 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Mon, 16 May 2022 22:50:36 +0200 Subject: [PATCH 4/7] restore the ==flashstringhelper overload, add ==decltype(NULL) --- cores/esp8266/WString.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cores/esp8266/WString.h b/cores/esp8266/WString.h index b715aa570c..72f214f36e 100644 --- a/cores/esp8266/WString.h +++ b/cores/esp8266/WString.h @@ -211,10 +211,9 @@ class String { return *this; } - // checks whether the internal buffer pointer is set. - // (should not be the case for us, since we always reset the pointer to the SSO buffer instead of setting it to nullptr) + // checks whether the String is empty explicit operator bool() const { - return buffer() != nullptr; + return length() != 0; } int compareTo(const String &s) const; @@ -227,18 +226,30 @@ class String { bool operator ==(const char *cstr) const { return equals(cstr); } + bool operator ==(const __FlashStringHelper *rhs) const { + return equals(rhs); + } bool operator ==(std::nullptr_t) const { return length() == 0; } + bool operator ==(decltype(NULL)) const { + return length() == 0; + } bool operator !=(const String &rhs) const { return !equals(rhs); } bool operator !=(const char *cstr) const { return !equals(cstr); } + bool operator !=(const __FlashStringHelper *rhs) const { + return !equals(rhs); + } bool operator !=(std::nullptr_t) const { return length() != 0; } + bool operator !=(decltype(NULL)) const { + return length() != 0; + } bool operator <(const String &rhs) const; bool operator >(const String &rhs) const; bool operator <=(const String &rhs) const; From bc52bd67aded7d46e6fedd416ab25d54ce61858f Mon Sep 17 00:00:00 2001 From: david gauchard Date: Mon, 16 May 2022 22:54:07 +0200 Subject: [PATCH 5/7] deprecate usage of NULL --- cores/esp8266/WString.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cores/esp8266/WString.h b/cores/esp8266/WString.h index 72f214f36e..ae12ef49c8 100644 --- a/cores/esp8266/WString.h +++ b/cores/esp8266/WString.h @@ -232,6 +232,7 @@ class String { bool operator ==(std::nullptr_t) const { return length() == 0; } + [[deprecated("use nullptr instead of NULL")]] bool operator ==(decltype(NULL)) const { return length() == 0; } @@ -247,6 +248,7 @@ class String { bool operator !=(std::nullptr_t) const { return length() != 0; } + [[deprecated("use nullptr instead of NULL")]] bool operator !=(decltype(NULL)) const { return length() != 0; } From 65ad698ff2a002fd1de36eed2d5ed7b03ec650db Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Tue, 17 May 2022 10:03:13 +0200 Subject: [PATCH 6/7] removing again ==(FlashStringHelper) overload --- cores/esp8266/WString.h | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/cores/esp8266/WString.h b/cores/esp8266/WString.h index ae12ef49c8..467e9e30bc 100644 --- a/cores/esp8266/WString.h +++ b/cores/esp8266/WString.h @@ -226,32 +226,12 @@ class String { bool operator ==(const char *cstr) const { return equals(cstr); } - bool operator ==(const __FlashStringHelper *rhs) const { - return equals(rhs); - } - bool operator ==(std::nullptr_t) const { - return length() == 0; - } - [[deprecated("use nullptr instead of NULL")]] - bool operator ==(decltype(NULL)) const { - return length() == 0; - } bool operator !=(const String &rhs) const { return !equals(rhs); } bool operator !=(const char *cstr) const { return !equals(cstr); } - bool operator !=(const __FlashStringHelper *rhs) const { - return !equals(rhs); - } - bool operator !=(std::nullptr_t) const { - return length() != 0; - } - [[deprecated("use nullptr instead of NULL")]] - bool operator !=(decltype(NULL)) const { - return length() != 0; - } bool operator <(const String &rhs) const; bool operator >(const String &rhs) const; bool operator <=(const String &rhs) const; From fb666efefa542eb21583c0ed793e79b56e9976a5 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Tue, 17 May 2022 14:09:55 +0200 Subject: [PATCH 7/7] revert changes about operator bool() --- cores/esp8266/WString.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cores/esp8266/WString.h b/cores/esp8266/WString.h index 467e9e30bc..47a9177534 100644 --- a/cores/esp8266/WString.h +++ b/cores/esp8266/WString.h @@ -211,9 +211,10 @@ class String { return *this; } - // checks whether the String is empty + // checks whether the internal buffer pointer is set. + // (should not be the case for us, since we always reset the pointer to the SSO buffer instead of setting it to nullptr) explicit operator bool() const { - return length() != 0; + return buffer() != nullptr; } int compareTo(const String &s) const;