mirror of
https://github.com/RGBCube/serenity
synced 2025-05-21 21:15:07 +00:00
AK: Make serialize_ipv6_address take a StringBuilder
This will allow us to implement 'concept-host-serializer' without needing to call String::formatted.
This commit is contained in:
parent
a1ae701a7d
commit
803ca8cc80
1 changed files with 4 additions and 7 deletions
|
@ -227,10 +227,9 @@ static ErrorOr<String> serialize_ipv4_address(URL::IPv4Address address)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#concept-ipv6-serializer
|
// https://url.spec.whatwg.org/#concept-ipv6-serializer
|
||||||
static ErrorOr<String> 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.
|
// 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.
|
// 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.
|
// 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<String> serialize_ipv6_address(URL::IPv6Address const& address)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. Return output.
|
// 6. Return output.
|
||||||
return output.to_string();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#concept-ipv6-parser
|
// https://url.spec.whatwg.org/#concept-ipv6-parser
|
||||||
|
@ -566,10 +564,9 @@ static Optional<DeprecatedString> parse_host(StringView input, bool is_not_speci
|
||||||
if (!address.has_value())
|
if (!address.has_value())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto result = serialize_ipv6_address(*address);
|
StringBuilder output;
|
||||||
if (result.is_error())
|
serialize_ipv6_address(*address, output);
|
||||||
return {};
|
return output.to_deprecated_string();
|
||||||
return result.release_value().to_deprecated_string();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. If isNotSpecial is true, then return the result of opaque-host parsing input.
|
// 2. If isNotSpecial is true, then return the result of opaque-host parsing input.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue