1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-16 17:02:37 +01:00

Codechange: Use std::string and std::string_view instead of C strings.

This commit is contained in:
frosch
2025-03-24 19:30:00 +01:00
committed by frosch
parent d7768f5f51
commit 488cda728d
9 changed files with 95 additions and 107 deletions

View File

@@ -193,9 +193,9 @@ void ScriptText::_FillParamList(ParamList &params, ScriptTextList &seen_texts)
}
}
void ScriptText::ParamCheck::Encode(std::back_insert_iterator<std::string> &output, const char *cmd)
void ScriptText::ParamCheck::Encode(std::back_insert_iterator<std::string> &output, std::string_view cmd)
{
if (this->cmd == nullptr) this->cmd = cmd;
if (this->cmd.empty()) this->cmd = cmd;
if (this->used) return;
struct visitor {
@@ -286,7 +286,7 @@ void ScriptText::_GetEncodedText(std::back_insert_iterator<std::string> &output,
default:
for (int i = 0; i < cur_param.consumes; i++) {
ParamCheck &p = *get_next_arg();
p.Encode(output, i == 0 ? cur_param.cmd : nullptr);
p.Encode(output, i == 0 ? cur_param.cmd : "");
if (i == 0 && p.cmd != cur_param.cmd) throw 1;
if (!std::holds_alternative<SQInteger>(*p.param)) ScriptLog::Error(fmt::format("{}({}): {{{}}} expects an integer", name, param_count + i + 1, cur_param.cmd));
}