url icon indicating copy to clipboard operation
url copied to clipboard

parse_unicode_url function

Open alandefreitas opened this issue 1 year ago • 1 comments
trafficstars

We should have a function to handle unicode urls:

result<url> parse_unicode_url(...)

To convert to a valid URL, the host would be converted with punycode, and other components would percent-escape when possible. Errors are still possible.

We can identify components by identifying possible delimiters (like urls::format does) or we can provide functions that create a URL from its components:

result<url>
make_url(
  string_view scheme,
  utf8_string_view authority,
  utf8_string_view path,
  utf8_string_view query,
  utf8_string_view fragment)
{
    url u;
    u.reserve(...);
    u.set_scheme(scheme);
    u.set_authority(authority);
    u.set_path(path);
    // ...
}

result<url>
make_iri(
  string_view scheme,
  utf8_string_view authority,
  utf8_string_view path,
  utf8_string_view query,
  utf8_string_view fragment)
{
    url u;
    u.reserve(...);
    u.set_scheme(scheme);
    u.set_authority(detail::parse_punycode(authority));
    u.set_path(detail::pct_encode(path));
    // ...
}

alandefreitas avatar Nov 11 '24 18:11 alandefreitas