From 803ca8cc806e19c93a5eb8e18b9342fd52dc078d Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Wed, 26 Jul 2023 21:04:15 +1200 Subject: [PATCH] AK: Make serialize_ipv6_address take a StringBuilder This will allow us to implement 'concept-host-serializer' without needing to call String::formatted. --- AK/URLParser.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/AK/URLParser.cpp b/AK/URLParser.cpp index 7570d714f0..8105a65a72 100644 --- a/AK/URLParser.cpp +++ b/AK/URLParser.cpp @@ -227,10 +227,9 @@ static ErrorOr serialize_ipv4_address(URL::IPv4Address address) } // https://url.spec.whatwg.org/#concept-ipv6-serializer -static ErrorOr serialize_ipv6_address(URL::IPv6Address const& address) +static void serialize_ipv6_address(URL::IPv6Address const& address, StringBuilder& output) { // 1. Let output be the empty string. - StringBuilder output; // 2. Let compress be an index to the first IPv6 piece in the first longest sequences of address’s IPv6 pieces that are 0. // 3. If there is no sequence of address’s IPv6 pieces that are 0 that is longer than 1, then set compress to null. @@ -286,7 +285,6 @@ static ErrorOr serialize_ipv6_address(URL::IPv6Address const& address) } // 6. Return output. - return output.to_string(); } // https://url.spec.whatwg.org/#concept-ipv6-parser @@ -566,10 +564,9 @@ static Optional parse_host(StringView input, bool is_not_speci if (!address.has_value()) return {}; - auto result = serialize_ipv6_address(*address); - if (result.is_error()) - return {}; - return result.release_value().to_deprecated_string(); + StringBuilder output; + serialize_ipv6_address(*address, output); + return output.to_deprecated_string(); } // 2. If isNotSpecial is true, then return the result of opaque-host parsing input.