From bffa0e9c2eaa4e88c12deaed55f8bcf4ded818b0 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 13 Sep 2021 19:28:59 -0700 Subject: [PATCH] doc work --- doc/qbk/quickref.xml | 107 +++++++++++-------- include/boost/url.hpp | 5 +- include/boost/url/bnf/char_set.hpp | 4 +- include/boost/url/error.hpp | 12 +-- include/boost/url/impl/ipv4_address.ipp | 9 +- include/boost/url/impl/ipv6_address.ipp | 9 +- include/boost/url/impl/path_view.ipp | 14 +++ include/boost/url/impl/query_params_view.ipp | 14 +++ include/boost/url/impl/url.ipp | 63 ++++++----- include/boost/url/ipv4_address.hpp | 17 +-- include/boost/url/ipv6_address.hpp | 17 ++- include/boost/url/path_view.hpp | 19 ++++ include/boost/url/query_params_view.hpp | 19 ++++ include/boost/url/scheme.hpp | 17 +-- include/boost/url/url.hpp | 10 +- include/boost/url/url_view.hpp | 2 +- test/url.cpp | 71 ++++++------ 17 files changed, 254 insertions(+), 155 deletions(-) diff --git a/doc/qbk/quickref.xml b/doc/qbk/quickref.xml index c2d17ed5..e58771fe 100644 --- a/doc/qbk/quickref.xml +++ b/doc/qbk/quickref.xml @@ -14,9 +14,12 @@ - + URL + + Encoding + @@ -26,7 +29,6 @@ ipv6_address path_view query_params_view - scheme static_pool static_url url @@ -36,7 +38,6 @@ Functions - parse_uri parse_path parse_path_abempty parse_path_absolute @@ -44,6 +45,8 @@ parse_path_rootless parse_query_params parse_relative_ref + parse_uri + parse_uri_reference Type Traits @@ -61,51 +64,20 @@ Operators + operator<< Constants + condition + error host_type + scheme Concepts CharSet - - rfc3986 - - absolute_uri_bnf - authority_bnf - fragment_bnf - hier_part_bnf - host_bnf - ip_literal_bnf - ipv_future_bnf - ipv4_address_bnf - ipv6_address_bnf - pct_encoded_bnf - port_bnf - query_bnf - relative_part_bnf - relative_ref_bnf - scheme_bnf - uri_bnf - userinfo_bnf - - - - - - - - - Percent Encoding - - - BNF - - - Functions @@ -114,16 +86,23 @@ pct_encode pct_encode_size - Options + Types pct_decode_opts pct_encode_opts - - Types - pct_encoded_str + + + + + + + BNF + + + Classes @@ -132,7 +111,6 @@ alpha_chars digit_chars hexdig_chars - parse_string range repeat token @@ -141,14 +119,57 @@ Functions + ascii_tolower find_if find_if_not hexdig_value is_valid parse + parse_range + parse_string validate + + RFC 3986 (1/2) + + absolute_uri_bnf + authority_bnf + fragment_bnf + fragment_part_bnf + hier_part_bnf + host_bnf + ip_literal_bnf + ipv_future_bnf + ipv4_address_bnf + ipv6_address_bnf + parsed_path + path_abempty_bnf + path_absolute_bnf + path_noscheme_bnf + path_rootless_bnf + + + + RFC 3986 (2/2) + + pct_encoded_bnf + port_bnf + port_part_bnf + query_bnf + query_part_bnf + relative_part_bnf + relative_ref_bnf + scheme_bnf + scheme_part_bnf + segment_bnf + segment_nz_bnf + segment_nz_nc_bnf + uri_bnf + uri_reference_bnf + userinfo_bnf + + diff --git a/include/boost/url.hpp b/include/boost/url.hpp index 4d442c5a..77a09ea2 100644 --- a/include/boost/url.hpp +++ b/include/boost/url.hpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -47,10 +48,10 @@ #include #include #include -#include -#include #include #include +#include +#include #include #include #include diff --git a/include/boost/url/bnf/char_set.hpp b/include/boost/url/bnf/char_set.hpp index ec458810..92ba60a0 100644 --- a/include/boost/url/bnf/char_set.hpp +++ b/include/boost/url/bnf/char_set.hpp @@ -190,7 +190,7 @@ hexdig_value(char c) noexcept //------------------------------------------------ -/** Find the first characer in the string that is in CharSet +/** Find the first character in the string that is in CharSet */ template char const* @@ -205,7 +205,7 @@ find_if( detail::has_find_if{}); } -/** Find the first characer in the string that is not in CharSet +/** Find the first character in the string that is not in CharSet */ template char const* diff --git a/include/boost/url/error.hpp b/include/boost/url/error.hpp index 7819d9e9..38c2d86a 100644 --- a/include/boost/url/error.hpp +++ b/include/boost/url/error.hpp @@ -18,18 +18,18 @@ namespace boost { namespace urls { -/// The type of error code used by the library -using error_code = boost::system::error_code; - -/// The type of system error thrown by the library -using system_error = boost::system::system_error; - /// The type of error category used by the library using error_category = boost::system::error_category; +/// The type of error code used by the library +using error_code = boost::system::error_code; + /// The type of error condition used by the library using error_condition = boost::system::error_condition; +/// The type of system error thrown by the library +using system_error = boost::system::system_error; + //---------------------------------------------------------- /** Error codes returned the library diff --git a/include/boost/url/impl/ipv4_address.ipp b/include/boost/url/impl/ipv4_address.ipp index 41975909..198a1b98 100644 --- a/include/boost/url/impl/ipv4_address.ipp +++ b/include/boost/url/impl/ipv4_address.ipp @@ -132,11 +132,12 @@ print_impl( std::ostream& operator<<( std::ostream& os, - ipv4_address const& a) + ipv4_address const& addr) { - char buf[ipv4_address::max_str_len + 1]; - auto n = a.print_impl(buf); - os.write(buf, n); + char buf[ipv4_address::max_str_len]; + auto const s = addr.to_buffer( + buf, sizeof(buf)); + os.write(s.data(), s.size()); return os; } diff --git a/include/boost/url/impl/ipv6_address.ipp b/include/boost/url/impl/ipv6_address.ipp index ed43e9a1..a503a47b 100644 --- a/include/boost/url/impl/ipv6_address.ipp +++ b/include/boost/url/impl/ipv6_address.ipp @@ -237,11 +237,12 @@ print_impl( std::ostream& operator<<( std::ostream& os, - ipv6_address const& a) + ipv6_address const& addr) { - char buf[ipv6_address::max_str_len + 1]; - auto n = a.print_impl(buf); - os.write(buf, n); + char buf[ipv6_address::max_str_len]; + auto const s = addr.to_buffer( + buf, sizeof(buf)); + os.write(s.data(), s.size()); return os; } diff --git a/include/boost/url/impl/path_view.ipp b/include/boost/url/impl/path_view.ipp index 371c09b7..158b258d 100644 --- a/include/boost/url/impl/path_view.ipp +++ b/include/boost/url/impl/path_view.ipp @@ -16,6 +16,7 @@ #include #include #include +#include namespace boost { namespace urls { @@ -162,6 +163,19 @@ end() const noexcept -> //------------------------------------------------ +std::ostream& +operator<<( + std::ostream& os, + path_view const& pv) +{ + os.write( + pv.encoded_path().data(), + pv.encoded_path().size()); + return os; +} + +//------------------------------------------------ + path_view parse_path_abempty( string_view s, diff --git a/include/boost/url/impl/query_params_view.ipp b/include/boost/url/impl/query_params_view.ipp index be688429..2e6cea44 100644 --- a/include/boost/url/impl/query_params_view.ipp +++ b/include/boost/url/impl/query_params_view.ipp @@ -15,6 +15,7 @@ #include #include #include +#include namespace boost { namespace urls { @@ -164,6 +165,19 @@ operator[](string_view key) const //------------------------------------------------ +std::ostream& +operator<<( + std::ostream& os, + query_params_view const& qpv) +{ + os.write( + qpv.encoded_query().data(), + qpv.encoded_query().size()); + return os; +} + +//------------------------------------------------ + query_params_view parse_query_params( string_view s, diff --git a/include/boost/url/impl/url.ipp b/include/boost/url/impl/url.ipp index 2de72724..eb411094 100644 --- a/include/boost/url/impl/url.ipp +++ b/include/boost/url/impl/url.ipp @@ -766,33 +766,6 @@ set_encoded_origin( // //------------------------------------------------ -url& -url:: -set_scheme(string_view s) -{ - set_scheme_impl( - s, string_to_scheme(s)); - return *this; -} - -url& -url:: -set_scheme(urls::scheme id) -{ - if(id == urls::scheme::unknown) - detail::throw_invalid_argument( - "url::set_scheme", - BOOST_CURRENT_LOCATION); - if(id == urls::scheme::none) - { - set_scheme_impl("", id); - return *this; - } - set_scheme_impl( - to_string(id), id); - return *this; -} - void url:: set_scheme_impl( @@ -896,6 +869,42 @@ set_scheme_impl( return; } +url& +url:: +remove_scheme() noexcept +{ + set_scheme_impl( + "", urls::scheme::none); + return *this; +} + +url& +url:: +set_scheme(string_view s) +{ + set_scheme_impl( + s, string_to_scheme(s)); + return *this; +} + +url& +url:: +set_scheme(urls::scheme id) +{ + if(id == urls::scheme::unknown) + detail::throw_invalid_argument( + "url::set_scheme", + BOOST_CURRENT_LOCATION); + if(id == urls::scheme::none) + { + set_scheme_impl("", id); + return *this; + } + set_scheme_impl( + to_string(id), id); + return *this; +} + //------------------------------------------------ // // authority diff --git a/include/boost/url/ipv4_address.hpp b/include/boost/url/ipv4_address.hpp index 954c5160..8f57323f 100644 --- a/include/boost/url/ipv4_address.hpp +++ b/include/boost/url/ipv4_address.hpp @@ -210,15 +210,6 @@ public: return ipv4_address(0xFFFFFFFF); } - /** Format the address to an output stream - */ - BOOST_URL_DECL - friend - std::ostream& - operator<<( - std::ostream&, - ipv4_address const&); - private: friend class ipv6_address; @@ -230,13 +221,13 @@ private: uint_type addr_; }; -#if 0 +/** Format the address to an output stream +*/ BOOST_URL_DECL std::ostream& operator<<( - std::ostream&, - ipv4_address const&); -#endif + std::ostream& os, + ipv4_address const& addr); /** Return an IPv4 address from an IP address string in dotted decimal form */ diff --git a/include/boost/url/ipv6_address.hpp b/include/boost/url/ipv6_address.hpp index 8ac88a27..8ad34257 100644 --- a/include/boost/url/ipv6_address.hpp +++ b/include/boost/url/ipv6_address.hpp @@ -214,15 +214,6 @@ public: ipv6_address loopback() noexcept; - /** Format the address to an output stream - */ - BOOST_URL_DECL - friend - std::ostream& - operator<<( - std::ostream&, - ipv6_address const&); - private: BOOST_URL_DECL std::size_t @@ -232,6 +223,14 @@ private: bytes_type addr_; }; +/** Format the address to an output stream +*/ +BOOST_URL_DECL +std::ostream& +operator<<( + std::ostream& os, + ipv6_address const& addr); + /** Return an IPv6 address from an IP address string @par Exception Safety diff --git a/include/boost/url/path_view.hpp b/include/boost/url/path_view.hpp index c4fe3d86..a3718d82 100644 --- a/include/boost/url/path_view.hpp +++ b/include/boost/url/path_view.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include namespace boost { @@ -65,6 +66,14 @@ public: return n_; } + /** Return the complete encoded path + */ + string_view + encoded_path() const noexcept + { + return s_; + } + /** Return an iterator to the beginning of the range */ BOOST_URL_DECL @@ -173,6 +182,16 @@ public: //---------------------------------------------------------- +/** Format the encoded path to an output stream +*/ +BOOST_URL_DECL +std::ostream& +operator<<( + std::ostream& os, + path_view const& pv); + +//---------------------------------------------------------- + /** Return a path view from a parsed string, using path-abempty bnf This function parses the string and returns the diff --git a/include/boost/url/query_params_view.hpp b/include/boost/url/query_params_view.hpp index 109b1ab9..fdce1c3d 100644 --- a/include/boost/url/query_params_view.hpp +++ b/include/boost/url/query_params_view.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include namespace boost { @@ -85,6 +86,14 @@ public: return n_; } + /** Return the full encoded query string + */ + string_view + encoded_query() const noexcept + { + return s_; + } + /** Return an iterator to the beginning of the range */ BOOST_URL_DECL @@ -416,6 +425,16 @@ public: //------------------------------------------------ +/** Format the encoded query to an output stream +*/ +BOOST_URL_DECL +std::ostream& +operator<<( + std::ostream& os, + query_params_view const& qpv); + +//------------------------------------------------ + /** Return a query params view from a parsed string, using query-params bnf This function parses the string and returns the diff --git a/include/boost/url/scheme.hpp b/include/boost/url/scheme.hpp index 21624c92..84d9c90d 100644 --- a/include/boost/url/scheme.hpp +++ b/include/boost/url/scheme.hpp @@ -28,16 +28,17 @@ enum class scheme : unsigned char */ unknown, - /** File Transfer Protocol (FTP) + /** + * File Transfer Protocol (FTP) - FTP is a standard communication protocol - used for the transfer of computer files - from a server to a client on a computer - network. + FTP is a standard communication protocol + used for the transfer of computer files + from a server to a client on a computer + network. - @par Specification - @li - The 'ftp' URI Scheme + @par Specification + @li + The 'ftp' URI Scheme */ ftp, diff --git a/include/boost/url/url.hpp b/include/boost/url/url.hpp index b5cd7bfe..c418ad92 100644 --- a/include/boost/url/url.hpp +++ b/include/boost/url/url.hpp @@ -738,6 +738,10 @@ public: // //-------------------------------------------- +private: + void set_scheme_impl(string_view s, urls::scheme id); +public: + /** Remove the scheme This function removes the scheme if it @@ -835,10 +839,6 @@ public: url& set_scheme(urls::scheme id); -private: - void set_scheme_impl(string_view s, urls::scheme id); -public: - //-------------------------------------------- // // authority @@ -2311,6 +2311,8 @@ private: parse() noexcept; }; +/** Format the encoded url to the output stream +*/ BOOST_URL_DECL std::ostream& operator<<(std::ostream& os, url const& u); diff --git a/include/boost/url/url_view.hpp b/include/boost/url/url_view.hpp index 7d3a5b38..6ba95fea 100644 --- a/include/boost/url/url_view.hpp +++ b/include/boost/url/url_view.hpp @@ -772,7 +772,7 @@ url_view parse_uri_reference( string_view s); -/** Format the serialized url to the output stream +/** Format the encoded url to the output stream */ BOOST_URL_DECL std::ostream& diff --git a/test/url.cpp b/test/url.cpp index 59669015..f53d610d 100644 --- a/test/url.cpp +++ b/test/url.cpp @@ -526,41 +526,48 @@ public: void testScheme() { + auto const remove = []( + string_view s1, string_view s2) { - url u; - u.reserve(40); + url u = parse_uri_reference(s1); BOOST_TEST( - u.set_scheme("http").str() == "http:"); - } + u.remove_scheme().str() == s2); + BOOST_TEST(u.scheme().empty()); + BOOST_TEST(u.scheme_id() == + scheme::none); + }; - url u; - BOOST_TEST(u.set_scheme("").str() == ""); - BOOST_TEST(u.set_scheme(scheme::none).str() == ""); - BOOST_TEST(u.set_scheme("http").str() == "http:"); - BOOST_TEST(u.scheme_id() == scheme::http); - BOOST_TEST_THROWS( - u.set_scheme("http:"), std::invalid_argument); - BOOST_TEST(u.str() == "http:"); - BOOST_TEST(u.scheme_id() == scheme::http); - BOOST_TEST_THROWS( - u.set_scheme("1http"), std::invalid_argument); - BOOST_TEST_THROWS( - u.set_scheme(scheme::unknown), std::invalid_argument); - BOOST_TEST(u.scheme_id() == scheme::http); - BOOST_TEST(u.str() == "http:"); - BOOST_TEST(u.scheme_id() == scheme::http); - BOOST_TEST(u.set_scheme("ftp").str() == "ftp:"); - BOOST_TEST(u.scheme_id() == scheme::ftp); - BOOST_TEST(u.set_scheme(scheme::none).str() == ""); - BOOST_TEST(u.scheme_id() == scheme::none); - BOOST_TEST(u.set_scheme(scheme::ws).str() == "ws:"); - BOOST_TEST(u.scheme_id() == scheme::ws); - BOOST_TEST(u.set_scheme("").str() == ""); - BOOST_TEST(u.scheme_id() == scheme::none); - BOOST_TEST(u.set_scheme("x").str() == "x:"); - BOOST_TEST(u.scheme_id() == scheme::unknown); - u = parse_uri("http:/path/to/file.txt"); - BOOST_TEST(u.set_scheme("").str() == "/path/to/file.txt"); + auto const set = []( + string_view s1, string_view s2, + string_view s3, scheme id) + { + url u = parse_uri_reference(s1); + BOOST_TEST( + u.set_scheme(s2).str() == s3); + BOOST_TEST(u.scheme() == s2); + BOOST_TEST(u.scheme_id() == id); + }; + + remove("", ""); + remove("x", "x"); + remove("x:", ""); + remove("x:/", "/"); + remove("x:a", "a"); + remove("x:a/", "a/"); + remove("x://", "//"); + remove("x:a:/", "./a:/"); + remove("x://a.b/1/2", "//a.b/1/2"); + remove("x://a:b@c.d/1/?#", "//a:b@c.d/1/?#"); + + set("", "ftp", "ftp:", scheme::ftp); + set("/", "ws", "ws:/", scheme::ws); + set("a", "ws", "ws:a", scheme::ws); + set("a/", "ws", "ws:a/", scheme::ws); + set("//", "ws", "ws://", scheme::ws); + set("a:/", "ws", "ws:/", scheme::ws); + set("//a.b/1/2", "ws","ws://a.b/1/2", scheme::ws); + set("//a:b@c.d/1/?#", "ws", + "ws://a:b@c.d/1/?#", scheme::ws); } //--------------------------------------------