#ifndef WSTRING_H #define WSTRING_H /*#include class String : public std::string { public: String() : std::string() {} String(uint32_t val) : std::string(std::to_string(val)) {} String(double value, unsigned int decimalPlaces) : std::string(std::to_string(value)) {} String(const char* str) : std::string(str) {} }; */ #include #include #include #include class String { private: std::string data; public: // Constructors String() = default; String(const char* s) : data(s) {} String(const std::string& s) : data(s) {} String(const String& other) = default; String(String&& other) = default; // Numeric constructors (Arduino-style) String(uint64_t value) { data = std::to_string(value); } String(int value) { data = std::to_string(value); } String(unsigned int value) { data = std::to_string(value); } String(long value) { data = std::to_string(value); } String(unsigned long value) { data = std::to_string(value); } String(float value) { data = std::to_string(value); } String(double value) { data = std::to_string(value); } String(float value, unsigned int decimalPlaces) { std::ostringstream oss; oss << std::fixed << std::setprecision(decimalPlaces) << value; data = oss.str(); } // Assignment operators String& operator=(const String& other) = default; String& operator=(String&& other) = default; // Conversion operator to std::string operator std::string() const { return data; } // Accessor const std::string& str() const { return data; } // Concatenation String operator+(const String& rhs) const { return String(data + rhs.data); } String operator+(const std::string& rhs) const { return String(data + rhs); } String operator+(const char* rhs) const { return String(data + std::string(rhs)); } // Append String& operator+=(const String& rhs) { data += rhs.data; return *this; } String& operator+=(const std::string& rhs) { data += rhs; return *this; } String& operator+=(const char* rhs) { data += rhs; return *this; } // Arduino-like methods (example) int length() const { return static_cast(data.length()); } const char* c_str() const { return data.c_str(); } // Friend functions to allow std::string + String friend String operator+(const std::string& lhs, const String& rhs) { return String(lhs + rhs.data); } friend String operator+(const char* lhs, const String& rhs) { return String(std::string(lhs) + rhs.data); } friend std::ostream& operator<<(std::ostream& os, const String& s) { return os << s.data; } }; #endif