mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-18 01:42:38 +01:00
Codechange: Use std::string and std::string_view instead of C strings.
This commit is contained in:
@@ -193,9 +193,9 @@ void ScriptText::_FillParamList(ParamList ¶ms, 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));
|
||||
}
|
||||
|
||||
@@ -137,11 +137,11 @@ private:
|
||||
int idx;
|
||||
Param *param;
|
||||
bool used = false;
|
||||
const char *cmd = nullptr;
|
||||
std::string_view cmd;
|
||||
|
||||
ParamCheck(StringIndexInTab owner, int idx, Param *param) : owner(owner), idx(idx), param(param) {}
|
||||
|
||||
void Encode(std::back_insert_iterator<std::string> &output, const char *cmd);
|
||||
void Encode(std::back_insert_iterator<std::string> &output, std::string_view cmd);
|
||||
};
|
||||
|
||||
using ParamList = std::vector<ParamCheck>;
|
||||
|
||||
Reference in New Issue
Block a user