// https://www.boost.org/doc/libs/1_92_0/libs/url/doc/html/url/quicklook.html

#include <boost/url.hpp>

#include <cassert>
#include <iostream>

int main()
{
    const boost::core::string_view text =
        "https://user:pass@www.debian.org:8080/path/to/file.txt?id=42&name=boost#frag";

    boost::urls::url_view u = boost::urls::parse_uri(text).value();

    std::cout << "scheme   = " << u.scheme() << std::endl;
    std::cout << "host     = " << u.host() << std::endl;
    std::cout << "port     = " << u.port() << std::endl;
    std::cout << "path     = " << u.path() << std::endl;
    std::cout << "query    = " << u.query() << std::endl;
    std::cout << "fragment = " << u.fragment() << std::endl;

    assert(u.scheme() == "https");
    assert(u.host() == "www.debian.org");
    assert(u.port() == "8080");
    assert(u.path() == "/path/to/file.txt");
    assert(u.fragment() == "frag");

    // Query parameters are decoded on access
    boost::urls::params_view params = u.params();
    assert(params.size() == 2);
    assert((*params.find("id")).value == "42");
    assert((*params.find("name")).value == "boost");

    // A malformed URL must be rejected rather than silently accepted
    assert(boost::urls::parse_uri("not a url").has_error());

    return 0;
}
