String.cpp 743 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <iostream>
  2. #include <cstring>
  3. #include "String.h"
  4. #include "Types.h"
  5. String::String() : length(0) {
  6. data[0] = '\0';
  7. }
  8. String::operator const char*() const {
  9. return data;
  10. }
  11. String& String::append(char c) {
  12. if(length + 1 < LENGTH) {
  13. data[length++] = c;
  14. data[length] = '\0';
  15. }
  16. return *this;
  17. }
  18. String& String::append(const char* str) {
  19. for(uint i = 0; length + 1 < LENGTH && str[i] != '\0'; length++, i++) {
  20. data[length] = str[i];
  21. }
  22. data[length] = '\0';
  23. return *this;
  24. }
  25. uint String::getLength() const {
  26. return length;
  27. }
  28. void String::clear() {
  29. length = 0;
  30. data[0] = '\0';
  31. }
  32. bool String::operator==(const char* str) const {
  33. return strcmp(data, str) == 0;
  34. }