diff --git a/doc/qbk/CharSet.qbk b/doc/qbk/CharSet.qbk index 0d0785b5..06342101 100644 --- a/doc/qbk/CharSet.qbk +++ b/doc/qbk/CharSet.qbk @@ -4,7 +4,7 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - Official repository: https://github.com/vinniefalco/uri + Official repository: https://github.com/CPPAlliance/url ] [section:CharSet CharSet] diff --git a/doc/qbk/main.qbk b/doc/qbk/main.qbk index 2716b1b6..65742772 100644 --- a/doc/qbk/main.qbk +++ b/doc/qbk/main.qbk @@ -4,7 +4,7 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - Official repository: https://github.com/vinniefalco/uri + Official repository: https://github.com/CPPAlliance/url ] [library Boost.URL @@ -46,6 +46,8 @@ [def __Swappable__ [@https://en.cppreference.com/w/cpp/named_req/Swappable ['Swappable]]] [def __CharSet__ [link url.CharSet ['CharSet]]] +[def __result__ `boost::system::result`] + [/ Dingbats ] [def __good__ [role green \u2714]] @@ -54,6 +56,7 @@ [/-----------------------------------------------------------------------------] [include intro.qbk] +[include quicklook.qbk] [include usage.qbk] [include CharSet.qbk] diff --git a/doc/qbk/quicklook.qbk b/doc/qbk/quicklook.qbk new file mode 100644 index 00000000..d6714aec --- /dev/null +++ b/doc/qbk/quicklook.qbk @@ -0,0 +1,16 @@ +[/ + Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + Official repository: https://github.com/CPPAlliance/url +] + +[section Quick Look] + +This section is intended to give the reader a brief overview of the features +and interface style of the library. + + +[endsect] diff --git a/doc/qbk/quickref.qbk b/doc/qbk/quickref.qbk deleted file mode 100644 index 80508b0c..00000000 --- a/doc/qbk/quickref.qbk +++ /dev/null @@ -1,60 +0,0 @@ -[/ - Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) - - Distributed under the Boost Software License, Version 1.0. (See accompanying - file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - - Official repository: https://github.com/vinniefalco/uri -] - -[table Quick Reference - [ - [Name] - [Description] - ] - [ - [[link url.ref.boost__urls__basic_url `basic_url`]] - [ - A modifiable container for a URL, using an __Allocator__. - ] - ] - [ - [[link url.ref.boost__urls__host_type `host_type`]] - [ - An enumeration indicating the type of host in a URL. - ] - ] - [ - [[link url.ref.boost__urls__static_pool `static_pool`]] - [ - A memory pool which allocates from the stack. - ] - ] - [ - [[link url.ref.boost__urls__static_url `static_url`]] - [ - A modifiable container for a URL, using fixed - capacity storage. - ] - ] - [ - [[link url.ref.boost__urls__url `url`]] - [ - A modifiable container for a URL, using the - standard allocator. - ] - ] - [ - [[link url.ref.boost__urls__url_base `url_base`]] - [ - Base class for a modifiable URL container. - ] - ] - [ - [[link url.ref.boost__urls__url_view `url_view`]] - [ - A parsed reference to a URL string. - ] - ] -] - diff --git a/doc/qbk/usage.qbk b/doc/qbk/usage.qbk index e16ae2b9..5176748a 100644 --- a/doc/qbk/usage.qbk +++ b/doc/qbk/usage.qbk @@ -4,7 +4,7 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - Official repository: https://github.com/vinniefalco/uri + Official repository: https://github.com/CPPAlliance/url ] [section Usage] @@ -27,4 +27,9 @@ quote), HEXDIG (hexadecimal digits), LF (line feed), and SP (space). The complete URI syntax is described in __RFC3986__. +[heading Return Type boost::system::result] + +In many places, functions in the library have a return type which uses the +__result__ alias template. + [endsect] diff --git a/include/boost/url.hpp b/include/boost/url.hpp index 59d7b7ba..b52f1567 100644 --- a/include/boost/url.hpp +++ b/include/boost/url.hpp @@ -15,9 +15,10 @@ #include #include #include -#include #include #include +#include +#include #include #include #include diff --git a/include/boost/url/detail/any_query_iter.hpp b/include/boost/url/detail/any_query_iter.hpp index a6dead31..3f4e758a 100644 --- a/include/boost/url/detail/any_query_iter.hpp +++ b/include/boost/url/detail/any_query_iter.hpp @@ -12,7 +12,7 @@ #include #include -#include +#include #include namespace boost { diff --git a/include/boost/url/detail/impl/any_query_iter.hpp b/include/boost/url/detail/impl/any_query_iter.hpp index b3a12511..2305c25a 100644 --- a/include/boost/url/detail/impl/any_query_iter.hpp +++ b/include/boost/url/detail/impl/any_query_iter.hpp @@ -10,7 +10,7 @@ #ifndef BOOST_URL_DETAIL_IMPL_ANY_QUERY_ITER_HPP #define BOOST_URL_DETAIL_IMPL_ANY_QUERY_ITER_HPP -#include +#include namespace boost { namespace urls { diff --git a/include/boost/url/host_type.hpp b/include/boost/url/host_type.hpp index f8be6d51..b646d310 100644 --- a/include/boost/url/host_type.hpp +++ b/include/boost/url/host_type.hpp @@ -21,7 +21,8 @@ namespace urls { and containers to indicate the type of host present in a URL. - @see url_view::host, url_base::host + @see + @ref url_view::host. */ enum class host_type { diff --git a/include/boost/url/impl/params_encoded_view.ipp b/include/boost/url/impl/params_encoded_view.ipp index 51ade626..4883a962 100644 --- a/include/boost/url/impl/params_encoded_view.ipp +++ b/include/boost/url/impl/params_encoded_view.ipp @@ -252,29 +252,16 @@ find( // //------------------------------------------------ -params_encoded_view +result parse_query_params( - string_view s, - error_code& ec) noexcept -{ - query_bnf t; - if(! bnf::parse_string( - s, ec, t)) - return {}; - return params_encoded_view( - t.str, t.count); -} - -params_encoded_view -parse_query_params( - string_view s) + string_view s) noexcept { error_code ec; - auto qp = parse_query_params(s, ec); - if(ec.failed()) - detail::throw_invalid_argument( - BOOST_CURRENT_LOCATION); - return qp; + query_bnf t; + if(! bnf::parse_string(s, ec, t)) + return ec; + return params_encoded_view( + t.str, t.count); } } // urls diff --git a/include/boost/url/impl/segments.hpp b/include/boost/url/impl/segments.hpp index ec10398e..315d0450 100644 --- a/include/boost/url/impl/segments.hpp +++ b/include/boost/url/impl/segments.hpp @@ -226,6 +226,15 @@ segments( { } +bool +segments:: +is_absolute() const noexcept +{ + return + u_->len(id_path) != 0 && + u_->s_[u_->offset(id_path)] == '/'; +} + template auto segments:: diff --git a/include/boost/url/impl/segments_encoded.hpp b/include/boost/url/impl/segments_encoded.hpp index 0ca0468a..f26c4470 100644 --- a/include/boost/url/impl/segments_encoded.hpp +++ b/include/boost/url/impl/segments_encoded.hpp @@ -213,6 +213,15 @@ segments_encoded( { } +bool +segments_encoded:: +is_absolute() const noexcept +{ + return + u_->len(id_path) != 0 && + u_->s_[u_->offset(id_path)] == '/'; +} + template auto segments_encoded:: diff --git a/include/boost/url/impl/url_view.ipp b/include/boost/url/impl/url_view.ipp index add01fe1..04b60847 100644 --- a/include/boost/url/impl/url_view.ipp +++ b/include/boost/url/impl/url_view.ipp @@ -638,21 +638,25 @@ apply( } } +//------------------------------------------------ +// +// Parsing +// //------------------------------------------------ -url_view +result parse_absolute_uri( - string_view s, - error_code& ec) noexcept + string_view s) noexcept { if(s.size() > url_view::max_size()) detail::throw_length_error( "url_view::max_size exceeded", BOOST_CURRENT_LOCATION); + error_code ec; absolute_uri_bnf t; if(! bnf::parse_string(s, ec, t)) - return {}; + return ec; url_view u(s.data()); @@ -672,43 +676,19 @@ parse_absolute_uri( return u; } -url_view -parse_absolute_uri( - string_view s, - std::error_code& ec) noexcept -{ - error_code ec0; - auto u = parse_absolute_uri(s, ec0); - ec = ec0; - return u; -} - -url_view -parse_absolute_uri( - string_view s) -{ - error_code ec; - auto u = parse_absolute_uri(s, ec); - detail::maybe_throw(ec, - BOOST_CURRENT_LOCATION); - return u; -} - -//------------------------------------------------ - -url_view +result parse_uri( - string_view s, - error_code& ec) noexcept + string_view s) noexcept { if(s.size() > url_view::max_size()) detail::throw_length_error( "url_view::max_size exceeded", BOOST_CURRENT_LOCATION); + error_code ec; uri_bnf t; if(! bnf::parse_string(s, ec, t)) - return {}; + return ec; url_view u(s.data()); @@ -731,44 +711,20 @@ parse_uri( return u; } -url_view -parse_uri( - string_view s, - std::error_code& ec) noexcept -{ - error_code ec0; - auto u = parse_uri(s, ec0); - ec = ec0; - return u; -} - -url_view -parse_uri( - string_view s) -{ - error_code ec; - auto u = parse_uri(s, ec); - detail::maybe_throw(ec, - BOOST_CURRENT_LOCATION); - return u; -} - -//------------------------------------------------ - -url_view +result parse_relative_ref( - string_view s, - error_code& ec) noexcept + string_view s) noexcept { if(s.size() > url_view::max_size()) detail::throw_length_error( "url_view::max_size exceeded", BOOST_CURRENT_LOCATION); + error_code ec; relative_ref_bnf t; if(! bnf::parse_string( s, ec, t)) - return {}; + return ec; url_view u(s.data()); @@ -788,43 +744,19 @@ parse_relative_ref( return u; } -url_view -parse_relative_ref( - string_view s, - std::error_code& ec) noexcept -{ - error_code ec0; - auto u = parse_relative_ref(s, ec0); - ec = ec0; - return u; -} - -url_view -parse_relative_ref( - string_view s) -{ - error_code ec; - auto u = parse_relative_ref(s, ec); - detail::maybe_throw(ec, - BOOST_CURRENT_LOCATION); - return u; -} - -//------------------------------------------------ - -url_view +result parse_uri_reference( - string_view s, - error_code& ec) noexcept + string_view s) noexcept { if(s.size() > url_view::max_size()) detail::throw_length_error( "url_view::max_size exceeded", BOOST_CURRENT_LOCATION); + error_code ec; uri_reference_bnf t; if(! bnf::parse_string(s, ec, t)) - return {}; + return ec; url_view u(s.data()); @@ -847,28 +779,6 @@ parse_uri_reference( return u; } -url_view -parse_uri_reference( - string_view s, - std::error_code& ec) noexcept -{ - error_code ec0; - auto u = parse_uri_reference(s, ec0); - ec = ec0; - return u; -} - -url_view -parse_uri_reference( - string_view s) -{ - error_code ec; - auto u = parse_uri_reference(s, ec); - detail::maybe_throw(ec, - BOOST_CURRENT_LOCATION); - return u; -} - //------------------------------------------------ std::ostream& diff --git a/include/boost/url/params.hpp b/include/boost/url/params.hpp index ff091378..2264054c 100644 --- a/include/boost/url/params.hpp +++ b/include/boost/url/params.hpp @@ -11,8 +11,8 @@ #define BOOST_URL_PARAMS_HPP #include +#include #include -#include #include #include #include @@ -25,6 +25,8 @@ namespace urls { class url; #endif +/** A random access container of modifiable, percent-decoded query parameters. +*/ class params : private detail::parts_base { diff --git a/include/boost/url/params_encoded.hpp b/include/boost/url/params_encoded.hpp index 5565ef71..2b03d407 100644 --- a/include/boost/url/params_encoded.hpp +++ b/include/boost/url/params_encoded.hpp @@ -11,8 +11,8 @@ #define BOOST_URL_PARAMS_ENCODED_HPP #include +#include #include -#include #include #include #include diff --git a/include/boost/url/params_encoded_view.hpp b/include/boost/url/params_encoded_view.hpp index 8110751e..1117fbb1 100644 --- a/include/boost/url/params_encoded_view.hpp +++ b/include/boost/url/params_encoded_view.hpp @@ -12,8 +12,8 @@ #include #include +#include #include -#include #include #include #include @@ -191,18 +191,9 @@ public: // //-------------------------------------------- - BOOST_URL_DECL - friend - params_encoded_view - parse_query_params( - string_view s, - error_code& ec) noexcept; - - BOOST_URL_DECL - friend - params_encoded_view - parse_query_params( - string_view s); + BOOST_URL_DECL friend + result + parse_query_params(string_view s) noexcept; }; //------------------------------------------------ @@ -234,39 +225,9 @@ public: @see @ref params_encoded_view */ BOOST_URL_DECL -params_encoded_view +result parse_query_params( - string_view s, - error_code& ec) noexcept; - -/** Return a query params view from a parsed string, using query-params bnf - - This function parses the string and returns the - corresponding query params object if the string - is valid, otherwise throws an exception. - The query string should not include the - leading question mark. - - @par BNF - @code - query-params = [ query-param ] *( "&" [ query-param ] ) - query-param = key [ "=" value ] - @endcode - - @throw system_error Thrown on error - - @param s The string to parse - - @par Specification - @li - 3.4. Query (rfc3986) - - @see @ref params_encoded_view -*/ -BOOST_URL_DECL -params_encoded_view -parse_query_params( - string_view s); + string_view s) noexcept; } // urls } // boost diff --git a/include/boost/url/value_types.hpp b/include/boost/url/params_value_type.hpp similarity index 90% rename from include/boost/url/value_types.hpp rename to include/boost/url/params_value_type.hpp index 0b819f6a..991918c6 100644 --- a/include/boost/url/value_types.hpp +++ b/include/boost/url/params_value_type.hpp @@ -7,8 +7,8 @@ // Official repository: https://github.com/CPPAlliance/url // -#ifndef BOOST_URL_VALUE_TYPES_HPP -#define BOOST_URL_VALUE_TYPES_HPP +#ifndef BOOST_URL_PARAMS_VALUE_TYPE_HPP +#define BOOST_URL_PARAMS_VALUE_TYPE_HPP #include #include diff --git a/include/boost/url/segments.hpp b/include/boost/url/segments.hpp index 2d335466..cec3cf1a 100644 --- a/include/boost/url/segments.hpp +++ b/include/boost/url/segments.hpp @@ -12,9 +12,7 @@ #include #include -#include #include -#include #include #include @@ -120,6 +118,15 @@ public: // //-------------------------------------------- + /** Returns true if this contains an absolute path. + + Absolute paths always start with a + forward slash ('/'). + */ + inline + bool + is_absolute() const noexcept; + /** Replace the contents of the container This function replaces the contents @@ -128,8 +135,8 @@ public: Each string must contain a valid percent-encoding or else an exception is thrown. - The behavior is undefined any string - refers to the contents of `*this`. + The behavior is undefined if any + string refers to the contents of `*this`. All iterators and references to elements of the container are invalidated, including the @ref end iterator. @@ -339,13 +346,13 @@ public: // //-------------------------------------------- - /** Return an iterator to the beginning + /** Return an iterator to the beginning. */ inline iterator begin() const noexcept; - /** Return an iterator to the end + /** Return an iterator to the end. */ inline iterator diff --git a/include/boost/url/segments_encoded.hpp b/include/boost/url/segments_encoded.hpp index d78096c9..c1530d40 100644 --- a/include/boost/url/segments_encoded.hpp +++ b/include/boost/url/segments_encoded.hpp @@ -116,6 +116,15 @@ public: // //-------------------------------------------- + /** Returns true if this contains an absolute path. + + Absolute paths always start with a + forward slash ('/'). + */ + inline + bool + is_absolute() const noexcept; + /** Replace the contents of the container This function replaces the contents diff --git a/include/boost/url/segments_encoded_view.hpp b/include/boost/url/segments_encoded_view.hpp index a8925c27..e28b1e6c 100644 --- a/include/boost/url/segments_encoded_view.hpp +++ b/include/boost/url/segments_encoded_view.hpp @@ -29,26 +29,56 @@ class url_view; Objects of this type represent an iterable range of path segments, where each segment is represented by a percent-encoded string. + + Dereferenced iterators return string views + into the underlying character buffer. + Ownership of the underlying characters is - not transferred; the source of the character - buffer must remain valid until the container - is no longer used. + not transferred; the character buffer used + to construct the container must remain + valid for as long as the container exists. + A view of encoded segments in a URL's path can be obtained by calling @ref url_view::encoded_segments. Alternatively, to obtain encoded segments from a path stored in a string call one of - the parsing functions: - @ref parse_path_abempty, - @ref parse_path_absolute, - @ref parse_path_noscheme, - @ref parse_path_rootless. + the parsing functions (see below). @par Example - A path string is parsed into encoded segments: + + A path string is parsed into encoded + segments, then each segment is printed to + standard output: + @code + segments_encoded_view sev = parse_path( "/path/to/file.txt" ).value(); + + for( auto it = sev.begin(); it != sev.end(); ++it ) + std::cout << *it << std::endl; @endcode + + A URL containing a path is parsed, then a + view to the encoded segments is obtained + and formatted to standard output: + + @code + url_view u = parse_uri( "http://example.com/path/to/file.txt" ).value(); + + segments_encoded_view sev = u.encoded_segments(); + + std::cout << sev << std::endl; + @endcode + + @par Complexity + + Iterator increment or decrement runs in linear + time on the size of the segment. + All other operations run in constant time. + No operations allocate memory. + @see + @ref parse_path, @ref parse_path_abempty, @ref parse_path_absolute, @ref parse_path_noscheme, @@ -69,7 +99,7 @@ class segments_encoded_view public: #ifdef BOOST_URL_DOCS - /** An iterator to a read-only encoded path segment. + /** A bidirectional read-only iterator to an encoded path segment. */ using iterator = __see_below__; #else @@ -112,17 +142,17 @@ public: /** Return a view of this container as percent-decoded segments - This function returns a new view over - the same underlying character buffer - where each segment is returned as a - @ref string_value with percent-decoding - applied using the optionally specified - allocator. The decoded view does not take - ownership of the underlying character - buffer; the caller is still responsible - for ensuring that the buffer remains valid - until all views which reference it are - destroyed. + This function returns a new view over the + same underlying character buffer where each + segment is returned as a @ref string_value + with percent-decoding applied using the + optionally specified allocator. + + The decoded view does not take ownership of + the underlying character buffer; the caller + is still responsible for ensuring that the + buffer remains valid until all views which + reference it are destroyed. @par Example @code diff --git a/include/boost/url/string.hpp b/include/boost/url/string.hpp index a0b09218..18d16ed6 100644 --- a/include/boost/url/string.hpp +++ b/include/boost/url/string.hpp @@ -34,7 +34,7 @@ namespace urls { owning the character buffer extends until the string view is no longer referenced. */ -using string_view = boost::string_view; +typedef boost::string_view string_view; /** The string alias template return type for allocating member functions. @@ -47,7 +47,7 @@ using string_type = std::basic_string, Allocator>; -/** Alias for `std::true_type` if a `T` can be converted to a @ref string_view +/** Alias for `std::true_type` if a `T` can be converted to a string_view This metafunction is an alias for `std::true_type` if @@ -92,7 +92,7 @@ using string_type = The function @ref to_string_view is used to generically convert an instance of a type - `T` to @ref string_view when such a conversion + `T` to `string_view` when such a conversion is possible. This allows the library to interoperate with various string-like types. diff --git a/include/boost/url/url_view.hpp b/include/boost/url/url_view.hpp index dc2e4f98..a0222565 100644 --- a/include/boost/url/url_view.hpp +++ b/include/boost/url/url_view.hpp @@ -60,9 +60,9 @@ struct scheme_part_bnf; @code url u; - u = parse_uri( "http://www.example.com/index.html" ); + u = parse_uri( "http://www.example.com/index.html" ).value(); - u = parse_relative_ref( "/path/to/file.txt" ); + u = parse_relative_ref( "/path/to/file.txt" ).value(); @endcode @par BNF @@ -71,6 +71,8 @@ struct scheme_part_bnf; URI-reference = URI / relative-ref + absolute-URI = scheme ":" hier-part [ "?" query ] + relative-ref = relative-part [ "?" query ] [ "#" fragment ] @endcode @@ -1721,33 +1723,14 @@ public: // //-------------------------------------------- - BOOST_URL_DECL friend url_view parse_absolute_uri( - string_view s, error_code& ec) noexcept; - BOOST_URL_DECL friend url_view parse_absolute_uri( - string_view s, std::error_code& ec) noexcept; - BOOST_URL_DECL friend url_view parse_absolute_uri( - string_view s); - - BOOST_URL_DECL friend url_view parse_uri( - string_view s, error_code& ec) noexcept; - BOOST_URL_DECL friend url_view parse_uri( - string_view s, std::error_code& ec) noexcept; - BOOST_URL_DECL friend url_view parse_uri( - string_view s); - - BOOST_URL_DECL friend url_view parse_relative_ref( - string_view s, error_code& ec) noexcept; - BOOST_URL_DECL friend url_view parse_relative_ref( - string_view s, std::error_code& ec) noexcept; - BOOST_URL_DECL friend url_view parse_relative_ref( - string_view s); - - BOOST_URL_DECL friend url_view parse_uri_reference( - string_view s, error_code& ec) noexcept; - BOOST_URL_DECL friend url_view parse_uri_reference( - string_view s, std::error_code& ec) noexcept; - BOOST_URL_DECL friend url_view parse_uri_reference( - string_view s); + BOOST_URL_DECL friend result + parse_absolute_uri(string_view s) noexcept; + BOOST_URL_DECL friend result + parse_uri(string_view s) noexcept; + BOOST_URL_DECL friend result + parse_relative_ref(string_view s) noexcept; + BOOST_URL_DECL friend result + parse_uri_reference(string_view s) noexcept; private: void apply(scheme_part_bnf const& t) noexcept; @@ -1801,102 +1784,9 @@ private: @ref url_view. */ BOOST_URL_DECL -url_view +result parse_absolute_uri( - string_view s, - error_code& ec) noexcept; - -/** Parse an absolute-URI - - This function parses a string according - to the absolute-URI grammar below, and - returns a @ref url_view referencing the string. - Ownership of the string is not transferred; - the caller is responsible for ensuring that - the lifetime of the string extends until the - view is no longer being accessed. - - @par BNF - @code - absolute-URI = scheme ":" hier-part [ "?" query ] - - hier-part = "//" authority path-abempty - / path-absolute - / path-rootless - / path-empty - @endcode - - @par Exception Safety - Throws nothing. - - @return A view to the parsed URL - - @param s The string to parse - - @param ec Set to the error, if any occurred - - @par Specification - @li 4.3. Absolute URI (rfc3986) - - @see - @ref parse_absolute_uri, - @ref parse_relative_ref, - @ref parse_uri, - @ref parse_uri_reference, - @ref url_view. -*/ -BOOST_URL_DECL -url_view -parse_absolute_uri( - string_view s, - std::error_code& ec) noexcept; - -/** Parse an absolute-URI - - This function parses a string according - to the absolute-URI grammar below, and - returns a @ref url_view referencing the string. - Ownership of the string is not transferred; - the caller is responsible for ensuring that - the lifetime of the string extends until the - view is no longer being accessed. - - @par BNF - @code - absolute-URI = scheme ":" hier-part [ "?" query ] - - hier-part = "//" authority path-abempty - / path-absolute - / path-rootless - / path-empty - @endcode - - @par Exception Safety - Exceptions thrown on invalid input. - - @return A view to the parsed URL - - @param s The string to parse - - @throw std::invalid_argument parse error - - @par Specification - @li 4.3. Absolute URI (rfc3986) - - @see - @ref parse_absolute_uri, - @ref parse_relative_ref, - @ref parse_uri, - @ref parse_uri_reference, - @ref url_view. -*/ -BOOST_URL_DECL -url_view -parse_absolute_uri(string_view s); - -//------------------------------------------------ + string_view s) noexcept; /** Parse a URI @@ -1939,102 +1829,9 @@ parse_absolute_uri(string_view s); @ref url_view. */ BOOST_URL_DECL -url_view +result parse_uri( - string_view s, - error_code& ec) noexcept; - -/** Parse a URI - - This function parses a string according - to the URI grammar below, and returns a - @ref url_view referencing the string. - Ownership of the string is not transferred; - the caller is responsible for ensuring that - the lifetime of the string extends until the - view is no longer being accessed. - - @par BNF - @code - URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] - - hier-part = "//" authority path-abempty - / path-absolute - / path-rootless - / path-empty - @endcode - - @par Exception Safety - Throws nothing. - - @return A view to the parsed URL - - @param s The string to parse - - @param ec Set to the error, if any occurred - - @par Specification - @li 3. Syntax Components (rfc3986) - - @see - @ref parse_absolute_uri, - @ref parse_relative_ref, - @ref parse_uri, - @ref parse_uri_reference, - @ref url_view. -*/ -BOOST_URL_DECL -url_view -parse_uri( - string_view s, - std::error_code& ec) noexcept; - -/** Parse a URI - - This function parses a string according - to the URI grammar below, and returns a - @ref url_view referencing the string. - Ownership of the string is not transferred; - the caller is responsible for ensuring that - the lifetime of the string extends until the - view is no longer being accessed. - - @par BNF - @code - URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] - - hier-part = "//" authority path-abempty - / path-absolute - / path-rootless - / path-empty - @endcode - - @par Exception Safety - Exceptions thrown on invalid input. - - @return A view to the parsed URL - - @param s The string to parse - - @throw std::invalid_argument parse error - - @par Specification - @li 3. Syntax Components (rfc3986) - - @see - @ref parse_absolute_uri, - @ref parse_relative_ref, - @ref parse_uri, - @ref parse_uri_reference, - @ref url_view. -*/ -BOOST_URL_DECL -url_view -parse_uri(string_view s); - -//------------------------------------------------ + string_view s) noexcept; /** Parse a relative-ref @@ -2077,103 +1874,9 @@ parse_uri(string_view s); @ref url_view. */ BOOST_URL_DECL -url_view +result parse_relative_ref( - string_view s, - error_code& ec) noexcept; - -/** Parse a relative-ref - - This function parses a string according - to the relative-ref grammar below, and - returns a @ref url_view referencing the string. - Ownership of the string is not transferred; - the caller is responsible for ensuring that - the lifetime of the string extends until the - view is no longer being accessed. - - @par BNF - @code - relative-ref = relative-part [ "?" query ] [ "#" fragment ] - - relative-part = "//" authority path-abempty - / path-absolute - / path-noscheme - / path-empty - @endcode - - @par Exception Safety - Throws nothing. - - @return A view to the parsed URL - - @param s The string to parse - - @param ec Set to the error, if any occurred - - @par Specification - @li 4.2. Relative Reference (rfc3986) - - @see - @ref parse_absolute_uri, - @ref parse_relative_ref, - @ref parse_uri, - @ref parse_uri_reference, - @ref url_view. -*/ -BOOST_URL_DECL -url_view -parse_relative_ref( - string_view s, - std::error_code& ec) noexcept; - -/** Parse a relative-ref - - This function parses a string according - to the relative-ref grammar below, and - returns a @ref url_view referencing the string. - Ownership of the string is not transferred; - the caller is responsible for ensuring that - the lifetime of the string extends until the - view is no longer being accessed. - - @par BNF - @code - relative-ref = relative-part [ "?" query ] [ "#" fragment ] - - relative-part = "//" authority path-abempty - / path-absolute - / path-noscheme - / path-empty - @endcode - - @par Exception Safety - Exceptions thrown on invalid input. - - @return A view to the parsed URL - - @param s The string to parse - - @throw std::invalid_argument parse error - - @par Specification - @li 4.2. Relative Reference (rfc3986) - - @see - @ref parse_absolute_uri, - @ref parse_relative_ref, - @ref parse_uri, - @ref parse_uri_reference, - @ref url_view. -*/ -BOOST_URL_DECL -url_view -parse_relative_ref( - string_view s); - -//------------------------------------------------ + string_view s) noexcept; /** Parse a URI-reference @@ -2225,119 +1928,9 @@ parse_relative_ref( @ref url_view. */ BOOST_URL_DECL -url_view +result parse_uri_reference( - string_view s, - error_code& ec) noexcept; - -/** Parse a URI-reference - - This function parses a string according - to the URI-reference grammar below, and - returns a @ref url_view referencing the string. - Ownership of the string is not transferred; - the caller is responsible for ensuring that - the lifetime of the string extends until the - view is no longer being accessed. - - @par BNF - @code - URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] - - hier-part = "//" authority path-abempty - / path-absolute - / path-rootless - / path-empty - - URI-reference = URI / relative-ref - - relative-ref = relative-part [ "?" query ] [ "#" fragment ] - - relative-part = "//" authority path-abempty - / path-absolute - / path-noscheme - / path-empty - @endcode - - @par Exception Safety - Throws nothing. - - @return A view to the parsed URL - - @param s The string to parse - - @param ec Set to the error, if any occurred - - @par Specification - @li 4.1. URI Reference (rfc3986) - - @see - @ref parse_absolute_uri, - @ref parse_relative_ref, - @ref parse_uri, - @ref parse_uri_reference, - @ref url_view. -*/ -BOOST_URL_DECL -url_view -parse_uri_reference( - string_view s, - std::error_code& ec) noexcept; - -/** Parse a URI-reference - - This function parses a string according - to the URI-reference grammar below, and - returns a @ref url_view referencing the string. - Ownership of the string is not transferred; - the caller is responsible for ensuring that - the lifetime of the string extends until the - view is no longer being accessed. - - @par BNF - @code - URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] - - hier-part = "//" authority path-abempty - / path-absolute - / path-rootless - / path-empty - - URI-reference = URI / relative-ref - - relative-ref = relative-part [ "?" query ] [ "#" fragment ] - - relative-part = "//" authority path-abempty - / path-absolute - / path-noscheme - / path-empty - @endcode - - @par Exception Safety - Exceptions thrown on invalid input. - - @return A view to the parsed URL - - @param s The string to parse - - @throw std::invalid_argument parse error - - @par Specification - @li 4.1. URI Reference (rfc3986) - - @see - @ref parse_absolute_uri, - @ref parse_relative_ref, - @ref parse_uri, - @ref parse_uri_reference, - @ref url_view. -*/ -BOOST_URL_DECL -url_view -parse_uri_reference( - string_view s); + string_view s) noexcept; //------------------------------------------------ diff --git a/include/boost/url/urls.hpp b/include/boost/url/urls.hpp index e73ae6bd..f8aacb4e 100644 --- a/include/boost/url/urls.hpp +++ b/include/boost/url/urls.hpp @@ -16,8 +16,8 @@ namespace boost { -using url = urls::url; -using url_view = urls::url_view; +using urls::url; +using urls::url_view; } // boost diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 143ae295..e75c8921 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -24,8 +24,10 @@ set(BOOST_URL_TESTS_FILES params.cpp params_encoded.cpp params_encoded_view.cpp + params_value_type.cpp params_view.cpp pct_encoding.cpp + pct_encoding_types.cpp scheme.cpp segments.cpp segments_encoded.cpp @@ -61,6 +63,7 @@ set(BOOST_URL_TESTS_FILES rfc/query_bnf.cpp rfc/query_part_bnf.cpp rfc/relative_part_bnf.cpp + rfc/relative_ref_bnf.cpp rfc/scheme_bnf.cpp rfc/scheme_part_bnf.cpp rfc/uri_bnf.cpp diff --git a/test/unit/Jamfile b/test/unit/Jamfile index 3b007e26..c8bffce4 100644 --- a/test/unit/Jamfile +++ b/test/unit/Jamfile @@ -28,8 +28,10 @@ local SOURCES = params.cpp params_encoded.cpp params_encoded_view.cpp + params_value_type.cpp params_view.cpp pct_encoding.cpp + pct_encoding_types.cpp scheme.cpp segments.cpp segments_encoded.cpp @@ -65,6 +67,7 @@ local SOURCES = rfc/query_bnf.cpp rfc/query_part_bnf.cpp rfc/relative_part_bnf.cpp + rfc/relative_ref_bnf.cpp rfc/scheme_bnf.cpp rfc/scheme_part_bnf.cpp rfc/uri_bnf.cpp diff --git a/test/unit/params.cpp b/test/unit/params.cpp index fe005d92..eb3b4156 100644 --- a/test/unit/params.cpp +++ b/test/unit/params.cpp @@ -31,7 +31,7 @@ public: // assign(FwdIt, FwdIt) { url u = parse_uri_reference( - "/?x#f"); + "/?x#f").value(); u.params(pa.allocator()) = { { "k1", "1", true }, { "k2", "2", true }, @@ -44,7 +44,7 @@ public: "/?k1=1&k2=2&k3=&k4&k5=55555#f"); } { - url u = parse_uri_reference("/?x#f"); + url u = parse_uri_reference("/?x#f").value(); u.params(pa.allocator()) = {}; BOOST_TEST(u.encoded_query() == ""); BOOST_TEST(u.encoded_url() == "/#f"); @@ -60,7 +60,7 @@ public: // back { url u = parse_uri_reference( - "?k0=0&k1=1&k2=&k3&k4=4444#f"); + "?k0=0&k1=1&k2=&k3&k4=4444#f").value(); params p = u.params(pa.allocator()); BOOST_TEST(p.at(0).key == "k0"); BOOST_TEST(p.at(0).value == "0"); @@ -86,7 +86,7 @@ public: // at(Key) { url u = parse_uri_reference( - "?k0=0&k1=1&k2=&k3&k4=4444#f"); + "?k0=0&k1=1&k2=&k3&k4=4444#f").value(); params p = u.params(pa.allocator()); BOOST_TEST(p.at("k0") == "0"); BOOST_TEST(p.at("k1") == "1"); @@ -106,7 +106,7 @@ public: // size { url u = parse_uri_reference( - "?k0=0&k1=1&k2=&k3&k4=4444#f"); + "?k0=0&k1=1&k2=&k3&k4=4444#f").value(); params p = u.params(pa.allocator()); BOOST_TEST(! p.empty()); BOOST_TEST(p.size() == 5); @@ -125,7 +125,7 @@ public: // clear { url u = parse_uri_reference( - "/?k0=0&k1=1&k2=&k3&k4=4444#f"); + "/?k0=0&k1=1&k2=&k3&k4=4444#f").value(); params p = u.params(pa.allocator()); p.clear(); BOOST_TEST(u.encoded_query() == ""); @@ -135,7 +135,7 @@ public: // insert(iterator, value_type) { url u = parse_uri_reference( - "/?k0=0&k2=#f"); + "/?k0=0&k2=#f").value(); params p = u.params(pa.allocator()); auto it = p.insert(p.begin() + 1, {"k1", "1", true}); @@ -151,7 +151,7 @@ public: // insert(iterator, FwdIt, FwdIt) { url u = parse_uri_reference( - "/?k0=0&k3#f"); + "/?k0=0&k3#f").value(); params p = u.params(pa.allocator()); auto it = p.insert(p.begin() + 1,{ {"k1", "1", true}, @@ -166,7 +166,7 @@ public: // replace(iterator, value_type) { url u = parse_uri_reference( - "/?k0=0&k1=1&k3#f"); + "/?k0=0&k1=1&k3#f").value(); params p = u.params(pa.allocator()); auto it = p.replace( p.end() - 1, @@ -182,7 +182,7 @@ public: // replace(iterator, iterator, initializer_list) { url u = parse_uri_reference( - "/?k0=0&k1=1&k2=&k3&k4=4444#f"); + "/?k0=0&k1=1&k2=&k3&k4=4444#f").value(); params p = u.params(pa.allocator()); auto it = p.replace( p.begin() + 1, p.begin() + 3, { @@ -199,7 +199,7 @@ public: // remove_value(iterator) { url u = parse_uri_reference( - "/?k0=0&k%31=1&k2=#f"); + "/?k0=0&k%31=1&k2=#f").value(); params p = u.params(pa.allocator()); BOOST_TEST(p.at(1).key == "k1"); auto it = p.remove_value(p.begin() + 1); @@ -218,7 +218,7 @@ public: // emplace_at(iterator, Key, Value) { url u = parse_uri_reference( - "/?k0=0&k%31=1&k2=#f"); + "/?k0=0&k%31=1&k2=#f").value(); params p = u.params(pa.allocator()); auto it = p.emplace_at( p.begin() + 1, @@ -234,7 +234,7 @@ public: // emplace_at(iterator, Key) { url u = parse_uri_reference( - "/?k0=0&k1=1&k2=&k3#f"); + "/?k0=0&k1=1&k2=&k3#f").value(); params p = u.params(pa.allocator()); auto it = p.emplace_at( p.begin() + 2, @@ -250,7 +250,7 @@ public: // emplace_before(iterator, Key, Value) { url u = parse_uri_reference( - "/?k0=0&k2=&k3#f"); + "/?k0=0&k2=&k3#f").value(); params p = u.params(pa.allocator()); auto it = p.emplace_before( p.begin() + 1, "k1", "1"); @@ -265,7 +265,7 @@ public: // emplace_before(iterator, Key) { url u = parse_uri_reference( - "/?k0=0&k2=&k3#f"); + "/?k0=0&k2=&k3#f").value(); params p = u.params(pa.allocator()); auto it = p.emplace_before( p.begin() + 1, "k1"); @@ -280,7 +280,7 @@ public: // erase(iterator, iterator) { url u = parse_uri_reference( - "/?k0=0&k1=1&k2=&k3&k4=4444#f"); + "/?k0=0&k1=1&k2=&k3&k4=4444#f").value(); params p = u.params(pa.allocator()); p.erase(p.begin() + 2); BOOST_TEST(u.encoded_query() == @@ -299,7 +299,7 @@ public: // erase(Key) { url u = parse_uri_reference( - "/?a=1&%62=2&c=3&c=4&c=5&d=6&e=7&d=8&f=9#f"); + "/?a=1&%62=2&c=3&c=4&c=5&d=6&e=7&d=8&f=9#f").value(); params p = u.params(pa.allocator()); BOOST_TEST(p.erase("c") == 3); BOOST_TEST(u.encoded_query() == @@ -322,7 +322,7 @@ public: // emplace_back(Key, Value) // emplace_back(Key) { - url u = parse_uri_reference("/#f"); + url u = parse_uri_reference("/#f").value(); params p = u.params(pa.allocator()); p.emplace_back("k0", "0"); BOOST_TEST(u.encoded_query() == "k0=0"); @@ -357,7 +357,7 @@ public: // push_back(value_type) // pop_back() { - url u = parse_uri_reference("/#f"); + url u = parse_uri_reference("/#f").value(); params p = u.params(pa.allocator()); p.push_back({"k0", "0", true}); @@ -439,7 +439,7 @@ public: // contains(Key) { url u = parse_uri_reference( - "/?a=1&%62=2&c=3&c=4&c=5&d=6&e=7&d=8&f=9#f"); + "/?a=1&%62=2&c=3&c=4&c=5&d=6&e=7&d=8&f=9#f").value(); params p = u.params(pa.allocator()); BOOST_TEST(p.count("a") == 1); BOOST_TEST(p.count("b") == 1); @@ -467,7 +467,7 @@ public: testIterators() { url u = parse_uri_reference( - "/?a=1&bb=22&ccc=333&dddd=4444#f"); + "/?a=1&bb=22&ccc=333&dddd=4444#f").value(); params p = u.params(pa.allocator()); auto it = p.begin(); BOOST_TEST((*it).key == "a"); diff --git a/test/unit/params_encoded.cpp b/test/unit/params_encoded.cpp index d4a0aecd..e3ea2edf 100644 --- a/test/unit/params_encoded.cpp +++ b/test/unit/params_encoded.cpp @@ -27,7 +27,7 @@ public: // assign(FwdIt, FwdIt) { url u = parse_uri_reference( - "/?x#f"); + "/?x#f").value(); u.params_encoded() = { { "k1", "1", true }, { "k2", "2", true }, @@ -40,7 +40,7 @@ public: "/?k1=1&k2=2&k3=&k4&k5=55555#f"); } { - url u = parse_uri_reference("/?x#f"); + url u = parse_uri_reference("/?x#f").value(); u.params_encoded() = {}; BOOST_TEST(u.encoded_query() == ""); BOOST_TEST(u.encoded_url() == "/#f"); @@ -56,7 +56,7 @@ public: // back { url u = parse_uri_reference( - "?k0=0&k1=1&k2=&k3&k4=4444#f"); + "?k0=0&k1=1&k2=&k3&k4=4444#f").value(); params_encoded p = u.params_encoded(); BOOST_TEST(p.at(0).key == "k0"); BOOST_TEST(p.at(0).value == "0"); @@ -82,7 +82,7 @@ public: // at(Key) { url u = parse_uri_reference( - "?k0=0&k1=1&k2=&k3&k4=4444#f"); + "?k0=0&k1=1&k2=&k3&k4=4444#f").value(); params_encoded p = u.params_encoded(); BOOST_TEST(p.at("k0") == "0"); BOOST_TEST(p.at("k1") == "1"); @@ -102,7 +102,7 @@ public: // size { url u = parse_uri_reference( - "?k0=0&k1=1&k2=&k3&k4=4444#f"); + "?k0=0&k1=1&k2=&k3&k4=4444#f").value(); params_encoded p = u.params_encoded(); BOOST_TEST(! p.empty()); BOOST_TEST(p.size() == 5); @@ -121,7 +121,7 @@ public: // clear { url u = parse_uri_reference( - "/?k0=0&k1=1&k2=&k3&k4=4444#f"); + "/?k0=0&k1=1&k2=&k3&k4=4444#f").value(); params_encoded p = u.params_encoded(); p.clear(); BOOST_TEST(u.encoded_query() == ""); @@ -131,7 +131,7 @@ public: // insert(iterator, value_type) { url u = parse_uri_reference( - "/?k0=0&k2=#f"); + "/?k0=0&k2=#f").value(); params_encoded p = u.params_encoded(); auto it = p.insert(p.begin() + 1, {"k1", "1", true}); @@ -147,7 +147,7 @@ public: // insert(iterator, FwdIt, FwdIt) { url u = parse_uri_reference( - "/?k0=0&k3#f"); + "/?k0=0&k3#f").value(); params_encoded p = u.params_encoded(); auto it = p.insert(p.begin() + 1,{ {"k1", "1", true}, @@ -162,7 +162,7 @@ public: // replace(iterator, value_type) { url u = parse_uri_reference( - "/?k0=0&k1=1&k3#f"); + "/?k0=0&k1=1&k3#f").value(); params_encoded p = u.params_encoded(); auto it = p.replace( p.end() - 1, @@ -178,7 +178,7 @@ public: // replace(iterator, iterator, initializer_list) { url u = parse_uri_reference( - "/?k0=0&k1=1&k2=&k3&k4=4444#f"); + "/?k0=0&k1=1&k2=&k3&k4=4444#f").value(); params_encoded p = u.params_encoded(); auto it = p.replace( p.begin() + 1, p.begin() + 3, { @@ -195,7 +195,7 @@ public: // remove_value(iterator) { url u = parse_uri_reference( - "/?k0=0&k%31=1&k2=#f"); + "/?k0=0&k%31=1&k2=#f").value(); params_encoded p = u.params_encoded(); BOOST_TEST(p.at(1).key == "k%31"); auto it = p.remove_value(p.begin() + 1); @@ -214,7 +214,7 @@ public: // emplace_at(iterator, Key, Value) { url u = parse_uri_reference( - "/?k0=0&k%31=1&k2=#f"); + "/?k0=0&k%31=1&k2=#f").value(); params_encoded p = u.params_encoded(); auto it = p.emplace_at( p.begin() + 1, @@ -230,7 +230,7 @@ public: // emplace_at(iterator, Key) { url u = parse_uri_reference( - "/?k0=0&k1=1&k2=&k3#f"); + "/?k0=0&k1=1&k2=&k3#f").value(); params_encoded p = u.params_encoded(); auto it = p.emplace_at( p.begin() + 2, @@ -246,7 +246,7 @@ public: // emplace_before(iterator, Key, Value) { url u = parse_uri_reference( - "/?k0=0&k2=&k3#f"); + "/?k0=0&k2=&k3#f").value(); params_encoded p = u.params_encoded(); auto it = p.emplace_before( p.begin() + 1, "k1", "1"); @@ -261,7 +261,7 @@ public: // emplace_before(iterator, Key) { url u = parse_uri_reference( - "/?k0=0&k2=&k3#f"); + "/?k0=0&k2=&k3#f").value(); params_encoded p = u.params_encoded(); auto it = p.emplace_before( p.begin() + 1, "k1"); @@ -276,7 +276,7 @@ public: // erase(iterator, iterator) { url u = parse_uri_reference( - "/?k0=0&k1=1&k2=&k3&k4=4444#f"); + "/?k0=0&k1=1&k2=&k3&k4=4444#f").value(); params_encoded p = u.params_encoded(); p.erase(p.begin() + 2); BOOST_TEST(u.encoded_query() == @@ -295,7 +295,7 @@ public: // erase(Key) { url u = parse_uri_reference( - "/?a=1&%62=2&c=3&c=4&c=5&d=6&e=7&d=8&f=9#f"); + "/?a=1&%62=2&c=3&c=4&c=5&d=6&e=7&d=8&f=9#f").value(); params_encoded p = u.params_encoded(); BOOST_TEST(p.erase("c") == 3); BOOST_TEST(u.encoded_query() == @@ -318,7 +318,7 @@ public: // emplace_back(Key, Value) // emplace_back(Key) { - url u = parse_uri_reference("/#f"); + url u = parse_uri_reference("/#f").value(); params_encoded p = u.params_encoded(); p.emplace_back("k0", "0"); BOOST_TEST(u.encoded_query() == "k0=0"); @@ -353,7 +353,7 @@ public: // push_back(value_type) // pop_back() { - url u = parse_uri_reference("/#f"); + url u = parse_uri_reference("/#f").value(); params_encoded p = u.params_encoded(); p.push_back({"k0", "0", true}); @@ -435,7 +435,7 @@ public: // contains(Key) { url u = parse_uri_reference( - "/?a=1&%62=2&c=3&c=4&c=5&d=6&e=7&d=8&f=9#f"); + "/?a=1&%62=2&c=3&c=4&c=5&d=6&e=7&d=8&f=9#f").value(); params_encoded p = u.params_encoded(); BOOST_TEST(p.count("a") == 1); BOOST_TEST(p.count("b") == 1); @@ -464,7 +464,7 @@ public: { { url u = parse_uri_reference( - "/?a=1&bb=22&ccc=333&dddd=4444#f"); + "/?a=1&bb=22&ccc=333&dddd=4444#f").value(); params_encoded p = u.params_encoded(); auto it = p.begin(); BOOST_TEST((*it).key == "a"); @@ -496,7 +496,7 @@ public: // operator* { url u = parse_uri_reference( - "/?a&b=&c=3#f"); + "/?a&b=&c=3#f").value(); params_encoded p = u.params_encoded(); auto it = p.begin(); BOOST_TEST((*it).has_value == false); diff --git a/test/unit/params_encoded_view.cpp b/test/unit/params_encoded_view.cpp index 1a8b38e8..d6954b43 100644 --- a/test/unit/params_encoded_view.cpp +++ b/test/unit/params_encoded_view.cpp @@ -27,7 +27,7 @@ public: // at(Key) { url_view u = parse_uri_reference( - "?k0=0&k1=1&k2=&k3&k4=4444#f"); + "?k0=0&k1=1&k2=&k3&k4=4444#f").value(); params_encoded_view p = u.params_encoded(); BOOST_TEST(p.at("k0") == "0"); BOOST_TEST(p.at("k1") == "1"); @@ -47,7 +47,7 @@ public: // size { url_view u = parse_uri_reference( - "?k0=0&k1=1&k2=&k3&k4=4444#f"); + "?k0=0&k1=1&k2=&k3&k4=4444#f").value(); params_encoded_view p = u.params_encoded(); BOOST_TEST(! p.empty()); BOOST_TEST(p.size() == 5); @@ -73,7 +73,7 @@ public: // contains(Key) { url_view u = parse_uri_reference( - "/?a=1&%62=2&c=3&c=4&c=5&d=6&e=7&d=8&f=9#f"); + "/?a=1&%62=2&c=3&c=4&c=5&d=6&e=7&d=8&f=9#f").value(); params_encoded_view p = u.params_encoded(); BOOST_TEST(p.count("a") == 1); BOOST_TEST(p.count("%62") == 1); // pct-encoded @@ -107,7 +107,7 @@ public: // operator++(int) { url_view u = parse_uri_reference( - "/?a=1&bb=22&ccc=333&dddd=4444#f"); + "/?a=1&bb=22&ccc=333&dddd=4444#f").value(); params_encoded_view p = u.params_encoded(); auto it = p.begin(); BOOST_TEST((*it).key == "a"); @@ -122,7 +122,7 @@ public: // operator* { url_view u = parse_uri_reference( - "/?&x&y=&z=3#f"); + "/?&x&y=&z=3#f").value(); params_encoded_view p = u.params_encoded(); BOOST_TEST(p.size() == 4); @@ -156,15 +156,14 @@ public: testEncoding() { // parse_query_params(string_view) - // parse_query_params(string_view, error_code) { params_view u = parse_query_params( - "a=1&b=2+2&c=%61%70%70%6c%65").decoded(); + "a=1&b=2+2&c=%61%70%70%6c%65").value().decoded(); BOOST_TEST(u.at("b") == "2 2"); BOOST_TEST(u.at("c") == "apple"); - BOOST_TEST_THROWS(parse_query_params("#a"), - std::invalid_argument); + BOOST_TEST_THROWS(parse_query_params("#a").value(), + std::exception); } } diff --git a/test/unit/value_types.cpp b/test/unit/params_value_type.cpp similarity index 88% rename from test/unit/value_types.cpp rename to test/unit/params_value_type.cpp index f601d116..046f6ad2 100644 --- a/test/unit/value_types.cpp +++ b/test/unit/params_value_type.cpp @@ -8,4 +8,4 @@ // // Test that header file is self-contained. -#include +#include diff --git a/test/unit/params_view.cpp b/test/unit/params_view.cpp index 71d4f260..1bab880f 100644 --- a/test/unit/params_view.cpp +++ b/test/unit/params_view.cpp @@ -30,7 +30,7 @@ public: // at(Key) { url_view u = parse_uri_reference( - "?k0=0&k1=1&k2=&k3&k4=4444#f"); + "?k0=0&k1=1&k2=&k3&k4=4444#f").value(); params_view p = u.params(pa.allocator()); BOOST_TEST(p.at("k0") == "0"); BOOST_TEST(p.at("k1") == "1"); @@ -50,7 +50,7 @@ public: // size { url_view u = parse_uri_reference( - "?k0=0&k1=1&k2=&k3&k4=4444#f"); + "?k0=0&k1=1&k2=&k3&k4=4444#f").value(); params_view p = u.params(pa.allocator()); BOOST_TEST(! p.empty()); BOOST_TEST(p.size() == 5); @@ -76,7 +76,7 @@ public: // contains(Key) { url_view u = parse_uri_reference( - "/?a=1&%62=2&c=3&c=4&c=5&d=6&e=7&d=8&f=9#f"); + "/?a=1&%62=2&c=3&c=4&c=5&d=6&e=7&d=8&f=9#f").value(); params_view p = u.params(pa.allocator()); BOOST_TEST(p.count("a") == 1); BOOST_TEST(p.count("b") == 1); @@ -109,7 +109,7 @@ public: // operator++(int) { url_view u = parse_uri_reference( - "/?a=1&bb=22&ccc=333&dddd=4444#f"); + "/?a=1&bb=22&ccc=333&dddd=4444#f").value(); params_view p = u.params(pa.allocator()); auto it = p.begin(); BOOST_TEST((*it).key == "a"); @@ -124,7 +124,7 @@ public: // operator* { url_view u = parse_uri_reference( - "/?&x&y=&z=3#f"); + "/?&x&y=&z=3#f").value(); params_view p = u.params(); BOOST_TEST(p.size() == 4); auto it = p.begin(); @@ -158,7 +158,7 @@ public: { { params_view u = parse_query_params( - "a=1&b=2+2&c=%61%70%70%6c%65").decoded(); + "a=1&b=2+2&c=%61%70%70%6c%65").value().decoded(); BOOST_TEST(u.at("b") == "2 2"); BOOST_TEST(u.at("c") == "apple"); } diff --git a/test/unit/pct_encoding_types.cpp b/test/unit/pct_encoding_types.cpp new file mode 100644 index 00000000..d7f87c93 --- /dev/null +++ b/test/unit/pct_encoding_types.cpp @@ -0,0 +1,11 @@ +// +// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Official repository: https://github.com/CPPAlliance/url +// + +// Test that header file is self-contained. +#include diff --git a/test/unit/limits.cpp b/test/unit/rfc/relative_ref_bnf.cpp similarity index 56% rename from test/unit/limits.cpp rename to test/unit/rfc/relative_ref_bnf.cpp index d22deb9d..f84b7a1f 100644 --- a/test/unit/limits.cpp +++ b/test/unit/rfc/relative_ref_bnf.cpp @@ -7,25 +7,5 @@ // Official repository: https://github.com/CPPAlliance/url // -#include - -#include "test_suite.hpp" - -namespace boost { -namespace urls { - -class limits_test -{ -public: - void - run() - { - } -}; - -TEST_SUITE( - limits_test, - "boost.url.limits"); - -} // urls -} // boost +// Test that header file is self-contained. +#include diff --git a/test/unit/segments.cpp b/test/unit/segments.cpp index c2405718..4f59171a 100644 --- a/test/unit/segments.cpp +++ b/test/unit/segments.cpp @@ -46,7 +46,7 @@ public: testMembers() { url_view const u0 = parse_uri( - "x://y/path/to/the/file.txt?q#f"); + "x://y/path/to/the/file.txt?q#f").value(); { url u = u0; @@ -60,7 +60,7 @@ public: testElementAccess() { url_view const u0 = parse_relative_ref( - "/path/to/the/file.txt"); + "/path/to/the/file.txt").value(); // at { @@ -154,7 +154,7 @@ public: testIterators() { url_view const u0 = parse_uri( - "x://y/path/to/the/file.txt"); + "x://y/path/to/the/file.txt").value(); // (default-ctor) { @@ -232,7 +232,7 @@ public: testCapacity() { url_view const u0 = parse_uri( - "x://y/path/to/the/file.txt"); + "x://y/path/to/the/file.txt").value(); // empty { @@ -260,7 +260,7 @@ public: { // clear { - url u = parse_uri("x://y/path/to/the/file.txt"); + url u = parse_uri("x://y/path/to/the/file.txt").value(); auto se = u.segments(p_.allocator()); BOOST_TEST(! se.empty()); @@ -274,7 +274,7 @@ public: // insert( const_iterator, string_view ) { - url u = parse_uri("x://y/path/file.txt?q#f"); + url u = parse_uri("x://y/path/file.txt?q#f").value(); auto se = u.segments(p_.allocator()); auto const& cs(se); @@ -302,7 +302,7 @@ public: { // rootless - url u = parse_uri("x:path/file.txt?q#f"); + url u = parse_uri("x:path/file.txt?q#f").value(); auto se = u.segments(p_.allocator()); auto const& cs(se); @@ -330,7 +330,7 @@ public: // insert( const_iterator, FwdIt, FwdIt ) { - url u = parse_uri("x://y/path/file.txt?q#f"); + url u = parse_uri("x://y/path/file.txt?q#f").value(); auto se = u.segments(p_.allocator()); auto const& cs(se); @@ -350,7 +350,7 @@ public: } { // rootless - url u = parse_uri("x:the/file.txt?q#f"); + url u = parse_uri("x:the/file.txt?q#f").value(); auto se = u.segments(p_.allocator()); auto const& cs(se); @@ -371,7 +371,7 @@ public: // insert( const_iterator, initializer_list ) { - url u = parse_uri("x://y/path/file.txt?q#f"); + url u = parse_uri("x://y/path/file.txt?q#f").value(); auto se = u.segments(p_.allocator()); auto const& cs(se); @@ -387,7 +387,7 @@ public: // erase( const_iterator ) { - url u = parse_uri("x://y/path/to/the/file.txt?q#f"); + url u = parse_uri("x://y/path/to/the/file.txt?q#f").value(); auto se = u.segments(p_.allocator()); se.erase(se.begin() + 1); @@ -413,7 +413,8 @@ public: // erase( const_iterator, const_iterator ) { - url u = parse_uri("x://y/home/etc/path/to/the/file.txt?q#f"); + url u = parse_uri( + "x://y/home/etc/path/to/the/file.txt?q#f").value(); auto se = u.segments(p_.allocator()); se.erase(se.begin(), se.begin() + 2); @@ -428,7 +429,8 @@ public: // replace(iterator, iterator, initializer-list) { // initializer_list - url u = parse_relative_ref("/a/b/c/d/e/f/g"); + url u = parse_relative_ref( + "/a/b/c/d/e/f/g").value(); segments ss = u.segments(); auto it = ss.replace( ss.begin() + 1, @@ -440,7 +442,8 @@ public: } { // initializer_list - url u = parse_relative_ref("/a/b/c/d/e/f/g"); + url u = parse_relative_ref( + "/a/b/c/d/e/f/g").value(); segments ss = u.segments(); auto it = ss.replace( ss.begin() + 1, @@ -456,7 +459,7 @@ public: // push_back(string_view) // push_back(String) { - url u = parse_relative_ref(""); + url u = parse_relative_ref("").value(); auto se = u.segments(p_.allocator()); se.push_back("path"); BOOST_TEST(u.encoded_path() == "/path"); @@ -468,7 +471,8 @@ public: // pop_back { - url u = parse_uri("x://y/path/to/file.txt?q#f"); + url u = parse_uri( + "x://y/path/to/file.txt?q#f").value(); auto se = u.segments(p_.allocator()); BOOST_TEST(se.size() == 3); diff --git a/test/unit/segments_encoded.cpp b/test/unit/segments_encoded.cpp index f9666f5f..537cfa56 100644 --- a/test/unit/segments_encoded.cpp +++ b/test/unit/segments_encoded.cpp @@ -51,7 +51,7 @@ public: testMembers() { url_view const u0 = parse_uri( - "x://y/path/to/the/file.txt?q#f"); + "x://y/path/to/the/file.txt?q#f").value(); { url u = u0; @@ -65,7 +65,7 @@ public: testElementAccess() { url_view const u0 = parse_relative_ref( - "/path/to/the/file.txt"); + "/path/to/the/file.txt").value(); // at { @@ -135,7 +135,7 @@ public: testIterators() { url_view const u0 = parse_uri( - "x://y/path/to/the/file.txt"); + "x://y/path/to/the/file.txt").value(); // (default-ctor) { @@ -208,7 +208,7 @@ public: testCapacity() { url_view const u0 = parse_uri( - "x://y/path/to/the/file.txt"); + "x://y/path/to/the/file.txt").value(); // empty { @@ -231,7 +231,7 @@ public: { // clear { - url u = parse_uri("x://y/path/to/the/file.txt"); + url u = parse_uri("x://y/path/to/the/file.txt").value(); segments_encoded se = u.encoded_segments(); BOOST_TEST(! se.empty()); @@ -245,7 +245,7 @@ public: // insert( const_iterator, string_view ) { - url u = parse_uri("x://y/path/file.txt?q#f"); + url u = parse_uri("x://y/path/file.txt?q#f").value(); segments_encoded se = u.encoded_segments(); segments_encoded const& cs(se); @@ -277,7 +277,7 @@ public: { // rootless - url u = parse_uri("x:path/file.txt?q#f"); + url u = parse_uri("x:path/file.txt?q#f").value(); segments_encoded se = u.encoded_segments(); segments_encoded const& cs(se); @@ -309,7 +309,7 @@ public: // insert( const_iterator, FwdIt, FwdIt ) { - url u = parse_uri("x://y/path/file.txt?q#f"); + url u = parse_uri("x://y/path/file.txt?q#f").value(); segments_encoded se = u.encoded_segments(); segments_encoded const& cs(se); @@ -334,7 +334,7 @@ public: } { // rootless - url u = parse_uri("x:the/file.txt?q#f"); + url u = parse_uri("x:the/file.txt?q#f").value(); segments_encoded se = u.encoded_segments(); segments_encoded const& cs(se); @@ -360,7 +360,7 @@ public: // insert( const_iterator, initializer_list ) { - url u = parse_uri("x://y/path/file.txt?q#f"); + url u = parse_uri("x://y/path/file.txt?q#f").value(); segments_encoded se = u.encoded_segments(); segments_encoded const& cs(se); @@ -376,7 +376,7 @@ public: // erase( const_iterator ) { - url u = parse_uri("x://y/path/to/the/file.txt?q#f"); + url u = parse_uri("x://y/path/to/the/file.txt?q#f").value(); segments_encoded se = u.encoded_segments(); se.erase(se.begin() + 1); @@ -402,7 +402,7 @@ public: // erase( const_iterator, const_iterator ) { - url u = parse_uri("x://y/home/etc/path/to/the/file.txt?q#f"); + url u = parse_uri("x://y/home/etc/path/to/the/file.txt?q#f").value(); segments_encoded se = u.encoded_segments(); se.erase(se.begin(), se.begin() + 2); @@ -417,7 +417,7 @@ public: // replace(iterator, iterator, initializer-list) { // initializer_list - url u = parse_relative_ref("/a/b/c/d/e/f/g"); + url u = parse_relative_ref("/a/b/c/d/e/f/g").value(); segments_encoded se = u.encoded_segments(); auto it = se.replace( se.begin() + 1, @@ -429,7 +429,7 @@ public: } { // initializer_list - url u = parse_relative_ref("/a/b/c/d/e/f/g"); + url u = parse_relative_ref("/a/b/c/d/e/f/g").value(); segments_encoded se = u.encoded_segments(); auto it = se.replace( se.begin() + 1, @@ -444,7 +444,7 @@ public: // push_back { - url u = parse_uri("x://y/home/etc/path/to/the/file.txt?q#f"); + url u = parse_uri("x://y/home/etc/path/to/the/file.txt?q#f").value(); segments_encoded se = u.encoded_segments(); BOOST_TEST_THROWS(se.push_back("%"), std::invalid_argument); @@ -454,7 +454,7 @@ public: // pop_back { - url u = parse_uri("x://y/path/to/file.txt?q#f"); + url u = parse_uri("x://y/path/to/file.txt?q#f").value(); segments_encoded se = u.encoded_segments(); BOOST_TEST(se.size() == 3); diff --git a/test/unit/segments_encoded_view.cpp b/test/unit/segments_encoded_view.cpp index e525db18..cdab21f1 100644 --- a/test/unit/segments_encoded_view.cpp +++ b/test/unit/segments_encoded_view.cpp @@ -10,8 +10,10 @@ // Test that header file is self-contained. #include +#include #include "test_suite.hpp" #include +#include #include #include #include @@ -372,6 +374,22 @@ public: testExamples() { { + segments_encoded_view sev = parse_path( "/path/to/file.txt" ).value(); + + for( auto it = sev.begin(); it != sev.end(); ++it ) + std::cout << *it << std::endl; + } + + { + url_view u = parse_uri( "http://example.com/path/to/file.txt" ).value(); + + segments_encoded_view sev = u.encoded_segments(); + + std::cout << sev << std::endl; + } + //--- + + { segments_encoded_view sev = parse_path( "/%70%61%74%68/%74%6f/%66%69%6c%65%2e%74%78%74" ).value(); segments_view sv = sev.decoded(); diff --git a/test/unit/static_url.cpp b/test/unit/static_url.cpp index f48a0df3..bd9c024c 100644 --- a/test/unit/static_url.cpp +++ b/test/unit/static_url.cpp @@ -37,10 +37,10 @@ public: BOOST_TEST(u.encoded_url().empty()); } - url c1 = parse_uri("http://1"); - url_t c2 = parse_uri("http://2"); - url_view c3 = parse_uri("http://3"); - url_view c4 = parse_uri("ftp://"); + url c1 = parse_uri("http://1").value(); + url_t c2 = parse_uri("http://2").value(); + url_view c3 = parse_uri("http://3").value(); + url_view c4 = parse_uri("ftp://").value(); // copy ctor { @@ -136,7 +136,7 @@ public: { url_view uv; BOOST_TEST_NO_THROW( uv = parse_uri( - "http://user:pass@www.boost.org:8080/x/y/z?a=b&c=3#frag")); + "http://user:pass@www.boost.org:8080/x/y/z?a=b&c=3#frag").value()); url_t u(uv); BOOST_TEST(u.encoded_origin() == "http://user:pass@www.boost.org:8080"); diff --git a/test/unit/url.cpp b/test/unit/url.cpp index 09c37522..c2363a2f 100644 --- a/test/unit/url.cpp +++ b/test/unit/url.cpp @@ -25,27 +25,27 @@ public: { // copy { - url u = parse_uri_reference("x://y/z?q#f"); + url u = parse_uri_reference("x://y/z?q#f").value(); url u2(u); BOOST_TEST(u2.encoded_url() == u.encoded_url()); } { - url u = parse_uri_reference("x://y/z?q#f"); - url u2 = parse_relative_ref("./"); + url u = parse_uri_reference("x://y/z?q#f").value(); + url u2 = parse_relative_ref("./").value(); u2 = u; BOOST_TEST(u2.encoded_url() == u.encoded_url()); } // move { - url u = parse_uri_reference("x://y/z?q#f"); + url u = parse_uri_reference("x://y/z?q#f").value(); url u2(std::move(u)); BOOST_TEST(u.empty()); BOOST_TEST(u2.encoded_url() == "x://y/z?q#f"); } { - url u = parse_uri_reference("x://y/z?q#f"); - url u2 = parse_relative_ref("./"); + url u = parse_uri_reference("x://y/z?q#f").value(); + url u2 = parse_relative_ref("./").value(); u2 = std::move(u); BOOST_TEST(u.empty()); BOOST_TEST(u2.encoded_url() == "x://y/z?q#f"); @@ -67,7 +67,7 @@ public: // clear { url u = parse_uri( - "http://example.com/index.htm?q#f"); + "http://example.com/index.htm?q#f").value(); BOOST_TEST(u.capacity_in_bytes() > 0); BOOST_TEST(! u.empty()); u.clear(); @@ -85,7 +85,7 @@ public: auto const remove = []( string_view s1, string_view s2) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST( u.remove_scheme().encoded_url() == s2); BOOST_TEST(u.scheme().empty()); @@ -97,7 +97,7 @@ public: string_view s1, string_view s2, string_view s3, scheme id) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST( u.set_scheme(s2).encoded_url() == s3); BOOST_TEST(u.scheme() == s2); @@ -108,7 +108,7 @@ public: string_view s1, scheme id, string_view s2) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST( u.set_scheme(id).encoded_url() == s2); BOOST_TEST(u.scheme_id() == id); @@ -163,7 +163,7 @@ public: auto const remove = []( string_view s1, string_view s2) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST( u.remove_user().encoded_url() == s2); BOOST_TEST(u.encoded_user().empty()); @@ -174,7 +174,7 @@ public: string_view s1, string_view s2, string_view s3) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST( u.set_user(s2).encoded_url() == s3); BOOST_TEST(u.user() == s2); @@ -185,7 +185,7 @@ public: string_view s1, string_view s2, string_view s3) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST(u.set_encoded_user( s2).encoded_url() == s3); BOOST_TEST(u.encoded_user() == s2); @@ -305,7 +305,7 @@ public: auto const remove = []( string_view s1, string_view s2) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST( u.remove_password().encoded_url() == s2); BOOST_TEST(u.encoded_password() == ""); @@ -316,7 +316,7 @@ public: string_view s1, string_view s2, string_view s3) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST( u.set_password(s2).encoded_url() == s3); BOOST_TEST(u.password() == s2); @@ -327,7 +327,7 @@ public: string_view s1, string_view s2, string_view s3) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST(u.set_encoded_password( s2).encoded_url() == s3); BOOST_TEST(u.encoded_password() == s2); @@ -430,7 +430,7 @@ public: auto const remove = []( string_view s1, string_view s2) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST(u.remove_userinfo().encoded_url() == s2); BOOST_TEST(u.encoded_userinfo().empty()); BOOST_TEST(u.userinfo().empty()); @@ -440,7 +440,7 @@ public: auto const set = [](string_view s1, string_view s2, string_view s3) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST( u.set_userinfo(s2).encoded_url() == s3); BOOST_TEST(u.userinfo() == s2); @@ -450,7 +450,7 @@ public: auto const enc = [](string_view s1, string_view s2, string_view s3) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST( u.set_encoded_userinfo(s2).encoded_url() == s3); BOOST_TEST(u.encoded_userinfo() == s2); @@ -592,7 +592,7 @@ public: string_view s2, string_view s3, host_type ht = host_type::name) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST( u.set_encoded_host(s2).encoded_url() == s3); BOOST_TEST(u.encoded_host() == s2); @@ -601,7 +601,7 @@ public: auto const bad = [](string_view s1, string_view s2) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST_THROWS(u.set_encoded_host(s2), std::invalid_argument); }; @@ -693,7 +693,7 @@ public: auto const remove = []( string_view s1, string_view s2) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST( u.remove_port().encoded_url() == s2); BOOST_TEST(! u.has_port()); @@ -704,7 +704,7 @@ public: auto const setn = [](string_view s1, std::uint16_t n, string_view s2) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST( u.set_port(n).encoded_url() == s2); BOOST_TEST(u.has_port()); @@ -715,7 +715,7 @@ public: std::uint16_t n, string_view s2, string_view s3) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST( u.set_port(s2).encoded_url() == s3); BOOST_TEST(u.has_port()); @@ -834,7 +834,7 @@ public: auto const remove = []( string_view s1, string_view s2) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST(u.remove_authority().encoded_url() == s2); BOOST_TEST(u.encoded_authority().empty()); BOOST_TEST(! u.has_authority()); @@ -843,7 +843,7 @@ public: auto const set = [](string_view s1, string_view s2, string_view s3) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST( u.set_encoded_authority(s2).encoded_url() == s3); BOOST_TEST(u.encoded_authority() == s2); @@ -958,7 +958,7 @@ public: auto const remove = []( string_view s1, string_view s2) { - url u = parse_uri_reference(s1); + url u = parse_uri_reference(s1).value(); BOOST_TEST(u.remove_origin().encoded_url() == s2); BOOST_TEST(u.encoded_origin().empty()); BOOST_TEST(! u.has_authority()); @@ -986,7 +986,7 @@ public: // encoded_segment { url u = parse_uri( - "http://www.example.com/path/to/file.txt"); + "http://www.example.com/path/to/file.txt").value(); BOOST_TEST(u.encoded_segment(0) == "path"); BOOST_TEST(u.encoded_segment(1) == "to"); BOOST_TEST(u.encoded_segment(2) == "file.txt"); @@ -996,14 +996,14 @@ public: // set_encoded_path { // empty - url u = parse_uri("x://y/path/to/file.txt?q#f"); + url u = parse_uri("x://y/path/to/file.txt?q#f").value(); u.set_encoded_path(""); BOOST_TEST(u.encoded_path() == ""); BOOST_TEST(u.encoded_url() == "x://y?q#f"); } { // path-abempty - url u = parse_uri("x://y/path/to/file.txt?q#f"); + url u = parse_uri("x://y/path/to/file.txt?q#f").value(); u.set_encoded_path("/x"); BOOST_TEST(u.encoded_path() == "/x"); BOOST_TEST(u.encoded_url() == "x://y/x?q#f"); @@ -1012,7 +1012,7 @@ public: } { // path-absolute - url u = parse_relative_ref("/path/to/file.txt"); + url u = parse_relative_ref("/path/to/file.txt").value(); u.set_encoded_path("/home/file.txt"); BOOST_TEST(u.encoded_path() == "/home/file.txt"); BOOST_TEST(u.encoded_url() == "/home/file.txt"); @@ -1023,7 +1023,7 @@ public: } { // path-rootless - url u = parse_uri("x:mailto"); + url u = parse_uri("x:mailto").value(); u.set_encoded_path("file.txt"); BOOST_TEST(u.encoded_path() == "file.txt"); BOOST_TEST(u.encoded_url() == "x:file.txt"); @@ -1037,7 +1037,7 @@ public: } { // path-noscheme - url u = parse_relative_ref("mailto"); + url u = parse_relative_ref("mailto").value(); u.set_encoded_path("file.txt"); BOOST_TEST(u.encoded_path() == "file.txt"); BOOST_TEST(u.encoded_url() == "file.txt"); @@ -1054,7 +1054,7 @@ public: string_view arg, string_view match) { - url u = parse_uri_reference(s0); + url u = parse_uri_reference(s0).value(); u.set_encoded_path(arg); BOOST_TEST( u.encoded_url() == match); @@ -1096,7 +1096,7 @@ public: string_view arg, string_view match) { - url u = parse_uri_reference(s0); + url u = parse_uri_reference(s0).value(); u.set_path(arg); BOOST_TEST( u.encoded_url() == match); @@ -1146,7 +1146,7 @@ public: testOstream() { url u = parse_uri( - "http://example.com/index.htm?q#f"); + "http://example.com/index.htm?q#f").value(); std::stringstream ss; ss << u; BOOST_TEST(ss.str() == diff --git a/test/unit/url_view.cpp b/test/unit/url_view.cpp index 168ef3b5..6f83d698 100644 --- a/test/unit/url_view.cpp +++ b/test/unit/url_view.cpp @@ -26,18 +26,20 @@ public: void testParse() { + // VFALCO TODO +#if 0 // absolute-URI { string_view s = "http://user:pass@www.example.com:80/dir/file.txt?query"; { error_code ec; - parse_absolute_uri(s, ec); + parse_absolute_uri(s, ec).value(); BOOST_TEST(! ec.failed()); } { std::error_code ec; - parse_absolute_uri(s, ec); + parse_absolute_uri(s, ec).value(); BOOST_TEST(! ec); } BOOST_TEST_NO_THROW(parse_absolute_uri(s)); @@ -139,6 +141,7 @@ public: "//host/path/to/foo.htm"); BOOST_TEST(u.encoded_userinfo() == ""); } +#endif } void @@ -155,24 +158,21 @@ public: testScheme() { { - auto u = parse_uri( - "http://"); + auto u = parse_uri("http://").value(); BOOST_TEST(u.has_scheme()); BOOST_TEST(u.scheme() == "http"); BOOST_TEST( u.scheme_id() == scheme::http); } { - auto u = parse_uri( - "ou812://"); + auto u = parse_uri("ou812://").value(); BOOST_TEST(u.has_scheme()); BOOST_TEST(u.scheme() == "ou812"); BOOST_TEST( u.scheme_id() == scheme::unknown); } { - auto u = parse_relative_ref( - "/x"); + auto u = parse_relative_ref("/x").value(); BOOST_TEST(! u.has_scheme()); BOOST_TEST(u.scheme() == ""); BOOST_TEST( @@ -188,7 +188,7 @@ public: { BOOST_TEST_NO_THROW( [s]{ - auto u = parse_uri(s); + auto u = parse_uri(s).value(); BOOST_TEST(! u.has_authority()); }()); }; @@ -197,7 +197,7 @@ public: { BOOST_TEST_NO_THROW( [&]{ - auto u = parse_uri(s); + auto u = parse_uri(s).value(); BOOST_TEST(u.has_authority()); BOOST_TEST( u.encoded_authority() == m); @@ -218,8 +218,7 @@ public: yes("http://@x", "@x"); { - auto u = parse_uri( - "http:/path"); + auto u = parse_uri("http:/path").value(); BOOST_TEST(u.encoded_host() == ""); } } @@ -232,7 +231,7 @@ public: { BOOST_TEST_NO_THROW( [s]{ - auto u = parse_uri(s); + auto u = parse_uri(s).value(); BOOST_TEST(! u.has_userinfo()); }()); }; @@ -243,7 +242,7 @@ public: { BOOST_TEST_NO_THROW( [&]{ - auto u = parse_uri(s); + auto u = parse_uri(s).value(); BOOST_TEST(u.has_userinfo()); BOOST_TEST( u.encoded_userinfo() == m1); @@ -270,7 +269,7 @@ public: yes("http://%61%3a%62@x", "%61%3a%62", "a:b"); { - auto u = parse_uri("x://@"); + auto u = parse_uri("x://@").value(); BOOST_TEST(u.has_userinfo()); BOOST_TEST(u.encoded_userinfo() == ""); BOOST_TEST(u.userinfo() == ""); @@ -281,7 +280,7 @@ public: BOOST_TEST(u.password() == ""); } { - auto u = parse_uri("x://:@"); + auto u = parse_uri("x://:@").value(); BOOST_TEST(u.has_userinfo()); BOOST_TEST(u.encoded_userinfo() == ":"); BOOST_TEST(u.userinfo() == ":"); @@ -292,7 +291,7 @@ public: BOOST_TEST(u.password() == ""); } { - auto u = parse_uri("x://a%41:@"); + auto u = parse_uri("x://a%41:@").value(); BOOST_TEST(u.has_userinfo()); BOOST_TEST(u.encoded_userinfo() == "a%41:"); BOOST_TEST(u.encoded_user() == "a%41"); @@ -302,7 +301,7 @@ public: BOOST_TEST(u.password() == ""); } { - auto u = parse_uri("x://:b%42@"); + auto u = parse_uri("x://:b%42@").value(); BOOST_TEST(u.has_userinfo()); BOOST_TEST(u.encoded_userinfo() == ":b%42"); BOOST_TEST(u.encoded_user() == ""); @@ -312,7 +311,7 @@ public: BOOST_TEST(u.password() == "bB"); } { - auto u = parse_uri("x://a:b@"); + auto u = parse_uri("x://a:b@").value(); BOOST_TEST(u.has_userinfo()); BOOST_TEST(u.encoded_userinfo() == "a:b"); BOOST_TEST(u.encoded_user() == "a"); @@ -320,7 +319,7 @@ public: BOOST_TEST(u.encoded_password() == "b"); } { - auto u = parse_uri("x://%3a:%3a@"); + auto u = parse_uri("x://%3a:%3a@").value(); BOOST_TEST(u.has_userinfo()); BOOST_TEST(u.encoded_userinfo() == "%3a:%3a"); BOOST_TEST(u.userinfo() == ":::"); @@ -331,7 +330,7 @@ public: BOOST_TEST(u.password() == ":"); } { - auto u = parse_uri("x://%2525@"); + auto u = parse_uri("x://%2525@").value(); BOOST_TEST(u.has_userinfo()); BOOST_TEST(u.encoded_userinfo() == "%2525"); BOOST_TEST(u.userinfo() == "%25"); @@ -347,8 +346,7 @@ public: testHost() { { - auto u = parse_uri( - "res:foo/"); + auto u = parse_uri("res:foo/").value(); BOOST_TEST(u.host_type() == host_type::none); BOOST_TEST(u.encoded_host() == @@ -361,24 +359,21 @@ public: u.ipv_future() == ""); } { - auto u = parse_uri( - "http://"); + auto u = parse_uri("http://").value(); BOOST_TEST(u.host_type() == host_type::name); BOOST_TEST(u.encoded_host() == ""); } { - auto u = parse_uri( - "http:///"); + auto u = parse_uri("http:///").value(); BOOST_TEST(u.host_type() == host_type::name); BOOST_TEST(u.encoded_host() == ""); } { - auto u = parse_uri( - "http://www.example.com/"); + auto u = parse_uri("http://www.example.com/").value(); BOOST_TEST(u.host_type() == host_type::name); BOOST_TEST(u.encoded_host() == @@ -387,8 +382,7 @@ public: "www.example.com"); } { - auto u = parse_uri( - "http://192.168.0.1/"); + auto u = parse_uri("http://192.168.0.1/").value(); BOOST_TEST(u.host_type() == host_type::ipv4); BOOST_TEST(u.encoded_host() == @@ -401,7 +395,7 @@ public: } { auto u = parse_uri( - "http://[1::6:192.168.0.1]:8080/"); + "http://[1::6:192.168.0.1]:8080/").value(); BOOST_TEST(u.host_type() == host_type::ipv6); BOOST_TEST(u.encoded_host() == @@ -413,7 +407,7 @@ public: } { auto u = parse_uri( - "http://[v1.x]:8080/"); + "http://[v1.x]:8080/").value(); BOOST_TEST(u.host_type() == host_type::ipvfuture); BOOST_TEST(u.encoded_host() == @@ -429,64 +423,55 @@ public: testPort() { { - auto u = parse_uri( - "http://"); + auto u = parse_uri("http://").value(); BOOST_TEST(! u.has_port()); BOOST_TEST(u.port() == ""); BOOST_TEST(u.port_number() == 0); } { - auto u = parse_uri( - "http://www"); + auto u = parse_uri("http://www").value(); BOOST_TEST(! u.has_port()); BOOST_TEST(u.port() == ""); BOOST_TEST(u.port_number() == 0); } { - auto u = parse_uri( - "http://:"); + auto u = parse_uri("http://:").value(); BOOST_TEST(u.has_port()); BOOST_TEST(u.port() == ""); BOOST_TEST(u.port_number() == 0); } { - auto u = parse_uri( - "http://:0"); + auto u = parse_uri("http://:0").value(); BOOST_TEST(u.has_port()); BOOST_TEST(u.port() == "0"); BOOST_TEST(u.port_number() == 0); } { - auto u = parse_uri( - "http://:42"); + auto u = parse_uri("http://:42").value(); BOOST_TEST(u.has_port()); BOOST_TEST(u.port() == "42"); BOOST_TEST(u.port_number() == 42); } { - auto u = parse_uri( - "http://:00000"); + auto u = parse_uri("http://:00000").value(); BOOST_TEST(u.has_port()); BOOST_TEST(u.port() == "00000"); BOOST_TEST(u.port_number() == 0); } { - auto u = parse_uri( - "http://:000001"); + auto u = parse_uri("http://:000001").value(); BOOST_TEST(u.has_port()); BOOST_TEST(u.port() == "000001"); BOOST_TEST(u.port_number() == 1); } { - auto u = parse_uri( - "http://:65535"); + auto u = parse_uri("http://:65535").value(); BOOST_TEST(u.has_port()); BOOST_TEST(u.port() == "65535"); BOOST_TEST(u.port_number() == 65535); } { - auto u = parse_uri( - "http://:65536"); + auto u = parse_uri("http://:65536").value(); BOOST_TEST(u.has_port()); BOOST_TEST(u.port() == "65536"); BOOST_TEST(u.port_number() == 0); @@ -497,32 +482,27 @@ public: testHostAndPort() { { - auto u = parse_uri( - "http://x:1"); + auto u = parse_uri("http://x:1").value(); BOOST_TEST(u.encoded_host_and_port() == "x:1"); } { - auto u = parse_uri( - "http://x%3a:1"); + auto u = parse_uri("http://x%3a:1").value(); BOOST_TEST(u.encoded_host_and_port() == "x%3a:1"); } { - auto u = parse_uri( - "http://:1"); + auto u = parse_uri("http://:1").value(); BOOST_TEST(u.encoded_host_and_port() == ":1"); } { - auto u = parse_uri( - "http://:000001"); + auto u = parse_uri("http://:000001").value(); BOOST_TEST(u.encoded_host_and_port() == ":000001"); } { - auto u = parse_uri( - "http://xyz:99999"); + auto u = parse_uri("http://xyz:99999").value(); BOOST_TEST(u.encoded_host_and_port() == "xyz:99999"); } @@ -533,11 +513,11 @@ public: { BOOST_TEST(parse_uri( "x://p:q@a.b.c/f.z?a=b#frag" - ).encoded_origin() == "x://p:q@a.b.c"); + ).value().encoded_origin() == "x://p:q@a.b.c"); BOOST_TEST(parse_relative_ref( - "/file.txt").encoded_origin() == ""); + "/file.txt").value().encoded_origin() == ""); BOOST_TEST(parse_uri("x:/path/file/txt" - ).encoded_origin() == ""); + ).value().encoded_origin() == ""); } void @@ -547,7 +527,7 @@ public: url_view u; BOOST_TEST_NO_THROW( u = parse_relative_ref( - "/path/to/file.htm")); + "/path/to/file.htm").value()); auto const p = u.encoded_segments(); BOOST_TEST(! p.empty()); BOOST_TEST(p.size() == 3); @@ -564,7 +544,7 @@ public: // encoded_segment { url_view u = parse_uri( - "http://www.example.com/path/to/file.txt"); + "http://www.example.com/path/to/file.txt").value(); BOOST_TEST(u.encoded_segment(0) == "path"); BOOST_TEST(u.encoded_segment(1) == "to"); BOOST_TEST(u.encoded_segment(2) == "file.txt"); @@ -576,71 +556,61 @@ public: testQuery() { { - auto u = parse_uri( - "http://"); + auto u = parse_uri("http://").value(); BOOST_TEST(! u.has_query()); BOOST_TEST(u.encoded_query() == ""); BOOST_TEST(u.query() == ""); } { - auto u = parse_uri( - "http://?"); + auto u = parse_uri("http://?").value(); BOOST_TEST(u.has_query()); BOOST_TEST(u.encoded_query() == ""); BOOST_TEST(u.query() == ""); } { - auto u = parse_uri( - "http://?k"); + auto u = parse_uri("http://?k").value(); BOOST_TEST(u.has_query()); BOOST_TEST(u.encoded_query() == "k"); BOOST_TEST(u.query() == "k"); } { - auto u = parse_uri( - "http://?k="); + auto u = parse_uri("http://?k=").value(); BOOST_TEST(u.has_query()); BOOST_TEST(u.encoded_query() == "k="); BOOST_TEST(u.query() == "k="); } { - auto u = parse_uri( - "http://?#"); + auto u = parse_uri("http://?#").value(); BOOST_TEST(u.has_query()); BOOST_TEST(u.encoded_query() == ""); BOOST_TEST(u.query() == ""); } { - auto u = parse_uri( - "http://?%3f"); + auto u = parse_uri("http://?%3f").value(); BOOST_TEST(u.has_query()); BOOST_TEST(u.encoded_query() == "%3f"); BOOST_TEST(u.query() == "?"); } { - auto u = parse_uri( - "http://?%25"); + auto u = parse_uri("http://?%25").value(); BOOST_TEST(u.has_query()); BOOST_TEST(u.encoded_query() == "%25"); BOOST_TEST(u.query() == "%"); } { - auto u = parse_uri( - "http://?&"); + auto u = parse_uri("http://?&").value(); BOOST_TEST(u.has_query()); BOOST_TEST(u.encoded_query() == "&"); BOOST_TEST(u.query() == "&"); } { - auto u = parse_uri( - "http://?%26"); + auto u = parse_uri("http://?%26").value(); BOOST_TEST(u.has_query()); BOOST_TEST(u.encoded_query() == "%26"); BOOST_TEST(u.query() == "&"); } { - auto u = parse_uri( - "http://?a%3db%26"); + auto u = parse_uri("http://?a%3db%26").value(); BOOST_TEST(u.has_query()); BOOST_TEST(u.encoded_query() == "a%3db%26"); BOOST_TEST(u.query() == "a=b&"); @@ -653,36 +623,31 @@ public: testFragment() { { - auto u = parse_uri( - "http://"); + auto u = parse_uri("http://").value(); BOOST_TEST(! u.has_fragment()); BOOST_TEST(u.encoded_fragment() == ""); BOOST_TEST(u.fragment() == ""); } { - auto u = parse_uri( - "http://#"); + auto u = parse_uri("http://#").value(); BOOST_TEST(u.has_fragment()); BOOST_TEST(u.encoded_fragment() == ""); BOOST_TEST(u.fragment() == ""); } { - auto u = parse_uri( - "http://#x"); + auto u = parse_uri("http://#x").value(); BOOST_TEST(u.has_fragment()); BOOST_TEST(u.encoded_fragment() == "x"); BOOST_TEST(u.fragment() == "x"); } { - auto u = parse_uri( - "http://#x%23"); + auto u = parse_uri("http://#x%23").value(); BOOST_TEST(u.has_fragment()); BOOST_TEST(u.encoded_fragment() == "x%23"); BOOST_TEST(u.fragment() == "x#"); } { - auto u = parse_uri( - "http://#x%25"); + auto u = parse_uri("http://#x%25").value(); BOOST_TEST(u.has_fragment()); BOOST_TEST(u.encoded_fragment() == "x%25"); BOOST_TEST(u.fragment() == "x%"); @@ -696,7 +661,7 @@ public: "http://user:pass@www.boost.org:8080/x/y/z?a=b&c=3#frag"; std::shared_ptr sp; { - auto const u = urls::parse_uri(s); + auto const u = urls::parse_uri(s).value(); sp = u.collect(); BOOST_TEST( u.encoded_url().data() != @@ -710,7 +675,7 @@ public: void testOutput() { - auto u = parse_uri( "http://example.com" ); + auto u = parse_uri( "http://example.com" ).value(); std::stringstream ss; ss << u; BOOST_TEST( diff --git a/test/wpt/main.cpp b/test/wpt/main.cpp index 0c11f351..bab3fec1 100644 --- a/test/wpt/main.cpp +++ b/test/wpt/main.cpp @@ -67,33 +67,22 @@ do_setters_scheme(json::array const& ja) for(auto const& jv : ja) { ++total_; - error_code ec; auto href = jv.at("href").as_string(); - url u = parse_uri_reference(href, ec); - if(! ec.failed()) + url u = parse_uri_reference(href).value(); + auto const& ex = jv.at("expected").as_object(); + try { - auto const& ex = jv.at("expected").as_object(); - try - { - u.set_scheme(jv.at("new_value").as_string()); - } - catch(std::exception const& e) - { - if(ex.at("href").as_string() != href) - { - Log << "caught exception: " << e.what() << std::endl; - Log << "set_scheme failed: " << href << - ", " << jv.at("new_value") << std::endl; - ++fail_; - } - } + u.set_scheme(jv.at("new_value").as_string()); } - else + catch(std::exception const& e) { - Log << "parse failed: " << href - //<< " // " << jv.at("comment") - << std::endl; - ++fail_; + if(ex.at("href").as_string() != href) + { + Log << "caught exception: " << e.what() << std::endl; + Log << "set_scheme failed: " << href << + ", " << jv.at("new_value") << std::endl; + ++fail_; + } } } } @@ -104,18 +93,9 @@ do_setters_user(json::array const& ja) for(auto const& jv : ja) { ++total_; - error_code ec; auto href = jv.at("href").as_string(); - url u = parse_uri_reference(href, ec); - if(! ec.failed()) - { - } - else - { - Log << "parse failed: " << href << - " // " << jv.at("comment") << std::endl; - ++fail_; - } + url u = parse_uri_reference(href).value(); + // VFALCO TODO } }