diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 41ae10203b..54b8e7aa8c 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -1190,15 +1190,13 @@ static bool ConExec(std::span argv) _script_current_depth++; uint script_depth = _script_current_depth; - char cmdline[ICON_CMDLN_SIZE]; - while (fgets(cmdline, sizeof(cmdline), *script_file) != nullptr) { + char buffer[ICON_CMDLN_SIZE]; + while (fgets(buffer, sizeof(buffer), *script_file) != nullptr) { /* Remove newline characters from the executing script */ - for (char *cmdptr = cmdline; *cmdptr != '\0'; cmdptr++) { - if (*cmdptr == '\n' || *cmdptr == '\r') { - *cmdptr = '\0'; - break; - } - } + std::string_view cmdline{buffer}; + auto last_non_newline = cmdline.find_last_not_of("\r\n"); + if (last_non_newline != std::string_view::npos) cmdline = cmdline.substr(0, last_non_newline + 1); + IConsoleCmdExec(cmdline); /* Ensure that we are still on the same depth or that we returned via 'return'. */ assert(_script_current_depth == script_depth || _script_current_depth == script_depth - 1); diff --git a/src/openttd.cpp b/src/openttd.cpp index b2f2064bfb..ab0f807153 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -271,9 +271,9 @@ static void WriteSavegameInfo(const std::string &name) * @param res variable to store the resolution in. * @param s the string to decompose. */ -static void ParseResolution(Dimension *res, const char *s) +static void ParseResolution(Dimension &res, std::string_view s) { - StringConsumer consumer(std::string_view{s}); + StringConsumer consumer(s); auto width = consumer.TryReadIntegerBase(10); auto valid = consumer.ReadIf("x"); auto height = consumer.TryReadIntegerBase(10); @@ -282,8 +282,8 @@ static void ParseResolution(Dimension *res, const char *s) return; } - res->width = std::max(*width, 64); - res->height = std::max(*height, 64); + res.width = std::max(*width, 64); + res.height = std::max(*height, 64); } @@ -552,7 +552,7 @@ int openttd_main(std::span arguments) case 'p': scanner->join_server_password = mgo.opt; break; - case 'r': ParseResolution(&resolution, mgo.opt); break; + case 'r': ParseResolution(resolution, mgo.opt); break; case 't': if (auto value = ParseInteger(mgo.opt); value.has_value()) { scanner->startyear = TimerGameCalendar::Year(*value); diff --git a/src/spritecache.cpp b/src/spritecache.cpp index a4eeb809ac..08b904214f 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -904,7 +904,7 @@ void *UniquePtrSpriteAllocator::AllocatePtr(size_t size) */ static void *HandleInvalidSpriteRequest(SpriteID sprite, SpriteType requested, SpriteCache *sc, SpriteAllocator *allocator) { - static const char * const sprite_types[] = { + static const std::string_view sprite_types[] = { "normal", // SpriteType::Normal "map generator", // SpriteType::MapGen "character", // SpriteType::Font diff --git a/src/station_gui.cpp b/src/station_gui.cpp index d6ed301352..971443aff4 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -1835,7 +1835,7 @@ struct StationViewWindow : public Window { DrawString(text.left, text.right, y, GetString(str, cargo, cd.GetCount(), station)); if (column < NUM_COLUMNS - 1) { - const char *sym = nullptr; + std::string_view sym; if (cd.GetNumChildren() > 0) { sym = "-"; } else if (auto_distributed && str != STR_STATION_VIEW_RESERVED) { @@ -1850,7 +1850,7 @@ struct StationViewWindow : public Window { } } } - if (sym != nullptr) DrawString(shrink.left, shrink.right, y, sym, TC_YELLOW); + if (!sym.empty()) DrawString(shrink.left, shrink.right, y, sym, TC_YELLOW); } this->SetDisplayedRow(cd); } diff --git a/src/table/strgen_tables.h b/src/table/strgen_tables.h index 2791e1982a..931bcad17e 100644 --- a/src/table/strgen_tables.h +++ b/src/table/strgen_tables.h @@ -160,8 +160,8 @@ static const CmdStruct _cmd_structs[] = { /** Description of a plural form */ struct PluralForm { size_t plural_count; ///< The number of plural forms - const char *description; ///< Human readable description of the form - const char *names; ///< Plural names + std::string_view description; ///< Human readable description of the form + std::string_view names; ///< Plural names }; /** The maximum number of plurals. */ @@ -199,7 +199,7 @@ static const PluralForm _plural_forms[] = { * a = array, i.e. list of strings */ /** All pragmas used */ -static const char * const _pragmas[][4] = { +static const std::string_view _pragmas[][4] = { /* name flags default description */ { "name", "0", "", "English name for the language" }, { "ownname", "t", "", "Localised name for the language" },