Beispiel #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();
    }
}
Beispiel #2
0
char* SimpleString::copyToNewBuffer(const char* bufferToCopy, size_t bufferSize)
{
    if(bufferSize == 0) bufferSize = StrLen(bufferToCopy) + 1;

    char* newBuffer = allocStringBuffer(bufferSize, __FILE__, __LINE__);
    StrNCpy(newBuffer, bufferToCopy, bufferSize);
    newBuffer[bufferSize-1] = '\0';
    return newBuffer;
}
char* SimpleString::copyToNewBuffer(const char* bufferToCopy, size_t bufferSize)
{
	if(bufferSize == 0) bufferSize = PlatformSpecificStrLen(bufferToCopy) + 1;

	char* newBuffer = allocStringBuffer(bufferSize);
	StrNCpy(newBuffer, bufferToCopy, bufferSize);
	newBuffer[bufferSize-1] = '\0';
	return newBuffer;
}
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;
}
SimpleString::SimpleString(const char *otherBuffer)
{
	if (otherBuffer == 0) {
		buffer_ = getEmptyString();
	}
	else {
		size_t len = PlatformSpecificStrLen(otherBuffer) + 1;
		buffer_ = allocStringBuffer(len);
		PlatformSpecificStrCpy(buffer_, otherBuffer);
	}
}
Beispiel #7
0
SimpleString::SimpleString(const char *other, size_t repeatCount)
{
    size_t otherStringLength = StrLen(other);
    size_t len = otherStringLength * repeatCount + 1;
    buffer_ = allocStringBuffer(len, __FILE__, __LINE__);
    char* next = buffer_;
    for (size_t i = 0; i < repeatCount; i++) {
        StrNCpy(next, other, otherStringLength + 1);
        next += otherStringLength;
    }
    *next = 0;
}
SimpleString::SimpleString(const char *other, size_t repeatCount)
{
	size_t len = PlatformSpecificStrLen(other) * repeatCount + 1;
	buffer_ = allocStringBuffer(len);
	char* next = buffer_;
	for (size_t i = 0; i < repeatCount; i++) {
		PlatformSpecificStrCpy(next, other);
		next += PlatformSpecificStrLen(other);
	}
	*next = 0;

}
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;
	}
}
Beispiel #10
0
char* SimpleString::getEmptyString() const
{
    char* empty = allocStringBuffer(1, __FILE__, __LINE__);
    empty[0] = '\0';
    return empty;
}
Beispiel #11
0
char* SimpleString::getEmptyString() const
{
    char* empty = allocStringBuffer(1);
    empty[0] = '\0';
    return empty;
}
SimpleString::SimpleString(const SimpleString& other)
{
	size_t len = other.size() + 1;
	buffer_ = allocStringBuffer(len);
	PlatformSpecificStrCpy(buffer_, other.buffer_);
}