mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use StringBuilder to create the gender-scan-string.
parent
dd073eb38d
commit
1d879f3043
|
@ -1165,20 +1165,21 @@ static void FormatString(StringBuilder &builder, std::string_view str_arg, Strin
|
||||||
/* Now we need to figure out what text to resolve, i.e.
|
/* Now we need to figure out what text to resolve, i.e.
|
||||||
* what do we need to draw? So get the actual raw string
|
* what do we need to draw? So get the actual raw string
|
||||||
* first using the control code to get said string. */
|
* first using the control code to get said string. */
|
||||||
char input[4 + 1];
|
std::string input;
|
||||||
char *p = input + Utf8Encode(input, args.GetTypeAtOffset(offset));
|
{
|
||||||
*p = '\0';
|
StringBuilder tmp_builder(input);
|
||||||
|
tmp_builder.PutUtf8(args.GetTypeAtOffset(offset));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string buffer;
|
||||||
|
{
|
||||||
|
AutoRestoreBackup sgd_backup(_scan_for_gender_data, true);
|
||||||
|
StringBuilder tmp_builder(buffer);
|
||||||
|
StringParameters tmp_params = args.GetRemainingParameters(offset);
|
||||||
|
FormatString(tmp_builder, input, tmp_params);
|
||||||
|
}
|
||||||
|
|
||||||
/* The gender is stored at the start of the formatted string. */
|
/* The gender is stored at the start of the formatted string. */
|
||||||
bool old_sgd = _scan_for_gender_data;
|
|
||||||
_scan_for_gender_data = true;
|
|
||||||
std::string buffer;
|
|
||||||
StringBuilder tmp_builder(buffer);
|
|
||||||
StringParameters tmp_params = args.GetRemainingParameters(offset);
|
|
||||||
FormatString(tmp_builder, input, tmp_params);
|
|
||||||
_scan_for_gender_data = old_sgd;
|
|
||||||
|
|
||||||
/* And determine the string. */
|
|
||||||
const char *s = buffer.c_str();
|
const char *s = buffer.c_str();
|
||||||
char32_t c = Utf8Consume(&s);
|
char32_t c = Utf8Consume(&s);
|
||||||
/* Does this string have a gender, if so, set it */
|
/* Does this string have a gender, if so, set it */
|
||||||
|
|
Loading…
Reference in New Issue