1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Use the parse functions, adjust code to account for the split change

This commit is contained in:
ζeh Matt
2025-09-28 23:09:11 +03:00
parent 9eeaf9a001
commit 6457eca67c
9 changed files with 18 additions and 18 deletions

View File

@@ -149,7 +149,7 @@ ShortcutInput::ShortcutInput(std::string_view value)
}
else
{
auto number = String::parse<int32_t>(rem);
auto number = String::tryParse<int32_t>(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<int32_t>(rem);
auto number = String::tryParse<int32_t>(rem);
if (number)
{
Kind = InputDeviceKind::Mouse;

View File

@@ -174,7 +174,7 @@ namespace OpenRCT2::Ui::Windows
break;
case WIDX_RATE:
const auto res = String::parse<int32_t>(text);
const auto res = String::tryParse<int32_t>(text);
if (res.has_value())
{
int32_t rate = res.value();

View File

@@ -236,7 +236,7 @@ namespace OpenRCT2::Ui::Windows
if (widgetIndex != WIDX_PREVIEW)
return;
const auto res = String::parse<int32_t>(text);
const auto res = String::tryParse<int32_t>(text);
if (res.has_value())
{
uint16_t size;

View File

@@ -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);

View File

@@ -109,7 +109,7 @@ namespace OpenRCT2::Ui::Windows
if (widgetIndex != WIDX_PREVIEW)
return;
const auto res = String::parse<int32_t>(text);
const auto res = String::tryParse<int32_t>(text);
if (res.has_value())
{
int32_t size;

View File

@@ -141,7 +141,7 @@ namespace OpenRCT2::Ui::Windows
if (widgetIndex != WIDX_PREVIEW || text.empty())
return;
const auto res = String::parse<int32_t>(text);
const auto res = String::tryParse<int32_t>(text);
if (res.has_value())
{

View File

@@ -18,9 +18,9 @@ namespace OpenRCT2
static exitcode_t HandleUri(const std::string& uri);
#ifndef DISABLE_NETWORK
static exitcode_t HandleUriJoin(const std::vector<std::string>& args);
static exitcode_t HandleUriJoin(const std::vector<std::string_view>& 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<std::string>& args)
static exitcode_t HandleUriJoin(const std::vector<std::string_view>& 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<int32_t>(hostnamePort.substr(colonIndex + 1));
}
*outPort = port;
*outHostname = std::move(hostname);

View File

@@ -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<int64_t>(nums.at(i));
constexpr auto maxValue = std::numeric_limits<uint16_t>().max();
if (value > maxValue)
{

View File

@@ -26,12 +26,12 @@ namespace OpenRCT2
auto parts = String::split(s, "..");
if (parts.size() == 1)
{
result = Range<int32_t>(std::stoi(parts[0]));
result = Range<int32_t>(String::parse<int32_t>(parts[0]));
}
else
{
auto left = std::stoi(parts[0]);
auto right = std::stoi(parts[1]);
auto left = String::parse<int32_t>(parts[0]);
auto right = String::parse<int32_t>(parts[1]);
if (left <= right)
{
result = Range<int32_t>(left, right);