String.h 985 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef STRING_H
  2. #define STRING_H
  3. #include "common/utils/Types.h"
  4. class String final {
  5. public:
  6. String();
  7. String(const char* str);
  8. bool operator==(const String& other) const;
  9. bool operator!=(const String& other) const;
  10. operator const char*() const;
  11. char operator[](uint index) const;
  12. uint getLength() const;
  13. template<typename T>
  14. String& append(const char* format, const T& t) {
  15. uint left = MAX_LENGTH - length;
  16. uint written = snprintf(data + length, left, format, t);
  17. if(written < left) {
  18. length += written;
  19. } else {
  20. length = MAX_LENGTH;
  21. }
  22. return *this;
  23. }
  24. String& append(char c);
  25. String& append(const char* str);
  26. String& append(uint i);
  27. String& append(int i);
  28. String& append(float f);
  29. String& append(bool b);
  30. String& clear();
  31. static constexpr uint MAX_LENGTH = 255;
  32. private:
  33. char data[MAX_LENGTH];
  34. u8 length;
  35. };
  36. #endif