Ejemplo n.º 1
0
void FString::StripRight (const char *charset)
{
	size_t max = Len(), i;
	for (i = max; i-- > 0; )
	{
		if (!strchr (charset, Chars[i]))
			break;
	}
	if (Data()->RefCount <= 1)
	{
		Chars[i+1] = '\0';
		ReallocBuffer (i+1);
	}
	else
	{
		FStringData *old = Data();
		AllocBuffer (i+1);
		StrCopy (Chars, old->Chars(), i+1);
		old->Release();
	}
}
Ejemplo n.º 2
0
void FString::StripRight ()
{
	size_t max = Len(), i;
	for (i = max - 1; i-- > 0; )
	{
		if (!isspace(Chars[i]))
			break;
	}
	if (Data()->RefCount <= 1)
	{
		Chars[i+1] = '\0';
		ReallocBuffer (i+1);
	}
	else
	{
		FStringData *old = Data();
		AllocBuffer (i+1);
		StrCopy (Chars, old->Chars(), i+1);
		old->Release();
	}
}
Ejemplo n.º 3
0
void FString::Insert (size_t index, const char *instr, size_t instrlen)
{
	size_t mylen = Len();
	if (index > mylen)
	{
		index = mylen;
	}
	if (Data()->RefCount <= 1)
	{
		ReallocBuffer (mylen + instrlen);
		memmove (Chars + index + instrlen, Chars + index, (mylen - index + 1)*sizeof(char));
		memcpy (Chars + index, instr, instrlen*sizeof(char));
	}
	else
	{
		FStringData *old = Data();
		AllocBuffer (mylen + instrlen);
		StrCopy (Chars, old->Chars(), index);
		StrCopy (Chars + index, instr, instrlen);
		StrCopy (Chars + index + instrlen, old->Chars() + index, mylen - index);
		old->Release();
	}
}
Ejemplo n.º 4
0
void FString::StripLeft (const char *charset)
{
	size_t max = Len(), i, j;
	for (i = 0; i < max; ++i)
	{
		if (!strchr (charset, Chars[i]))
			break;
	}
	if (Data()->RefCount <= 1)
	{
		for (j = 0; i <= max; ++j, ++i)
		{
			Chars[j] = Chars[i];
		}
		ReallocBuffer (j-1);
	}
	else
	{
		FStringData *old = Data();
		AllocBuffer (max - i);
		StrCopy (Chars, old->Chars() + i, max - i);
		old->Release();
	}
}