diff --git a/src/strings.cpp b/src/strings.cpp index 87c2b3e76a..de391cdb27 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -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(); diff --git a/src/strings_internal.h b/src/strings_internal.h index c15a09a0c3..bd5dcc987a 100644 --- a/src/strings_internal.h +++ b/src/strings_internal.h @@ -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 ¶m = this->GetNextParameterReference();