Ejemplo n.º 1
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;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
int SimpleString::count(const SimpleString& substr) const
{
    int num = 0;
    char* str = buffer;
    while( (str = PlatformSpecificStrStr(str, substr.buffer)) ) {
        num++;
        str++;
    }
    return num;
}
Ejemplo n.º 4
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.º 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;
	}
}