Add safe bool idiom in JsonString

This commit is contained in:
Benoit Blanchon
2021-10-22 17:19:14 +02:00
parent 8418845c8d
commit acfa174333
5 changed files with 55 additions and 7 deletions

View File

@@ -4,9 +4,11 @@
#pragma once
#include <ArduinoJson/Misc/SafeBoolIdiom.hpp>
namespace ARDUINOJSON_NAMESPACE {
class String {
class String : public SafeBoolIdom<String> {
public:
String() : _data(0), _isStatic(true) {}
String(const char* data, bool isStaticData = true)
@@ -24,6 +26,11 @@ class String {
return _isStatic;
}
// safe bool idiom
operator bool_type() const {
return _data ? safe_true() : safe_false();
}
friend bool operator==(String lhs, String rhs) {
if (lhs._data == rhs._data)
return true;