diff options
author | Andreas Kling <kling@serenityos.org> | 2020-06-12 21:07:52 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-12 21:28:55 +0200 |
commit | fdfda6dec20101013bb33633e657f06ef2a1ea96 (patch) | |
tree | 2157f8281cd9bc33a6984455c4831c397d2bd30c /DevTools | |
parent | 15f4043a7a80f52c0fa05c4e69771e758464cd20 (diff) | |
download | serenity-fdfda6dec20101013bb33633e657f06ef2a1ea96.zip |
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
Diffstat (limited to 'DevTools')
-rw-r--r-- | DevTools/HackStudio/Debugger/VariablesModel.cpp | 7 | ||||
-rw-r--r-- | DevTools/IPCCompiler/main.cpp | 4 | ||||
-rw-r--r-- | DevTools/Inspector/main.cpp | 7 |
3 files changed, 9 insertions, 9 deletions
diff --git a/DevTools/HackStudio/Debugger/VariablesModel.cpp b/DevTools/HackStudio/Debugger/VariablesModel.cpp index b5351724f5..83aadc8c22 100644 --- a/DevTools/HackStudio/Debugger/VariablesModel.cpp +++ b/DevTools/HackStudio/Debugger/VariablesModel.cpp @@ -124,9 +124,10 @@ static Optional<u32> string_to_variable_value(const StringView& string_value, co } if (variable.type_name == "int") { - bool success = false; - auto value = string_value.to_int(success); - return success ? value : Optional<u32>(); + auto value = string_value.to_int(); + if (value.has_value()) + return value.value(); + return {}; } if (variable.type_name == "bool") { diff --git a/DevTools/IPCCompiler/main.cpp b/DevTools/IPCCompiler/main.cpp index 053e3a9611..1f2c353a13 100644 --- a/DevTools/IPCCompiler/main.cpp +++ b/DevTools/IPCCompiler/main.cpp @@ -227,9 +227,7 @@ int main(int argc, char** argv) consume_specific('='); consume_whitespace(); auto magic_string = extract_while([](char ch) { return !isspace(ch) && ch != '{'; }); - bool ok; - endpoints.last().magic = magic_string.to_int(ok); - ASSERT(ok); + endpoints.last().magic = magic_string.to_int().value(); consume_whitespace(); consume_specific('{'); parse_messages(); diff --git a/DevTools/Inspector/main.cpp b/DevTools/Inspector/main.cpp index 38fe69f016..49cea918d9 100644 --- a/DevTools/Inspector/main.cpp +++ b/DevTools/Inspector/main.cpp @@ -65,11 +65,12 @@ int main(int argc, char** argv) if (argc != 2) print_usage_and_exit(); - bool ok; - pid_t pid = String(argv[1]).to_int(ok); - if (!ok) + auto pid_opt = String(argv[1]).to_int(); + if (!pid_opt.has_value()) print_usage_and_exit(); + pid_t pid = pid_opt.value(); + GUI::Application app(argc, argv); auto window = GUI::Window::construct(); |