예제 #1
0
void SimpleString::replace(const char* to, const char* with)
{
    size_t c = count(to);
    size_t len = size();
    size_t tolen = StrLen(to);
    size_t withlen = StrLen(with);

    size_t newsize = len + (withlen * c) - (tolen * c) + 1;

    if (newsize > 1) {
        char* newbuf = allocStringBuffer(newsize, __FILE__, __LINE__);
        for (size_t i = 0, j = 0; i < len;) {
            if (StrNCmp(&buffer_[i], to, tolen) == 0) {
                StrNCpy(&newbuf[j], with, withlen + 1);
                j += withlen;
                i += tolen;
            }
            else {
                newbuf[j] = buffer_[i];
                j++;
                i++;
            }
        }
        deallocStringBuffer(buffer_, __FILE__, __LINE__);
        buffer_ = newbuf;
        buffer_[newsize - 1] = '\0';
    }
    else {
        deallocStringBuffer(buffer_, __FILE__, __LINE__);
        buffer_ = getEmptyString();
    }
}
예제 #2
0
SimpleString& SimpleString::operator=(const SimpleString& other)
{
    if (this != &other) {
        deallocStringBuffer(buffer_, __FILE__, __LINE__);
        buffer_ = copyToNewBuffer(other.buffer_);
    }
    return *this;
}
SimpleString& SimpleString::operator=(const SimpleString& other)
{
	if (this != &other) {
		deallocStringBuffer(buffer_);
		size_t len = other.size() + 1;
		buffer_ = allocStringBuffer(len);
		PlatformSpecificStrCpy(buffer_, other.buffer_);
	}
	return *this;
}
SimpleString& SimpleString::operator+=(const char* rhs)
{
	size_t len = this->size() + PlatformSpecificStrLen(rhs) + 1;
	char* tbuffer = allocStringBuffer(len);
	PlatformSpecificStrCpy(tbuffer, this->buffer_);
	PlatformSpecificStrCat(tbuffer, rhs);
	deallocStringBuffer(buffer_);
	buffer_ = tbuffer;
	return *this;
}
예제 #5
0
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 : 1;
	col.allocate(num + extraEndToken);

	char* str = buffer_;
	char* prev;
	for (size_t i = 0; i < num; ++i) {
		prev = str;
		str = PlatformSpecificStrStr(str, delimiter.buffer_) + 1;
		size_t len = str - prev;
		char* sub = allocStringBuffer(len + 1);
		PlatformSpecificStrNCpy(sub, prev, len);
		sub[len] = '\0';
		col[i] = sub;
		deallocStringBuffer(sub);
	}
	if (extraEndToken) {
		col[num] = str;
	}
}
예제 #7
0
SimpleString::~SimpleString()
{
    deallocStringBuffer(buffer_, __FILE__, __LINE__);
}
예제 #8
0
SimpleString::~SimpleString()
{
    deallocStringBuffer(buffer_);
}