Beispiel #1
0
//
// Compare two strings without respecting case and return the result, <0 if *this<rhs, >0 if *this>rhs or 0 if *this==rhs
//
int STR_String::CompareNoCase(rcSTR_String rhs) const
{
#ifdef WIN32
	return stricmp(this->ReadPtr(), rhs.ReadPtr());
#else
	return strcasecmp(this->ReadPtr(), rhs.ReadPtr());
#endif
}
Beispiel #2
0
//
// Construct a string from the first number of characters in another string
//
STR_String::STR_String(rcSTR_String str, int len) :
	pData(new char [len+8]),
	Len(len),
	Max(len+8)
{
	assertd(pData != NULL);
	assertd(str.pData != NULL);
	memcpy(pData, str.pData, str.Length());
	pData[str.Length()] = 0;
}
Beispiel #3
0
//
// Construct a string from the first number of characters in another string
//
STR_String::STR_String(rcSTR_String str, int len) :
	m_data(new char[len + 8]),
	m_len(len),
	m_max(len + 8)
{
	assertd(this->m_data != NULL);
	assertd(str.this->m_data != NULL);
	memcpy(this->m_data, str.ReadPtr(), str.Length());
	this->m_data[str.Length()] = 0;
}
Beispiel #4
0
//
// Find the first occurence of <str> in the string
//
int	STR_String::Find(rcSTR_String str, int pos) const
{
	assertd(pos >= 0);
	assertd(Len==0 || pos<Len);
	assertd(pData != NULL);
	char *find_pos = strstr(pData+pos, str.ReadPtr());
	return (find_pos) ? (find_pos-pData) : -1;
}
Beispiel #5
0
//
// Replace a substring of this string with another string
//
void STR_String::Replace(int pos, int num, rcSTR_String str)
{
	//bounds(pos, 0, Length()-1);
	//bounds(pos+num, 0, Length());
	assertd(num >= 1);

	if (str.Length() < num)
	{
		// Remove some data from the string by replacement
		memcpy(this->m_data + pos + str.Length(), this->m_data + pos + num, this->m_len - pos - num + 1);
		memcpy(this->m_data + pos, str.ReadPtr(), str.Length());
	}
	else {
		// Insert zero or more characters into the string
		AllocBuffer(this->m_len + str.Length() - num, true);
		if (str.Length() != num) memcpy(this->m_data + pos + str.Length(), this->m_data + pos + num, Length() - pos - num + 1);
		memcpy(this->m_data + pos, str.ReadPtr(), str.Length());
	}

	this->m_len += str.Length() - num;
}
Beispiel #6
0
//
// Replace a character in this string with another string
//
void STR_String::Replace(int pos, rcSTR_String str)
{
	//bounds(pos, 0, Length()-1);

	if (str.Length() < 1)
	{
		// Remove one character from the string
		memcpy(this->m_data + pos, this->m_data + pos + 1, this->m_len - pos);
	}
	else {
		// Insert zero or more characters into the string
		AllocBuffer(this->m_len + str.Length() - 1, true);
		if (str.Length() != 1) memcpy(this->m_data + pos + str.Length(), this->m_data + pos + 1, Length() - pos);
		memcpy(this->m_data + pos, str.ReadPtr(), str.Length());
	}

	this->m_len += str.Length() - 1;
}
Beispiel #7
0
//
// Compare two strings and return the result, <0 if *this<rhs, >0 if *this>rhs or 0 if *this==rhs
//
int STR_String::Compare(rcSTR_String rhs) const
{
	return strcmp(this->ReadPtr(), rhs.ReadPtr());
}