SimpleString& SimpleString::operator=(const SimpleString& other) { if (this != &other) { deallocStringBuffer(buffer_, __FILE__, __LINE__); buffer_ = copyToNewBuffer(other.buffer_); } return *this; }
SimpleString::SimpleString(const char *otherBuffer) { if (otherBuffer == 0) { buffer_ = getEmptyString(); } else { buffer_ = copyToNewBuffer(otherBuffer); } }
SimpleString& SimpleString::operator+=(const char* rhs) { size_t originalSize = this->size(); size_t additionalStringSize = StrLen(rhs) + 1; size_t sizeOfNewString = originalSize + additionalStringSize; char* tbuffer = copyToNewBuffer(this->buffer_, sizeOfNewString); StrNCpy(tbuffer + originalSize, rhs, additionalStringSize); deallocStringBuffer(this->buffer_, __FILE__, __LINE__); this->buffer_ = tbuffer; return *this; }
void SimpleString::split(const SimpleString& delimiter, SimpleStringCollection& col) const { size_t num = count(delimiter); size_t extraEndToken = (endsWith(delimiter)) ? 0 : 1U; col.allocate(num + extraEndToken); char* str = buffer_; char* prev; for (size_t i = 0; i < num; ++i) { prev = str; str = StrStr(str, delimiter.buffer_) + 1; size_t len = (size_t) (str - prev) + 1; col[i].buffer_ = copyToNewBuffer(prev, len); } if (extraEndToken) { col[num] = str; } }
SimpleString::SimpleString(const SimpleString& other) { buffer_ = copyToNewBuffer(other.buffer_); }