String.h 783 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2021
  3. // MIT License
  4. #pragma once
  5. #include <string>
  6. // Reproduces Arduino's String class
  7. class String {
  8. public:
  9. String() {}
  10. explicit String(const char* s) : _str(s) {}
  11. String& operator+=(const char* rhs) {
  12. _str += rhs;
  13. return *this;
  14. }
  15. size_t length() const {
  16. return _str.size();
  17. }
  18. const char* c_str() const {
  19. return _str.c_str();
  20. }
  21. bool operator==(const char* s) const {
  22. return _str == s;
  23. }
  24. friend std::ostream& operator<<(std::ostream& lhs, const ::String& rhs) {
  25. lhs << rhs._str;
  26. return lhs;
  27. }
  28. private:
  29. std::string _str;
  30. };
  31. class StringSumHelper;
  32. inline bool operator==(const std::string& lhs, const ::String& rhs) {
  33. return lhs == rhs.c_str();
  34. }