mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-24 21:11:39 +00:00
Fixed: FString::StripLeftRight() lost the right character when copying to a new buffer
- Also, some minor improvements to the strip functions to avoid doing extra work.
This commit is contained in:
parent
513ad7f75f
commit
1e497e0b3e
1 changed files with 25 additions and 4 deletions
|
@ -635,6 +635,10 @@ void FString::StripLeft ()
|
|||
if (!isspace(Chars[i]))
|
||||
break;
|
||||
}
|
||||
if (i == 0)
|
||||
{ // Nothing to strip.
|
||||
return;
|
||||
}
|
||||
if (Data()->RefCount <= 1)
|
||||
{
|
||||
for (j = 0; i <= max; ++j, ++i)
|
||||
|
@ -666,6 +670,10 @@ void FString::StripLeft (const char *charset)
|
|||
if (!strchr (charset, Chars[i]))
|
||||
break;
|
||||
}
|
||||
if (i == 0)
|
||||
{ // Nothing to strip.
|
||||
return;
|
||||
}
|
||||
if (Data()->RefCount <= 1)
|
||||
{
|
||||
for (j = 0; i <= max; ++j, ++i)
|
||||
|
@ -686,11 +694,16 @@ void FString::StripLeft (const char *charset)
|
|||
void FString::StripRight ()
|
||||
{
|
||||
size_t max = Len(), i;
|
||||
for (i = max; i-- > 0; )
|
||||
if (max == 0) return;
|
||||
for (i = --max; i-- > 0; )
|
||||
{
|
||||
if (!isspace(Chars[i]))
|
||||
break;
|
||||
}
|
||||
if (i == max)
|
||||
{ // Nothing to strip.
|
||||
return;
|
||||
}
|
||||
if (Data()->RefCount <= 1)
|
||||
{
|
||||
Chars[i+1] = '\0';
|
||||
|
@ -714,11 +727,15 @@ void FString::StripRight (const char *charset)
|
|||
{
|
||||
size_t max = Len(), i;
|
||||
if (max == 0) return;
|
||||
for (i = max; i-- > 0; )
|
||||
for (i = --max; i-- > 0; )
|
||||
{
|
||||
if (!strchr (charset, Chars[i]))
|
||||
break;
|
||||
}
|
||||
if (i == max)
|
||||
{ // Nothing to strip.
|
||||
return;
|
||||
}
|
||||
if (Data()->RefCount <= 1)
|
||||
{
|
||||
Chars[i+1] = '\0';
|
||||
|
@ -747,6 +764,10 @@ void FString::StripLeftRight ()
|
|||
if (!isspace(Chars[j]))
|
||||
break;
|
||||
}
|
||||
if (i == 0 && j == max - 1)
|
||||
{ // Nothing to strip.
|
||||
return;
|
||||
}
|
||||
if (Data()->RefCount <= 1)
|
||||
{
|
||||
for (k = 0; i <= j; ++i, ++k)
|
||||
|
@ -759,8 +780,8 @@ void FString::StripLeftRight ()
|
|||
else
|
||||
{
|
||||
FStringData *old = Data();
|
||||
AllocBuffer (j - i);
|
||||
StrCopy (Chars, old->Chars(), j - i);
|
||||
AllocBuffer(j - i + 1);
|
||||
StrCopy(Chars, old->Chars(), j - i + 1);
|
||||
old->Release();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue