[Added] Remove from String Function

Moderators: Developers, ZDoom.org Team

Remove from String Function

Postby ZippeyKeys12 » Thu Nov 09, 2017 12:13 am

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 allExpand view
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?
ZippeyKeys12
 
Joined: 15 Jun 2016

Re: Remove from String Function

Postby _mental_ » Sun Nov 12, 2017 7:45 am

Added in 5d83ee5.
_mental_
 
 
 
Joined: 07 Aug 2011

Re: Remove from String Function

Postby ZippeyKeys12 » Sun Nov 12, 2017 4:42 pm

:o Thank you so much! :D
ZippeyKeys12
 
Joined: 15 Jun 2016


Return to Closed Feature Suggestions

Who is online

Users browsing this forum: Google [Bot] and 2 guests