Ejemplo n.º 1
0
TEST(SimpleString, CollectionWritingToEmptyString)
{
	SimpleStringCollection col;
	col.allocate(3);
	col[3] = SimpleString("HAH");
	STRCMP_EQUAL("", col[3].asCharString());
}
Ejemplo n.º 2
0
TEST(SimpleString, CollectionMultipleAllocateNoLeaksMemory)
{
	SimpleStringCollection col;
	col.allocate(5);
	col.allocate(5);
	// CHECK no memory leak
}
Ejemplo n.º 3
0
SimpleString FailableMemoryAllocator::getBaseName(const char* file)
{
    SimpleString fileFullPath(file);
    fileFullPath.replace('\\', '/');
    SimpleStringCollection pathElements;
    fileFullPath.split("/", pathElements);
    return pathElements[pathElements.size() - 1];
}
Ejemplo n.º 4
0
TEST(SimpleString, splitNoTokenOnTheEnd)
{
	SimpleString string("Bah Yah oops");
	SimpleStringCollection collection;

	string.split(" ", collection);
	LONGS_EQUAL(3, collection.size());
	STRCMP_EQUAL("Bah ", collection[0].asCharString());
	STRCMP_EQUAL("Yah ", collection[1].asCharString());
	STRCMP_EQUAL("oops", collection[2].asCharString());
}
Ejemplo n.º 5
0
TEST(SimpleString, split)
{
	SimpleString hi("hello\nworld\nhow\ndo\nyou\ndo\n\n");

	SimpleStringCollection collection;
	hi.split("\n", collection);

	LONGS_EQUAL(7, collection.size());
	STRCMP_EQUAL("hello\n", collection[0].asCharString());
	STRCMP_EQUAL("world\n", collection[1].asCharString());
	STRCMP_EQUAL("how\n", collection[2].asCharString());
	STRCMP_EQUAL("do\n", collection[3].asCharString());
	STRCMP_EQUAL("you\n", collection[4].asCharString());
	STRCMP_EQUAL("do\n", collection[5].asCharString());
	STRCMP_EQUAL("\n", collection[6].asCharString());
}
Ejemplo n.º 6
0
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;
        col[i] = SimpleString(prev).subString(0, size_t (str - prev));
    }
    if (extraEndToken) {
        col[num] = str;
    }
}
Ejemplo n.º 7
0
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 = PlatformSpecificStrStr(str, delimiter.buffer_) + 1;
		size_t len = (size_t) (str - prev) + 1;
		col[i].buffer_ = copyToNewBuffer(prev, len);
	}
	if (extraEndToken) {
		col[num] = str;
	}
}
Ejemplo n.º 8
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;
	}
}
Ejemplo n.º 10
0
TEST(SimpleString, CollectionReadOutOfBoundsReturnsEmptyString)
{
	SimpleStringCollection col;
	col.allocate(3);
	STRCMP_EQUAL("", col[3].asCharString());
}
Ejemplo n.º 11
0
 size_t amountOfLines()
 {
     buffer_.split("\n", linesOfFile_);
     return linesOfFile_.size();
 }