Esempio n. 1
0
void SimpleString::replace(const char* to, const char* with)
{
    int c = count(to);
    int len = size();
    int tolen = PlatformSpecificStrLen(to);
    int withlen = PlatformSpecificStrLen(with);

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

    if (newsize) {
        char* newbuf = allocString(newsize);
        for (int i = 0, j = 0; i < len;) {
            if (PlatformSpecificStrNCmp(&buffer[i], to, tolen) == 0) {
                PlatformSpecificStrNCpy(&newbuf[j], with, withlen);
                j += withlen;
                i += tolen;
            }
            else {
                newbuf[j] = buffer[i];
                j++;
                i++;
            }
        }
        deallocString(buffer);
        buffer = newbuf;
        buffer[newsize-1] = '\0';
    }
    else {
        buffer = getEmptryString();
        buffer [0] = '\0';
    }
}
void SimpleString::replace(const char* to, const char* with)
{
	size_t c = count(to);
	size_t len = size();
	size_t tolen = PlatformSpecificStrLen(to);
	size_t withlen = PlatformSpecificStrLen(with);

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

	if (newsize) {
		char* newbuf = allocStringBuffer(newsize);
		for (size_t i = 0, j = 0; i < len;) {
			if (PlatformSpecificStrNCmp(&buffer_[i], to, tolen) == 0) {
				StrNCpy(&newbuf[j], with, withlen + 1);
				j += withlen;
				i += tolen;
			}
			else {
				newbuf[j] = buffer_[i];
				j++;
				i++;
			}
		}
		deallocStringBuffer(buffer_);
		buffer_ = newbuf;
		buffer_[newsize - 1] = '\0';
	}
	else {
		buffer_ = getEmptyString();
		buffer_[0] = '\0';
	}
}
bool SimpleString::contains(const SimpleString& other) const
{
	//strstr on some machines does not handle ""
	//the right way.  "" should be found in any string
	if (PlatformSpecificStrLen(other.buffer_) == 0) return true;
	else if (PlatformSpecificStrLen(buffer_) == 0) return false;
	else return PlatformSpecificStrStr(buffer_, other.buffer_) != 0;
}
Esempio n. 4
0
bool SimpleString::endsWith(const SimpleString& other) const
{
    int buffer_length = PlatformSpecificStrLen(buffer);
    int other_buffer_length = PlatformSpecificStrLen(other.buffer);
    if (other_buffer_length == 0) return true;
    if (buffer_length == 0) return false;
    if (buffer_length < other_buffer_length) return false;
    return PlatformSpecificStrCmp(buffer + buffer_length - other_buffer_length, other.buffer) == 0;
}
Esempio n. 5
0
bool SimpleString::startsWith(const SimpleString& other) const
{
    if (PlatformSpecificStrLen(other.buffer) == 0)
        return true;
    else if (PlatformSpecificStrLen(buffer) == 0)
        return false;
    else
        return PlatformSpecificStrStr(buffer, other.buffer) == buffer;
}
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;

}
Esempio n. 7
0
SimpleString::SimpleString(const char *other, int repeatCount)
{
	int len = PlatformSpecificStrLen(other) * repeatCount + 1;
	buffer = allocString(len);
	char* next = buffer;
	for (int i = 0; i < repeatCount; i++) {
		PlatformSpecificStrCpy(next, other);
		next += PlatformSpecificStrLen(other);
	}
	*next = 0;

}
static SimpleString extractFileNameFromPath(const char* file)
{
	const char* fileNameOnly = file + PlatformSpecificStrLen(file);
	while (fileNameOnly != file && *fileNameOnly != '/')
		fileNameOnly--;
	if (*fileNameOnly == '/') fileNameOnly++;
	return fileNameOnly;
}
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;
}
Esempio n. 10
0
SimpleString& SimpleString::operator+=(const char* rhs)
{
    int len = this->size() + PlatformSpecificStrLen(rhs) + 1;
    char* tbuffer = allocString(len);
    PlatformSpecificStrCpy(tbuffer, this->buffer);
    PlatformSpecificStrCat(tbuffer, rhs);
    deallocString(buffer);
    buffer = tbuffer;
    return *this;
}
Esempio n. 11
0
SimpleString::SimpleString (const char *otherBuffer)
{
    if (otherBuffer == 0) {
        buffer = getEmptryString();
    }
    else {
        int len = PlatformSpecificStrLen (otherBuffer) + 1;
        buffer = allocString(len);
        PlatformSpecificStrCpy (buffer, otherBuffer);
    }
}
Esempio n. 12
0
SimpleString& SimpleString::operator+=(const char* rhs)
{
	size_t originalSize = this->size();
	size_t additionalStringSize = PlatformSpecificStrLen(rhs) + 1;
	size_t sizeOfNewString = originalSize + additionalStringSize;
	char* tbuffer = copyToNewBuffer(this->buffer_, sizeOfNewString);
	StrNCpy(tbuffer + originalSize, rhs, additionalStringSize);
	deallocStringBuffer(this->buffer_);
	this->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);
	}
}
Esempio n. 14
0
SimpleString::SimpleString(const char *other, size_t repeatCount)
{
	size_t otherStringLength = PlatformSpecificStrLen(other);
	size_t len = otherStringLength * repeatCount + 1;
	buffer_ = allocStringBuffer(len);
	char* next = buffer_;
	for (size_t i = 0; i < repeatCount; i++) {
		StrNCpy(next, other, otherStringLength + 1);
		next += otherStringLength;
	}
	*next = 0;
}
Esempio n. 15
0
int SimpleString::size() const
{
    return PlatformSpecificStrLen (buffer);
}