String.cpp 564 B

1234567891011121314151617181920212223242526
  1. #include <cstring>
  2. #include "common/utils/String.h"
  3. String::String() : length(0) {
  4. data[0] = '\0';
  5. }
  6. String::String(const char* str) : length(0) {
  7. for(; length < BUFFER_LENGTH - 1 && str[length] != '\0'; length++) {
  8. data[length] = str[length];
  9. }
  10. data[length] = '\0';
  11. }
  12. bool String::operator==(const String& other) const {
  13. return length == other.length && strcmp(data, other.data) == 0;
  14. }
  15. bool String::operator!=(const String& other) const {
  16. return !(*this == other);
  17. }
  18. String::operator const char*() const {
  19. return data;
  20. }