Remove from String Function

Moderator: GZDoom Developers

Post Reply
ZippeyKeys12
Posts: 111
Joined: Wed Jun 15, 2016 2:49 pm

Remove from String Function

Post by ZippeyKeys12 »

I was wondering if we could get Remove(int length, int lengthRemoved) as there seems to be a function for it in zstring:

Code: Select all

void FString::Remove(size_t index, size_t remlen)
{
	if (index < Len())
	{
		if (index + remlen >= Len())
		{
			Truncate((long)index);
		}
		else
		{
			if (Data()->RefCount == 1)
			{ // Can do this in place
				memmove(Chars + index, Chars + index + remlen, Len() - index - remlen);
				memset(Chars + Len() - remlen, 0, remlen);
				Data()->Len -= (unsigned)remlen;
			}
			else
			{ // Must do it in a copy
				FStringData *old = Data();
				AllocBuffer(old->Len - remlen);
				StrCopy(Chars, old->Chars(), index);
				StrCopy(Chars + index, old->Chars() + index + remlen, old->Len - index - remlen);
				old->Release();
			}
		}
	}
}
And I can't find a convenient alternative :? Could this be added?
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: Remove from String Function

Post by _mental_ »

Added in 5d83ee5.
ZippeyKeys12
Posts: 111
Joined: Wed Jun 15, 2016 2:49 pm

Re: Remove from String Function

Post by ZippeyKeys12 »

:o Thank you so much! :D
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”