1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-18 19:29:09 +00:00

Fix substring indexing and whitespace.

Fixes an off-by-one and off-by-initial-offset error,
not clearing the stream between loops,
and a few other edge conditions.
This commit is contained in:
2013-01-13 12:34:06 -08:00
parent a2dd2f60d2
commit 0efcebb2e9

View File

@ -84,16 +84,20 @@ void pfLocalizedString::IParameterize(const plString & inString)
if (nextToken != -1)
{
// Check it's not escaped.
if ((nextToken > 0) && (remainder.CharAt(nextToken-1) != '\\'))
if ((nextToken == 0) || ((nextToken > 0) && (remainder.CharAt(nextToken-1) != '\\')))
{
// Check if it has an end.
// Check if it has an end (ignoring any terminators we need to cross a space to find).
int endToken = remainder.Substr(nextToken).Find("s");
if (endToken != -1)
if ((endToken != -1) && (remainder.Substr(nextToken, endToken).Find(" ") == -1))
{
// Store existing block.
newText << remainder;
// Store existing block if it contains anything.
newText << remainder.Substr(0, nextToken);
curTextBlock.fText = newText.GetString().Replace("\\\\", "\\");
if (!curTextBlock.fText.IsEmpty())
{
fText.push_back(curTextBlock);
newText.Truncate();
}
if (endToken == nextToken + 1)
{
@ -107,7 +111,7 @@ void pfLocalizedString::IParameterize(const plString & inString)
{
// Store indexed param block.
curTextBlock.fIsParam = true;
curTextBlock.fParamIndex = remainder.Substr(nextToken, endToken-1).ToInt(10) - 1; // args start at 1
curTextBlock.fParamIndex = remainder.Substr(nextToken + 1, endToken - 1).ToInt(10) - 1; // args start at 1
curTextBlock.fText = "";
fText.push_back(curTextBlock);
}
@ -115,8 +119,16 @@ void pfLocalizedString::IParameterize(const plString & inString)
curTextBlock.fParamIndex = 0;
fNumArguments++;
// Continue using the remaining string.
remainder = remainder.Substr(endToken+1);
// Continue, using the remaining string.
remainder = remainder.Substr(nextToken + endToken + 1);
}
else
{
// We have an unescaped but unterminated %.
// For now, let's just pretend it was escaped;
// This way they'll show up visibly in-game and will be reported.
newText << "%";
remainder = remainder.Substr(nextToken + 1);
}
}
else
@ -132,7 +144,11 @@ void pfLocalizedString::IParameterize(const plString & inString)
newText << remainder;
remainder = "";
curTextBlock.fText = newText.GetString().Replace("\\\\", "\\");
if (!curTextBlock.fText.IsEmpty())
{
fText.push_back(curTextBlock);
newText.Truncate();
}
}
}
}
@ -159,7 +175,7 @@ void pfLocalizedString::IUpdatePlainText()
if (curTextBlock.fIsParam)
{
// Fill in parameter value.
ss << plString::Format("%%%ds", curTextBlock.fParamIndex + 1);
ss << "%%" << curTextBlock.fParamIndex + 1 << "s";
}
else
{
@ -192,8 +208,7 @@ void pfLocalizedString::IUpdateXML()
if (curTextBlock.fIsParam)
{
// Fill in parameter value.
plString paramStr = plString::Format("%%%ds", curTextBlock.fParamIndex + 1);
ss << paramStr;
ss << "%%" << curTextBlock.fParamIndex + 1 << "s";
}
else
{