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 /AK/IPv4Address.h | |
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 'AK/IPv4Address.h')
-rw-r--r-- | AK/IPv4Address.h | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/AK/IPv4Address.h b/AK/IPv4Address.h index aee493035f..810c9013a4 100644 --- a/AK/IPv4Address.h +++ b/AK/IPv4Address.h @@ -78,18 +78,11 @@ public: auto parts = string.split_view('.'); if (parts.size() != 4) return {}; - bool ok; - auto a = parts[0].to_uint(ok); - if (!ok || a > 255) - return {}; - auto b = parts[1].to_uint(ok); - if (!ok || b > 255) - return {}; - auto c = parts[2].to_uint(ok); - if (!ok || c > 255) - return {}; - auto d = parts[3].to_uint(ok); - if (!ok || d > 255) + auto a = parts[0].to_uint().value_or(256); + auto b = parts[1].to_uint().value_or(256); + auto c = parts[2].to_uint().value_or(256); + auto d = parts[3].to_uint().value_or(256); + if (a > 255 || b > 255 || c > 255 || d > 255) return {}; return IPv4Address((u8)a, (u8)b, (u8)c, (u8)d); } |