mirror of
https://github.com/RGBCube/serenity
synced 2025-07-07 08:07:35 +00:00
AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature: - int StringType::to_int(bool& ok) const And replace it with sensible new signature: - Optional<int> StringType::to_int() const
This commit is contained in:
parent
15f4043a7a
commit
fdfda6dec2
55 changed files with 354 additions and 455 deletions
|
@ -280,9 +280,9 @@ void ArgsParser::add_option(int& value, const char* help_string, const char* lon
|
|||
short_name,
|
||||
value_name,
|
||||
[&value](const char* s) {
|
||||
bool ok;
|
||||
value = StringView(s).to_int(ok);
|
||||
return ok;
|
||||
auto opt = StringView(s).to_int();
|
||||
value = opt.value_or(0);
|
||||
return opt.has_value();
|
||||
}
|
||||
};
|
||||
add_option(move(option));
|
||||
|
@ -316,9 +316,9 @@ void ArgsParser::add_positional_argument(int& value, const char* help_string, co
|
|||
required == Required::Yes ? 1 : 0,
|
||||
1,
|
||||
[&value](const char* s) {
|
||||
bool ok;
|
||||
value = StringView(s).to_int(ok);
|
||||
return ok;
|
||||
auto opt = StringView(s).to_int();
|
||||
value = opt.value_or(0);
|
||||
return opt.has_value();
|
||||
}
|
||||
};
|
||||
add_positional_argument(move(arg));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue