mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:47: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
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue