示例#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 CodeMemoryReportFormatter::addNodeToList(const char* variableName, void* memory, CodeReportingAllocationNode* next)
{
	CodeReportingAllocationNode* newNode = (CodeReportingAllocationNode*) (void*) internalAllocator_->alloc_memory(sizeof(CodeReportingAllocationNode), __FILE__, __LINE__);
	newNode->memory_ = memory;
	newNode->next_ = next;
	PlatformSpecificStrNCpy(newNode->variableName_, variableName, MAX_VARIABLE_NAME_LENGTH);
	codeReportingList_ = newNode;
}
void SimpleString::copyToBuffer(char* bufferToCopy, size_t bufferSize) const
{
	if (bufferToCopy == NULL || bufferSize == 0) return;

	size_t sizeToCopy = (bufferSize-1 < size()) ? bufferSize-1 : size();

	PlatformSpecificStrNCpy(bufferToCopy, buffer_, sizeToCopy);
	bufferToCopy[sizeToCopy] = '\0';

}
示例#4
0
TEST(TestHarness_c, cpputest_realloc_larger)
{
	const char* number_string = "123456789";

	char* mem1 = (char*) cpputest_malloc(10);

	PlatformSpecificStrNCpy(mem1, number_string, 10);
	CHECK(mem1 != 0);

	char* mem2 = (char*) cpputest_realloc(mem1, 1000);

	CHECK(mem2 != 0);
	STRCMP_EQUAL(number_string, mem2);

	cpputest_free(mem2);
}
示例#5
0
void SimpleString::split(const SimpleString& split, SimpleStringCollection& col) const
{
    int num = count(split);
    int extraEndToken = (endsWith(split)) ? 0 : 1;
    col.allocate(num + extraEndToken);

    char* str = buffer;
    char* prev;
    for (int i = 0; i < num; ++i) {
        prev = str;
        str = PlatformSpecificStrStr(str, split.buffer) + 1;
        int len = str - prev;
        char* sub = allocString(len+1);
        PlatformSpecificStrNCpy(sub, prev, len);
        sub[len] = '\0';
        col[i] = sub;
        deallocString(sub);
    }
    if (extraEndToken) {
        col[num] = str;
    }
}
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;
	}
}