1
0
Fork 0

Codechange: use std::string_view for GetNextParameterString

pull/14115/head
Rubidium 2025-04-26 11:22:09 +02:00 committed by rubidium42
parent 398524e49a
commit 4476ce804d
2 changed files with 6 additions and 13 deletions

View File

@ -1238,16 +1238,9 @@ static void FormatString(StringBuilder &builder, std::string_view str_arg, Strin
builder += _openttd_revision;
break;
case SCC_RAW_STRING_POINTER: { // {RAW_STRING}
const char *raw_string = args.GetNextParameterString();
/* raw_string can be nullptr. */
if (raw_string == nullptr) {
builder += "(invalid RAW_STRING parameter)";
break;
}
FormatString(builder, raw_string, args);
case SCC_RAW_STRING_POINTER: // {RAW_STRING}
FormatString(builder, args.GetNextParameterString(), args);
break;
}
case SCC_STRING: {// {STRING}
StringID string_id = args.GetNextParameter<StringID>();

View File

@ -112,12 +112,12 @@ public:
* will be read.
* @return The next parameter's value.
*/
const char *GetNextParameterString()
std::string_view GetNextParameterString()
{
struct visitor {
const char *operator()(const std::monostate &) { throw std::out_of_range("Attempt to read uninitialised parameter as string"); }
const char *operator()(const uint64_t &) { throw std::out_of_range("Attempt to read integer parameter as string"); }
const char *operator()(const std::string &arg) { return arg.c_str(); }
std::string_view operator()(const std::monostate &) { throw std::out_of_range("Attempt to read uninitialised parameter as string"); }
std::string_view operator()(const uint64_t &) { throw std::out_of_range("Attempt to read integer parameter as string"); }
std::string_view operator()(const std::string &arg) { return arg; }
};
const auto &param = this->GetNextParameterReference();