Use StringBuilder for GetString/GetStringWithArgs, as per upstream

Update dependent code as required
This commit is contained in:
Jonathan G Rennison
2024-01-05 21:12:54 +00:00
parent 1b7a5372ec
commit f034714559
61 changed files with 1064 additions and 1228 deletions

View File

@@ -1353,34 +1353,26 @@ void CommandCost::UseTextRefStack(const GRFFile *grffile, uint num_registers)
}
std::string CommandCost::SummaryMessage(StringID cmd_msg) const
{
char buf[DRAW_STRING_BUFFER];
this->WriteSummaryMessage(buf, lastof(buf), cmd_msg);
return buf;
}
int CommandCost::WriteSummaryMessage(char *buf, char *last, StringID cmd_msg) const
{
if (this->Succeeded()) {
return seprintf(buf, last, "Success: cost: " OTTD_PRINTF64, (int64) this->GetCost());
return stdstr_fmt("Success: cost: " OTTD_PRINTF64, (int64) this->GetCost());
} else {
const uint textref_stack_size = this->GetTextRefStackSize();
if (textref_stack_size > 0) StartTextRefStackUsage(this->GetTextRefStackGRF(), textref_stack_size, this->GetTextRefStack());
char *b = buf;
b += seprintf(b, last, "Failed: cost: " OTTD_PRINTF64, (int64) this->GetCost());
std::string buf = stdstr_fmt("Failed: cost: " OTTD_PRINTF64, (int64) this->GetCost());
if (cmd_msg != 0) {
b += seprintf(b, last, " ");
b = GetString(b, cmd_msg, last);
buf += ' ';
GetString(StringBuilder(buf), cmd_msg);
}
if (this->message != INVALID_STRING_ID) {
b += seprintf(b, last, " ");
b = GetString(b, this->message, last);
buf += ' ';
GetString(StringBuilder(buf), this->message);
}
if (textref_stack_size > 0) StopTextRefStackUsage();
return b - buf;
return buf;
}
}