mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:37: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));
|
||||
|
|
|
@ -129,11 +129,7 @@ int ConfigFile::read_num_entry(const String& group, const String& key, int defau
|
|||
return default_value;
|
||||
}
|
||||
|
||||
bool ok;
|
||||
int value = read_entry(group, key).to_int(ok);
|
||||
if (!ok)
|
||||
return default_value;
|
||||
return value;
|
||||
return read_entry(group, key).to_int().value_or(default_value);
|
||||
}
|
||||
|
||||
bool ConfigFile::read_bool_entry(const String& group, const String& key, bool default_value) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue