From 89b006bbad156d5c79be12635c85d364260e4762 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Wed, 14 Sep 2022 08:28:44 -0700 Subject: [PATCH] tidy segments --- include/boost/url/detail/any_params_iter.hpp | 48 ++--- .../boost/url/detail/any_segments_iter.hpp | 134 +++++++++----- .../boost/url/detail/impl/any_params_iter.ipp | 2 +- .../url/detail/impl/any_segments_iter.ipp | 174 ++++++++++++++---- include/boost/url/impl/params_ref.hpp | 1 + .../boost/url/impl/segments_encoded_ref.ipp | 24 +-- include/boost/url/impl/segments_ref.ipp | 21 +-- include/boost/url/impl/url_base.ipp | 103 ++++++----- include/boost/url/url_base.hpp | 4 +- test/unit/CMakeLists.txt | 2 - test/unit/Jamfile | 1 - test/unit/segments_ref.cpp | 110 ++++++----- test/unit/segments_test.cpp | 17 -- test/unit/segments_test.hpp | 22 --- 14 files changed, 373 insertions(+), 290 deletions(-) delete mode 100644 test/unit/segments_test.cpp delete mode 100644 test/unit/segments_test.hpp diff --git a/include/boost/url/detail/any_params_iter.hpp b/include/boost/url/detail/any_params_iter.hpp index 9aab302fb..0043ea43b 100644 --- a/include/boost/url/detail/any_params_iter.hpp +++ b/include/boost/url/detail/any_params_iter.hpp @@ -31,52 +31,33 @@ namespace detail { possibly encoded sequence of query params_ref. */ -class BOOST_SYMBOL_VISIBLE +struct BOOST_SYMBOL_VISIBLE any_params_iter { - bool empty_ = false; - protected: - explicit - any_params_iter( - bool empty) noexcept - : empty_(empty) - { - } - - any_params_iter( - bool empty, - string_view const& s0_) noexcept - : empty_(empty) - , s0(s0_) - { - } - any_params_iter( - bool empty, - string_view const& s0_, - string_view const& s1_) noexcept - : empty_(empty) - , s0(s0_) + bool empty_, + string_view s0_ = {}, + string_view s1_ = {}) noexcept + : s0(s0_) , s1(s1_) + , empty(empty_) { } public: + // these are adjusted + // when self-intersecting string_view s0; string_view s1; + // True if the sequence is empty + bool empty = false; + BOOST_URL_DECL virtual ~any_params_iter() noexcept = 0; - // True if the sequence is empty - bool - empty() const noexcept - { - return empty_; - } - // Rewind the iterator to the beginning virtual void @@ -251,8 +232,6 @@ struct BOOST_SYMBOL_VISIBLE param_encoded_iter : any_params_iter { - // constructor argument will - // throw on invalid input BOOST_URL_DECL explicit param_encoded_iter( @@ -342,9 +321,8 @@ struct params_encoded_iter { if(it_ == end_) return false; - // param_pct_view conversion - // will throw on invalid input - measure_impl(n, + // throw on invalid input + measure_impl(n, param_pct_view(*it_++)); return true; } diff --git a/include/boost/url/detail/any_segments_iter.hpp b/include/boost/url/detail/any_segments_iter.hpp index 745747515..57ebf28f1 100644 --- a/include/boost/url/detail/any_segments_iter.hpp +++ b/include/boost/url/detail/any_segments_iter.hpp @@ -20,54 +20,38 @@ namespace boost { namespace urls { namespace detail { -class BOOST_SYMBOL_VISIBLE +struct BOOST_SYMBOL_VISIBLE any_segments_iter { - string_view* s_ = nullptr; - protected: explicit any_segments_iter( - string_view* s = nullptr) noexcept - : s_(s) + string_view s_ = {}) noexcept + : s(s_) { } - string_view front_; - public: - string_view - front() const noexcept - { - return front_; - } + // this is adjusted + // when self-intersecting + string_view s; - // Return the input string or nullptr - string_view* - input() const noexcept - { - return s_; - } + // the first segment, + // to handle special cases + string_view front; // Rewind the iterator to the beginning - virtual - void - rewind() noexcept = 0; + virtual void rewind() noexcept = 0; // Measure and increment the current // element. n is increased by the // encoded size. Returns false on // end of range. - virtual bool measure( - std::size_t& n) noexcept = 0; + virtual bool measure(std::size_t& n) = 0; // Copy and increment the current - // element. encoding is performed - // if needed. - virtual - void - copy( - char*& dest, + // element, encoding as needed. + virtual void copy(char*& dest, char const* end) noexcept = 0; }; @@ -75,15 +59,14 @@ class BOOST_SYMBOL_VISIBLE // iterates segments in a string struct BOOST_SYMBOL_VISIBLE - path_iter : - public any_segments_iter + path_iter + : any_segments_iter { explicit path_iter( string_view s) noexcept; protected: - string_view s_; std::size_t pos_; std::size_t next_; @@ -109,18 +92,44 @@ struct BOOST_SYMBOL_VISIBLE void copy(char*&, char const*) noexcept override; }; +//------------------------------------------------ +// +// segment_iter +// +//------------------------------------------------ + +// A 1-segment range +// allowing self-intersection +// iterates segments in an encoded string +struct BOOST_SYMBOL_VISIBLE + segment_iter + : any_segments_iter +{ + explicit + segment_iter( + string_view s) noexcept; + +private: + bool at_end_ = false; + void rewind() noexcept override; + bool measure(std::size_t&) noexcept override; + void copy(char*&, char const*) noexcept override; +}; + //------------------------------------------------ // // segments_iter // //------------------------------------------------ -class segments_iter_base +struct segments_iter_base { protected: - BOOST_URL_DECL static void measure_impl( + BOOST_URL_DECL static void + measure_impl( string_view, std::size_t&) noexcept; - BOOST_URL_DECL static void copy_impl( + BOOST_URL_DECL static void + copy_impl( string_view, char*&, char const*) noexcept; }; @@ -145,7 +154,7 @@ struct segments_iter , end_(last) { if (first != last) - front_ = *first; + front = *first; } private: @@ -181,6 +190,30 @@ struct segments_iter } }; +//------------------------------------------------ +// +// segment_encoded_iter +// +//------------------------------------------------ + +// A 1-segment range +// allowing self-intersection +// iterates segments in an encoded string +struct BOOST_SYMBOL_VISIBLE + segment_encoded_iter + : any_segments_iter +{ + explicit + segment_encoded_iter( + pct_string_view const& s) noexcept; + +private: + bool at_end_ = false; + void rewind() noexcept override; + bool measure(std::size_t&) noexcept override; + void copy(char*&, char const*) noexcept override; +}; + //------------------------------------------------ // // segments_encoded_iter @@ -189,13 +222,15 @@ struct segments_iter // Validating and copying from // a string of encoded segments -class segments_encoded_iter_base +struct segments_encoded_iter_base { protected: - BOOST_URL_DECL static bool measure_impl( - pct_string_view, std::size_t&) noexcept; - BOOST_URL_DECL static void copy_impl( - string_view, char*&, char const*) noexcept; + BOOST_URL_DECL static void + measure_impl( + std::size_t&, string_view) noexcept; + BOOST_URL_DECL static void + copy_impl( + char*&, char const*, string_view) noexcept; }; // iterates segments in an @@ -224,8 +259,11 @@ struct segments_encoded_iter , it0_(first) , end_(last) { - if (it_ != end_) - front_ = *first; + if(it_ != end_) + { + // throw on invalid input + front = pct_string_view(*first); + } } private: @@ -241,12 +279,13 @@ struct segments_encoded_iter bool measure( - std::size_t& n) noexcept override + std::size_t& n) override { if(it_ == end_) return false; - if(! measure_impl(*it_, n)) - return false; + // throw on invalid input + measure_impl(n, + pct_string_view(*it_)); ++it_; return true; } @@ -257,8 +296,7 @@ struct segments_encoded_iter char const* end ) noexcept override { - copy_impl(*it_, dest, end); - ++it_; + copy_impl(dest, end, *it_++); } }; diff --git a/include/boost/url/detail/impl/any_params_iter.ipp b/include/boost/url/detail/impl/any_params_iter.ipp index a29145074..5f25a8048 100644 --- a/include/boost/url/detail/impl/any_params_iter.ipp +++ b/include/boost/url/detail/impl/any_params_iter.ipp @@ -59,7 +59,7 @@ void query_iter:: rewind() noexcept { - if(empty()) + if(empty) { at_end_ = true; return; diff --git a/include/boost/url/detail/impl/any_segments_iter.ipp b/include/boost/url/detail/impl/any_segments_iter.ipp index f49d41593..8d06b16d3 100644 --- a/include/boost/url/detail/impl/any_segments_iter.ipp +++ b/include/boost/url/detail/impl/any_segments_iter.ipp @@ -28,9 +28,8 @@ namespace detail { path_iter:: path_iter( - string_view s) noexcept - : any_segments_iter(&s_) - , s_(s) + string_view s_) noexcept + : any_segments_iter(s_) { rewind(); } @@ -40,7 +39,7 @@ path_iter:: increment() noexcept { pos_ = next_; - if(pos_ == s_.size()) + if(pos_ == s.size()) { pos_ = string_view::npos; return; @@ -48,20 +47,20 @@ increment() noexcept // skip '/' ++pos_; auto const end = - s_.data() + s_.size(); + s.data() + s.size(); auto const p0 = - s_.data() + pos_; + s.data() + pos_; auto p = p0; while(p != end) { if(*p == '/') { - next_ = p - s_.data(); + next_ = p - s.data(); return; } ++p; } - next_ = s_.size(); + next_ = s.size(); } void @@ -69,8 +68,8 @@ path_iter:: rewind() noexcept { pos_ = 0; - auto p0 = s_.data(); - auto const end = p0 + s_.size(); + auto p0 = s.data(); + auto const end = p0 + s.size(); if(p0 != end) { // skip leading '/' @@ -87,14 +86,14 @@ rewind() noexcept break; ++p; } - front_ = string_view( + front = string_view( p0, p - p0); - next_ = p - s_.data(); + next_ = p - s.data(); } else { pos_ = string_view::npos; - front_ = { p0, 0 }; + front = { p0, 0 }; } } @@ -105,11 +104,12 @@ measure( { if(pos_ == string_view::npos) return false; - string_view s = s_.substr( - pos_, next_ - pos_); encode_opts opt; - n += urls::encoded_size( - s, + opt.space_to_plus = false; + n += encoded_size( + s.substr( + pos_, + next_ - pos_), opt, pchars); increment(); @@ -124,13 +124,14 @@ copy( { BOOST_ASSERT(pos_ != string_view::npos); - string_view s = s_.substr( - pos_, next_ - pos_); encode_opts opt; + opt.space_to_plus = false; dest += encode( dest, end, - s, + s.substr( + pos_, + next_ - pos_), opt, pchars); increment(); @@ -156,11 +157,12 @@ measure( { if(pos_ == string_view::npos) return false; - string_view s = s_.substr( - pos_, next_ - pos_); encode_opts opt; + opt.space_to_plus = false; n += detail::re_encoded_size_unchecked( - s, + s.substr( + pos_, + next_ - pos_), opt, pchars); increment(); @@ -175,18 +177,71 @@ copy( { BOOST_ASSERT(pos_ != string_view::npos); - string_view s = s_.substr( - pos_, next_ - pos_); encode_opts opt; + opt.space_to_plus = false; detail::re_encode_unchecked( dest, end, - s, + s.substr( + pos_, + next_ - pos_), opt, pchars); increment(); } +//------------------------------------------------ +// +// segment_iter +// +//------------------------------------------------ + +segment_iter:: +segment_iter( + string_view s_) noexcept + : any_segments_iter(s_) +{ + front = s; +} + +void +segment_iter:: +rewind() noexcept +{ + at_end_ = false; +} + +bool +segment_iter:: +measure( + std::size_t& n) noexcept +{ + if(at_end_) + return false; + encode_opts opt; + opt.space_to_plus = false; + n += encoded_size( + s, + opt, + pchars); + at_end_ = true; + return true; +} + +void +segment_iter:: +copy(char*& dest, char const* end) noexcept +{ + encode_opts opt; + opt.space_to_plus = false; + dest += encode( + dest, + end, + s, + opt, + pchars); +} + //------------------------------------------------ // // segments_iter_base @@ -200,6 +255,7 @@ measure_impl( std::size_t& n) noexcept { encode_opts opt; + opt.space_to_plus = false; n += encoded_size( s, opt, @@ -214,6 +270,7 @@ copy_impl( char const* end) noexcept { encode_opts opt; + opt.space_to_plus = false; dest += encode( dest, end, @@ -224,32 +281,85 @@ copy_impl( //------------------------------------------------ // -// segments_encoded_iter_base +// segment_encoded_iter // //------------------------------------------------ +segment_encoded_iter:: +segment_encoded_iter( + pct_string_view const& s_) noexcept + : any_segments_iter(s_) +{ + front = s; +} + +void +segment_encoded_iter:: +rewind() noexcept +{ + at_end_ = false; +} + bool -segments_encoded_iter_base:: -measure_impl( - pct_string_view s, +segment_encoded_iter:: +measure( std::size_t& n) noexcept { + if(at_end_) + return false; encode_opts opt; + opt.space_to_plus = false; n += detail::re_encoded_size_unchecked( s, opt, pchars); + at_end_ = true; return true; } +void +segment_encoded_iter:: +copy(char*& dest, char const* end) noexcept +{ + encode_opts opt; + opt.space_to_plus = false; + detail::re_encode_unchecked( + dest, + end, + s, + opt, + pchars); +} + +//------------------------------------------------ +// +// segments_encoded_iter_base +// +//------------------------------------------------ + +void +segments_encoded_iter_base:: +measure_impl( + std::size_t& n, + string_view s) noexcept +{ + encode_opts opt; + opt.space_to_plus = false; + n += detail::re_encoded_size_unchecked( + s, + opt, + pchars); +} + void segments_encoded_iter_base:: copy_impl( - string_view s, char*& dest, - char const* end) noexcept + char const* end, + string_view s) noexcept { encode_opts opt; + opt.space_to_plus = false; detail::re_encode_unchecked( dest, end, diff --git a/include/boost/url/impl/params_ref.hpp b/include/boost/url/impl/params_ref.hpp index 4db77d452..768565862 100644 --- a/include/boost/url/impl/params_ref.hpp +++ b/include/boost/url/impl/params_ref.hpp @@ -12,6 +12,7 @@ #define BOOST_URL_IMPL_PARAMS_REF_HPP #include +#include #include #include #include diff --git a/include/boost/url/impl/segments_encoded_ref.ipp b/include/boost/url/impl/segments_encoded_ref.ipp index 8f05ebd94..21a56caaf 100644 --- a/include/boost/url/impl/segments_encoded_ref.ipp +++ b/include/boost/url/impl/segments_encoded_ref.ipp @@ -86,15 +86,13 @@ auto segments_encoded_ref:: insert( iterator before, - pct_string_view s0) -> + pct_string_view s) -> iterator { - string_view s = s0; return u_->edit_segments( before.it_, before.it_, - detail::make_segments_encoded_iter( - &s, &s + 1)); + detail::segment_encoded_iter(s)); } auto @@ -133,11 +131,10 @@ replace( pct_string_view s) -> iterator { - return replace( - pos, - std::next(pos), - &s, - &s + 1); + return u_->edit_segments( + pos.it_, + std::next(pos).it_, + detail::segment_encoded_iter(s)); } auto @@ -148,11 +145,10 @@ replace( pct_string_view s) -> iterator { - return replace( - from, - to, - &s, - &s+1); + return u_->edit_segments( + from.it_, + to.it_, + detail::segment_encoded_iter(s)); } auto diff --git a/include/boost/url/impl/segments_ref.ipp b/include/boost/url/impl/segments_ref.ipp index e82ea6119..8798eb462 100644 --- a/include/boost/url/impl/segments_ref.ipp +++ b/include/boost/url/impl/segments_ref.ipp @@ -90,8 +90,7 @@ insert( return u_->edit_segments( before.it_, before.it_, - detail::make_segments_iter( - &s, &s + 1)); + detail::segment_iter(s)); } auto @@ -131,11 +130,10 @@ replace( string_view s) -> iterator { - return replace( - pos, - std::next(pos), - &s, - &s + 1); + return u_->edit_segments( + pos.it_, + std::next(pos).it_, + detail::segment_iter(s)); } auto @@ -146,11 +144,10 @@ replace( string_view s) -> iterator { - return replace( - from, - to, - &s, - &s + 1); + return u_->edit_segments( + from.it_, + to.it_, + detail::segment_iter(s)); } auto diff --git a/include/boost/url/impl/url_base.ipp b/include/boost/url/impl/url_base.ipp index 5e7cc6734..6a027006e 100644 --- a/include/boost/url/impl/url_base.ipp +++ b/include/boost/url/impl/url_base.ipp @@ -16,7 +16,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -1942,15 +1943,15 @@ edit_segments( else if(nseg > 0) { // first segment from src - if(! src.front().empty()) + if(! src.front.empty()) { - if( src.front() == "." && + if( src.front == "." && nseg > 1) prefix = 2 + absolute; else if(absolute) prefix = 1; else if(has_scheme() || - ! src.front().contains(':')) + ! src.front.contains(':')) prefix = 0; else prefix = 2; @@ -2006,7 +2007,7 @@ edit_segments( // // Resize // - op_t op(*this, src.input()); + op_t op(*this, &src.s); char* dest; char const* end; { @@ -2086,14 +2087,7 @@ edit_segments( auto const dn = detail::decode_bytes_unchecked( string_view(dest0, dest - dest0)); - auto const dn1 = - u_.decoded_[id_path] + dn - dn0; -#if 0 - BOOST_ASSERT(dn1 == - detail::decode_bytes_unchecked( - u_.get(id_path))); -#endif - u_.decoded_[id_path] = dn1; + u_.decoded_[id_path] += dn - dn0; return detail::segments_iter_impl( u_, pos0, it0.index); @@ -2160,55 +2154,68 @@ edit_params( } } - op_t op(*this, &src.s0, &src.s1); - //------------------------------------------------ // // Resize // - - // VFALCO OVERFLOW CHECK HERE - auto const nparam1 = - u_.nparam_ + nparam - ( - it1.index - it0.index); - auto const nremove = pos1 - pos0; - reserve_impl(size() + nchar - nremove, op); - auto dest = s_ + pos0; - if(u_.nparam_ > 0) - { - // needed when we move - // the beginning of the query - s_[u_.offset(id_query)] = '&'; - } - op.move( - dest + nchar, - u_.cs_ + pos1, - size() - pos1); - u_.set_size( - id_query, - u_.len(id_query) + - nchar - nremove); - u_.nparam_ = nparam1; - if(nparam1 > 0) + op_t op(*this, &src.s0, &src.s1); + char* dest; + char const* end; { - // needed when we erase - // the beginning of the query - s_[u_.offset(id_query)] = '?'; + auto const nremove = pos1 - pos0; + // check overflow + if( nchar > nremove && + nchar - nremove > + max_size() - size()) + { + // too large + detail::throw_url_too_large(); + } + auto const nparam1 = + u_.nparam_ + nparam - ( + it1.index - it0.index); + reserve_impl(size() + nchar - nremove, op); + dest = s_ + pos0; + end = dest + nchar; + if(u_.nparam_ > 0) + { + // needed when we move + // the beginning of the query + s_[u_.offset(id_query)] = '&'; + } + op.move( + dest + nchar, + u_.cs_ + pos1, + size() - pos1); + u_.set_size( + id_query, + u_.len(id_query) + + nchar - nremove); + u_.nparam_ = nparam1; + if(nparam1 > 0) + { + // needed when we erase + // the beginning of the query + s_[u_.offset(id_query)] = '?'; + } + if(s_) + s_[size()] = '\0'; } - if(s_) - s_[size()] = '\0'; auto const dest0 = dest; - // copy - src.rewind(); - //auto dest = dest0; +//------------------------------------------------ +// +// Output params and internal separators: +// +// [ '?' param ] [ '&' param ] +// if(nparam > 0) { - auto const end = dest + nchar; if(it0.index == 0) *dest++ = '?'; else *dest++ = '&'; + src.rewind(); for(;;) { src.copy(dest, end); diff --git a/include/boost/url/url_base.hpp b/include/boost/url/url_base.hpp index 154ea3604..c17b94916 100644 --- a/include/boost/url/url_base.hpp +++ b/include/boost/url/url_base.hpp @@ -21,8 +21,6 @@ #include #include #include -#include -#include #include #include #include @@ -33,6 +31,8 @@ namespace urls { #ifndef BOOST_URL_DOCS namespace detail { +struct any_params_iter; +struct any_segments_iter; struct params_iter_impl; struct segments_iter_impl; } diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index ab33f77ed..95f28ae31 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -17,8 +17,6 @@ set(BOOST_URL_TESTS_FILES CMakeLists.txt Jamfile test_rule.hpp - segments_test.hpp - segments_test.cpp authority_view.cpp doc_container.cpp doc_grammar.cpp diff --git a/test/unit/Jamfile b/test/unit/Jamfile index b34c18948..2fbea21f9 100644 --- a/test/unit/Jamfile +++ b/test/unit/Jamfile @@ -49,7 +49,6 @@ local SOURCES = segments_encoded_ref.cpp segments_encoded_view.cpp segments_ref.cpp - segments_test.cpp segments_view.cpp snippets.cpp static_url.cpp diff --git a/test/unit/segments_ref.cpp b/test/unit/segments_ref.cpp index 7c6d5ce2b..5da56081d 100644 --- a/test/unit/segments_ref.cpp +++ b/test/unit/segments_ref.cpp @@ -16,28 +16,26 @@ #include #include -#include "segments_test.hpp" +#include "test_suite.hpp" namespace boost { namespace urls { -using Type = segments_ref; - BOOST_STATIC_ASSERT( ! std::is_default_constructible< - Type>::value); + segments_ref>::value); BOOST_STATIC_ASSERT( std::is_copy_constructible< - Type>::value); + segments_ref>::value); BOOST_STATIC_ASSERT( std::is_copy_assignable< - Type>::value); + segments_ref>::value); BOOST_STATIC_ASSERT( std::is_default_constructible< - Type::iterator>::value); + segments_ref::iterator>::value); //------------------------------------------------ @@ -48,7 +46,7 @@ struct segments_ref_test static void check( - void(*f)(Type), + void(*f)(segments_ref), string_view s0, string_view s1, std::initializer_list< @@ -58,7 +56,7 @@ struct segments_ref_test if(! BOOST_TEST(rv.has_value())) return; url u = *rv; - Type ps(u.segments()); + segments_ref ps(u.segments()); f(ps); BOOST_TEST_EQ(u.encoded_path(), s1); if(! BOOST_TEST_EQ( @@ -78,7 +76,7 @@ struct segments_ref_test static void check( - void(*f1)(Type), void(*f2)(Type), + void(*f1)(segments_ref), void(*f2)(segments_ref), string_view s0, string_view s1, std::initializer_list< string_view> init) @@ -95,8 +93,8 @@ struct segments_ref_test // segments_ref(segments_ref) { url u("/index.htm"); - Type ps0 = u.segments(); - Type ps(ps0); + segments_ref ps0 = u.segments(); + segments_ref ps(ps0); BOOST_TEST_EQ(&ps0.url(), &ps.url()); BOOST_TEST_EQ( ps0.url().buffer().data(), @@ -107,8 +105,8 @@ struct segments_ref_test { url u1("/index%2Ehtm"); url u2("/path/to/file.txt"); - Type ps1 = u1.segments(); - Type ps2 = u2.segments(); + segments_ref ps1 = u1.segments(); + segments_ref ps2 = u2.segments(); BOOST_TEST_NE( ps1.buffer().data(), ps2.buffer().data()); @@ -125,7 +123,7 @@ struct segments_ref_test { url u1("/index.htm"); url_view u2("/path/to/file.txt"); - Type ps1 = u1.segments(); + segments_ref ps1 = u1.segments(); segments_view ps2 = u2.segments(); BOOST_TEST_NE( ps1.buffer().data(), @@ -184,7 +182,7 @@ struct segments_ref_test // { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { ps.clear(); }; @@ -203,11 +201,11 @@ struct segments_ref_test // { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { ps.assign({ "path", "to", "file.txt?" }); }; - auto const g = [](Type ps) + auto const g = [](segments_ref ps) { auto const assign = [&ps]( std::initializer_list< @@ -230,7 +228,7 @@ struct segments_ref_test // { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.insert(ps.begin(), ""); BOOST_TEST_EQ(*it, ""); @@ -245,7 +243,7 @@ struct segments_ref_test check(f, "x:", "./", {""}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.insert(ps.begin(), "my seg"); BOOST_TEST_EQ(*it, "my seg"); @@ -259,7 +257,7 @@ struct segments_ref_test check(f, "Program%20Files", "my%20seg/Program%20Files", {"my seg", "Program Files"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.insert(std::next(ps.begin(), 1), "my seg"); BOOST_TEST_EQ(*it, "my seg"); @@ -268,7 +266,7 @@ struct segments_ref_test check(f, "/path/to/file.txt", "/path/my%20seg/to/file.txt", {"path", "my seg", "to", "file.txt"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.insert(ps.end(), "my seg"); BOOST_TEST_EQ(*it, "my seg"); @@ -282,7 +280,7 @@ struct segments_ref_test check(f, "Program%20Files", "Program%20Files/my%20seg", {"Program Files", "my seg"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.insert(ps.end(), ""); BOOST_TEST_EQ(*it, ""); @@ -301,12 +299,12 @@ struct segments_ref_test // { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.insert(ps.begin(), { "u", "v#" }); BOOST_TEST_EQ(*it, "u"); }; - auto const g = [](Type ps) + auto const g = [](segments_ref ps) { auto const insert = [&ps]( std::initializer_list< @@ -327,12 +325,12 @@ struct segments_ref_test check(f, g, "Program%20Files", "u/v%23/Program%20Files", {"u", "v#", "Program Files"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.insert(ps.begin(), { "", "" }); BOOST_TEST_EQ(*it, ""); }; - auto const g = [](Type ps) + auto const g = [](segments_ref ps) { auto const insert = [&ps]( std::initializer_list< @@ -358,7 +356,7 @@ struct segments_ref_test // { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.erase(std::next(ps.begin(), 0)); if(it != ps.end()) @@ -374,7 +372,7 @@ struct segments_ref_test check(f, "x:.//:", ":", {":"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.erase(std::next(ps.begin(), 1)); BOOST_TEST_EQ(*it, "file.txt"); @@ -383,7 +381,7 @@ struct segments_ref_test check(f, "/path/to/file.txt", "/path/file.txt", {"path", "file.txt"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.erase(std::next(ps.begin(), 2)); BOOST_TEST_EQ(it, ps.end()); @@ -392,7 +390,7 @@ struct segments_ref_test check(f, "/path/to/file.txt", "/path/to", {"path", "to"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { ps.erase(std::next(ps.begin(), 1)); }; @@ -405,7 +403,7 @@ struct segments_ref_test // { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.erase( std::next(ps.begin(), 0), @@ -416,7 +414,7 @@ struct segments_ref_test check(f, "/path/to/the/file.txt", "/the/file.txt", {"the", "file.txt"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.erase( std::next(ps.begin(), 1), @@ -427,7 +425,7 @@ struct segments_ref_test check(f, "/path/to/the/file.txt", "/path/file.txt", {"path", "file.txt"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.erase( std::next(ps.begin(), 2), @@ -443,7 +441,7 @@ struct segments_ref_test // { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.replace(std::next(ps.begin(), 0), ""); BOOST_TEST_EQ(*it, ""); @@ -452,7 +450,7 @@ struct segments_ref_test check(f, "/path/to/file.txt", "/.//to/file.txt", {"", "to", "file.txt"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.replace(std::next(ps.begin(), 1), ""); BOOST_TEST_EQ(*it, ""); @@ -461,7 +459,7 @@ struct segments_ref_test check(f, "/path/to/file.txt", "/path//file.txt", {"path", "", "file.txt"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.replace(std::next(ps.begin(), 0), "test"); BOOST_TEST_EQ(*it, "test"); @@ -470,7 +468,7 @@ struct segments_ref_test check(f, "/path/to/file.txt", "/test/to/file.txt", {"test", "to", "file.txt"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.replace(std::next(ps.begin(), 1), "test"); BOOST_TEST_EQ(*it, "test"); @@ -479,7 +477,7 @@ struct segments_ref_test check(f, "/path/to/file.txt", "/path/test/file.txt", {"path", "test", "file.txt"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.replace(std::next(ps.begin(), 2), "test"); BOOST_TEST_EQ(*it, "test"); @@ -488,7 +486,7 @@ struct segments_ref_test check(f, "/path/to/file.txt", "/path/to/test", {"path", "to", "test"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.replace(ps.begin(), ":"); BOOST_TEST_EQ(*it, ":"); @@ -504,7 +502,7 @@ struct segments_ref_test // { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.replace( std::next(ps.begin(), 0), @@ -516,7 +514,7 @@ struct segments_ref_test check(f, "/path/to/the/file.txt", "/.//the/file.txt", {"", "the", "file.txt"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.replace( std::next(ps.begin(), 1), @@ -528,7 +526,7 @@ struct segments_ref_test check(f, "/path/to/the/file.txt", "/path//file.txt", {"path", "", "file.txt"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.replace( std::next(ps.begin(), 2), @@ -540,7 +538,7 @@ struct segments_ref_test check(f, "/path/to/the/file.txt", "/path/to/", {"path", "to", ""}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.replace( std::next(ps.begin(), 0), @@ -552,7 +550,7 @@ struct segments_ref_test check(f, "/path/to/the/file.txt", "/test/the/file.txt", {"test", "the", "file.txt"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.replace( std::next(ps.begin(), 1), @@ -564,7 +562,7 @@ struct segments_ref_test check(f, "/path/to/the/file.txt", "/path/test/file.txt", {"path", "test", "file.txt"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.replace( std::next(ps.begin(), 2), @@ -582,7 +580,7 @@ struct segments_ref_test // { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.replace( std::next(ps.begin(), 0), @@ -590,7 +588,7 @@ struct segments_ref_test { "t", "u", "v" }); BOOST_TEST_EQ(*it, "t"); }; - auto const g = [](Type ps) + auto const g = [](segments_ref ps) { auto const replace = [&ps]( std::initializer_list< @@ -608,7 +606,7 @@ struct segments_ref_test check(f, g, "/path/to/the/file.txt", "/t/u/v/the/file.txt", {"t", "u", "v", "the", "file.txt"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.replace( std::next(ps.begin(), 1), @@ -616,7 +614,7 @@ struct segments_ref_test { "t", "u", "v" }); BOOST_TEST_EQ(*it, "t"); }; - auto const g = [](Type ps) + auto const g = [](segments_ref ps) { auto const replace = [&ps]( std::initializer_list< @@ -634,7 +632,7 @@ struct segments_ref_test check(f, g, "/path/to/the/file.txt", "/path/t/u/v/file.txt", {"path", "t", "u", "v", "file.txt"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { auto it = ps.replace( std::next(ps.begin(), 2), @@ -642,7 +640,7 @@ struct segments_ref_test { "t", "u", "v" }); BOOST_TEST_EQ(*it, "t"); }; - auto const g = [](Type ps) + auto const g = [](segments_ref ps) { auto const replace = [&ps]( std::initializer_list< @@ -665,7 +663,7 @@ struct segments_ref_test // { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { ps.push_back(""); }; @@ -675,7 +673,7 @@ struct segments_ref_test check(f, "/./", "/.//", {"", ""}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { ps.push_back("/"); }; @@ -683,7 +681,7 @@ struct segments_ref_test check(f, "/", "/%2F", {"/"}); } { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { ps.push_back(":"); }; @@ -695,7 +693,7 @@ struct segments_ref_test // pop_back // { - auto const f = [](Type ps) + auto const f = [](segments_ref ps) { ps.pop_back(); }; diff --git a/test/unit/segments_test.cpp b/test/unit/segments_test.cpp deleted file mode 100644 index cc37ceb16..000000000 --- a/test/unit/segments_test.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// -// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) -// Copyright (c) 2022 Alan de Freitas (alandefreitas@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/boostorg/url -// - -#include "segments_test.hpp" - -namespace boost { -namespace urls { - -} // urls -} // boost diff --git a/test/unit/segments_test.hpp b/test/unit/segments_test.hpp deleted file mode 100644 index fdf724e08..000000000 --- a/test/unit/segments_test.hpp +++ /dev/null @@ -1,22 +0,0 @@ -// -// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) -// Copyright (c) 2022 Alan de Freitas (alandefreitas@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/boostorg/url -// - -#ifndef BOOST_URL_TEST_SEGMENTS_TEST_HPP -#define BOOST_URL_TEST_SEGMENTS_TEST_HPP - -#include "test_suite.hpp" - -namespace boost { -namespace urls { - -} // urls -} // boost - -#endif