diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 93ccff34b3..5d15b0e79e 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -1504,17 +1504,15 @@ static bool ConStartAI([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *arg * try again with the assumption everything right of the dot is * the version the user wants to load. */ if (!config->HasScript()) { - const char *e = strrchr(argv[1], '.'); - if (e != nullptr) { - size_t name_length = e - argv[1]; - e++; - - auto version = ParseInteger(e); + StringConsumer consumer{std::string_view{argv[1]}}; + auto name = consumer.ReadUntilChar('.', StringConsumer::SKIP_ONE_SEPARATOR); + if (consumer.AnyBytesLeft()) { + auto version = consumer.TryReadIntegerBase(10); if (!version.has_value()) { IConsolePrint(CC_ERROR, "The version is not a valid number."); return true; } - config->Change(std::string(argv[1], name_length), *version, true); + config->Change(name, *version, true); } } diff --git a/src/script/script_config.cpp b/src/script/script_config.cpp index c5d8d136c8..e2acf7117d 100644 --- a/src/script/script_config.cpp +++ b/src/script/script_config.cpp @@ -20,10 +20,10 @@ #include "../safeguards.h" -void ScriptConfig::Change(std::optional name, int version, bool force_exact_match) +void ScriptConfig::Change(std::optional name, int version, bool force_exact_match) { if (name.has_value()) { - this->name = std::move(name.value()); + this->name = name.value(); this->info = this->FindInfo(this->name, version, force_exact_match); } else { this->info = nullptr; @@ -140,7 +140,7 @@ int ScriptConfig::GetVersion() const return this->version; } -void ScriptConfig::StringToSettings(const std::string &value) +void ScriptConfig::StringToSettings(std::string_view value) { std::string_view to_process = value; for (;;) { diff --git a/src/script/script_config.hpp b/src/script/script_config.hpp index 7368d0001b..448149052b 100644 --- a/src/script/script_config.hpp +++ b/src/script/script_config.hpp @@ -78,7 +78,7 @@ public: * @param force_exact_match If true try to find the exact same version * as specified. If false any compatible version is ok. */ - void Change(std::optional name, int version = -1, bool force_exact_match = false); + void Change(std::optional name, int version = -1, bool force_exact_match = false); /** * Get the ScriptInfo linked to this ScriptConfig. @@ -154,7 +154,7 @@ public: * Convert a string which is stored in the config file or savegames to * custom settings of this Script. */ - void StringToSettings(const std::string &value); + void StringToSettings(std::string_view value); /** * Convert the custom settings to a string that can be stored in the config