From 6457eca67cd049af3593020d03cb580b40fbff06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sun, 28 Sep 2025 23:09:11 +0300 Subject: [PATCH] Use the parse functions, adjust code to account for the split change --- src/openrct2-ui/input/ShortcutInput.cpp | 4 ++-- src/openrct2-ui/windows/CustomCurrency.cpp | 2 +- src/openrct2-ui/windows/LandRights.cpp | 2 +- src/openrct2-ui/windows/LoadSave.cpp | 2 +- src/openrct2-ui/windows/PatrolArea.cpp | 2 +- src/openrct2-ui/windows/SceneryScatter.cpp | 2 +- src/openrct2/command_line/UriHandler.cpp | 14 +++++++------- src/openrct2/object/Object.cpp | 2 +- src/openrct2/object/ResourceTable.cpp | 6 +++--- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/openrct2-ui/input/ShortcutInput.cpp b/src/openrct2-ui/input/ShortcutInput.cpp index a564debda1..9f8b546708 100644 --- a/src/openrct2-ui/input/ShortcutInput.cpp +++ b/src/openrct2-ui/input/ShortcutInput.cpp @@ -149,7 +149,7 @@ ShortcutInput::ShortcutInput(std::string_view value) } else { - auto number = String::parse(rem); + auto number = String::tryParse(rem); if (number.has_value()) { Kind = InputDeviceKind::JoyButton; @@ -161,7 +161,7 @@ ShortcutInput::ShortcutInput(std::string_view value) else if (String::startsWith(rem, "MOUSE ", true)) { rem = rem.substr(6); - auto number = String::parse(rem); + auto number = String::tryParse(rem); if (number) { Kind = InputDeviceKind::Mouse; diff --git a/src/openrct2-ui/windows/CustomCurrency.cpp b/src/openrct2-ui/windows/CustomCurrency.cpp index c29c2f4a9d..9f98a32ab5 100644 --- a/src/openrct2-ui/windows/CustomCurrency.cpp +++ b/src/openrct2-ui/windows/CustomCurrency.cpp @@ -174,7 +174,7 @@ namespace OpenRCT2::Ui::Windows break; case WIDX_RATE: - const auto res = String::parse(text); + const auto res = String::tryParse(text); if (res.has_value()) { int32_t rate = res.value(); diff --git a/src/openrct2-ui/windows/LandRights.cpp b/src/openrct2-ui/windows/LandRights.cpp index 93f1124015..8143e872d4 100644 --- a/src/openrct2-ui/windows/LandRights.cpp +++ b/src/openrct2-ui/windows/LandRights.cpp @@ -236,7 +236,7 @@ namespace OpenRCT2::Ui::Windows if (widgetIndex != WIDX_PREVIEW) return; - const auto res = String::parse(text); + const auto res = String::tryParse(text); if (res.has_value()) { uint16_t size; diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index 79b0c3ce79..d5df1fcd0e 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -241,7 +241,7 @@ namespace OpenRCT2::Ui::Windows // List all files with the wanted extensions bool showExtension = false; - for (const u8string& extToken : String::split(extensionPattern, ";")) + for (const u8string_view extToken : String::split(extensionPattern, ";")) { const u8string filter = Path::Combine(directory, extToken); auto scanner = Path::ScanDirectory(filter, false); diff --git a/src/openrct2-ui/windows/PatrolArea.cpp b/src/openrct2-ui/windows/PatrolArea.cpp index ad3dd50a36..c27ca7d179 100644 --- a/src/openrct2-ui/windows/PatrolArea.cpp +++ b/src/openrct2-ui/windows/PatrolArea.cpp @@ -109,7 +109,7 @@ namespace OpenRCT2::Ui::Windows if (widgetIndex != WIDX_PREVIEW) return; - const auto res = String::parse(text); + const auto res = String::tryParse(text); if (res.has_value()) { int32_t size; diff --git a/src/openrct2-ui/windows/SceneryScatter.cpp b/src/openrct2-ui/windows/SceneryScatter.cpp index b021683e98..58b28e9282 100644 --- a/src/openrct2-ui/windows/SceneryScatter.cpp +++ b/src/openrct2-ui/windows/SceneryScatter.cpp @@ -141,7 +141,7 @@ namespace OpenRCT2::Ui::Windows if (widgetIndex != WIDX_PREVIEW || text.empty()) return; - const auto res = String::parse(text); + const auto res = String::tryParse(text); if (res.has_value()) { diff --git a/src/openrct2/command_line/UriHandler.cpp b/src/openrct2/command_line/UriHandler.cpp index 76809d5fab..3e2443b7d6 100644 --- a/src/openrct2/command_line/UriHandler.cpp +++ b/src/openrct2/command_line/UriHandler.cpp @@ -18,9 +18,9 @@ namespace OpenRCT2 static exitcode_t HandleUri(const std::string& uri); #ifndef DISABLE_NETWORK - static exitcode_t HandleUriJoin(const std::vector& args); + static exitcode_t HandleUriJoin(const std::vector& args); static bool TryParseHostnamePort( - const std::string& hostnamePort, std::string* outHostname, int32_t* outPort, int32_t defaultPort); + const std::string_view hostnamePort, std::string* outHostname, int32_t* outPort, int32_t defaultPort); #endif exitcode_t CommandLine::HandleCommandUri(CommandLineArgEnumerator* enumerator) @@ -46,7 +46,7 @@ namespace OpenRCT2 if (!args.empty()) { #ifndef DISABLE_NETWORK - std::string arg = args[0]; + const auto arg = args[0]; if (arg == "join") { result = HandleUriJoin(args); @@ -58,7 +58,7 @@ namespace OpenRCT2 #ifndef DISABLE_NETWORK - static exitcode_t HandleUriJoin(const std::vector& args) + static exitcode_t HandleUriJoin(const std::vector& args) { std::string hostname; int32_t port; @@ -76,18 +76,18 @@ namespace OpenRCT2 } static bool TryParseHostnamePort( - const std::string& hostnamePort, std::string* outHostname, int32_t* outPort, int32_t defaultPort) + const std::string_view hostnamePort, std::string* outHostname, int32_t* outPort, int32_t defaultPort) { try { // Argument is in hostname:port format, so we need to split - std::string hostname = hostnamePort; + std::string hostname{ hostnamePort }; int32_t port = defaultPort; size_t colonIndex = hostnamePort.find_first_of(':'); if (colonIndex != std::string::npos) { hostname = hostnamePort.substr(0, colonIndex); - port = std::stoi(hostnamePort.substr(colonIndex + 1)); + port = String::parse(hostnamePort.substr(colonIndex + 1)); } *outPort = port; *outHostname = std::move(hostname); diff --git a/src/openrct2/object/Object.cpp b/src/openrct2/object/Object.cpp index b4cac59e9b..e007f81044 100644 --- a/src/openrct2/object/Object.cpp +++ b/src/openrct2/object/Object.cpp @@ -433,7 +433,7 @@ namespace OpenRCT2 size_t highestIndex = std::min(nums.size(), VersionNumFields); for (size_t i = 0; i < highestIndex; i++) { - auto value = stoll(nums.at(i)); + auto value = String::parse(nums.at(i)); constexpr auto maxValue = std::numeric_limits().max(); if (value > maxValue) { diff --git a/src/openrct2/object/ResourceTable.cpp b/src/openrct2/object/ResourceTable.cpp index 3e09dc7d3c..7ca4ba2ebd 100644 --- a/src/openrct2/object/ResourceTable.cpp +++ b/src/openrct2/object/ResourceTable.cpp @@ -26,12 +26,12 @@ namespace OpenRCT2 auto parts = String::split(s, ".."); if (parts.size() == 1) { - result = Range(std::stoi(parts[0])); + result = Range(String::parse(parts[0])); } else { - auto left = std::stoi(parts[0]); - auto right = std::stoi(parts[1]); + auto left = String::parse(parts[0]); + auto right = String::parse(parts[1]); if (left <= right) { result = Range(left, right);