2021-03-29 17:14:01 +02:00
|
|
|
// ArduinoJson - https://arduinojson.org
|
2021-01-25 09:14:15 +01:00
|
|
|
// Copyright Benoit Blanchon 2014-2021
|
2020-01-14 10:32:52 +01:00
|
|
|
// MIT License
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
// Reproduces Arduino's String class
|
|
|
|
class String {
|
|
|
|
public:
|
2020-07-21 20:15:31 +02:00
|
|
|
String() {}
|
|
|
|
explicit String(const char* s) : _str(s) {}
|
|
|
|
|
2020-01-14 14:50:44 +01:00
|
|
|
String& operator+=(const char* rhs) {
|
|
|
|
_str += rhs;
|
2020-01-14 10:32:52 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t length() const {
|
|
|
|
return _str.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* c_str() const {
|
|
|
|
return _str.c_str();
|
|
|
|
}
|
|
|
|
|
2020-01-14 14:50:44 +01:00
|
|
|
bool operator==(const char* s) const {
|
|
|
|
return _str == s;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend std::ostream& operator<<(std::ostream& lhs, const ::String& rhs) {
|
|
|
|
lhs << rhs._str;
|
|
|
|
return lhs;
|
|
|
|
}
|
|
|
|
|
2020-01-14 10:32:52 +01:00
|
|
|
private:
|
|
|
|
std::string _str;
|
|
|
|
};
|
|
|
|
|
|
|
|
class StringSumHelper;
|
|
|
|
|
2020-01-14 14:50:44 +01:00
|
|
|
inline bool operator==(const std::string& lhs, const ::String& rhs) {
|
2020-01-14 10:32:52 +01:00
|
|
|
return lhs == rhs.c_str();
|
|
|
|
}
|