1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-17 01:12:39 +01:00

Codechange: Change internal format of encoded strings to improve robustness and allow expansion. (#13499)

This commit is contained in:
Peter Nelson
2025-02-09 12:45:50 +00:00
committed by GitHub
parent 1193852007
commit dccc6185b9
7 changed files with 241 additions and 94 deletions

View File

@@ -197,16 +197,26 @@ void ScriptText::ParamCheck::Encode(std::back_insert_iterator<std::string> &outp
struct visitor {
std::back_insert_iterator<std::string> &output;
void operator()(const std::string &value) { fmt::format_to(this->output, ":\"{}\"", value); }
void operator()(const SQInteger &value) { fmt::format_to(this->output, ":{:X}", value); }
void operator()(const std::string &value)
{
Utf8Encode(this->output, SCC_ENCODED_STRING);
fmt::format_to(this->output, "{}", value);
}
void operator()(const SQInteger &value)
{
Utf8Encode(this->output, SCC_ENCODED_NUMERIC);
fmt::format_to(this->output, "{:X}", value);
}
void operator()(const ScriptTextRef &value)
{
fmt::format_to(this->output, ":");
Utf8Encode(this->output, SCC_ENCODED);
fmt::format_to(this->output, "{:X}", value->string);
}
};
*output = SCC_RECORD_SEPARATOR;
std::visit(visitor{output}, *this->param);
this->used = true;
}