123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #ifndef STRING_H
- #define STRING_H
- #include "common/utils/Types.h"
- class String final {
- public:
- String();
- String(const char* str);
- String(const String& other);
- String& operator=(const String& other);
- bool operator==(const String& other) const;
- bool operator!=(const String& other) const;
- operator const char*() const;
- char operator[](uint index) const;
- uint getLength() const;
- template<typename T>
- String& append(const char* format, const T& t) {
- uint left = MAX_LENGTH - length;
- uint written = snprintf(data + length, left, format, t);
- if(written < left) {
- length += written;
- } else {
- length = MAX_LENGTH;
- }
- return *this;
- }
- String& append(const char* str);
-
- String& append(u8 u);
- String& append(u16 u);
- String& append(u32 u);
- String& append(u64 u);
-
- String& append(s8 s);
- String& append(s16 s);
- String& append(s32 s);
- String& append(s64 s);
-
- String& append(float f);
- String& append(bool b);
-
- String& clear();
-
- static constexpr uint MAX_LENGTH = 255;
- private:
- char data[MAX_LENGTH];
- u8 length;
- };
- #endif
|