100.00% Lines (28/28)
100.00% Functions (1/1)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) | 2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) | |||||
| 3 | // Copyright (c) 2024 Alan de Freitas (alandefreitas@gmail.com) | 3 | // Copyright (c) 2024 Alan de Freitas (alandefreitas@gmail.com) | |||||
| 4 | // | 4 | // | |||||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |||||
| 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||||
| 7 | // | 7 | // | |||||
| 8 | // Official repository: https://github.com/boostorg/url | 8 | // Official repository: https://github.com/boostorg/url | |||||
| 9 | // | 9 | // | |||||
| 10 | 10 | |||||||
| 11 | #ifndef BOOST_URL_RFC_IMPL_ORIGIN_FORM_RULE_HPP | 11 | #ifndef BOOST_URL_RFC_IMPL_ORIGIN_FORM_RULE_HPP | |||||
| 12 | #define BOOST_URL_RFC_IMPL_ORIGIN_FORM_RULE_HPP | 12 | #define BOOST_URL_RFC_IMPL_ORIGIN_FORM_RULE_HPP | |||||
| 13 | 13 | |||||||
| 14 | #include <boost/url/detail/config.hpp> | 14 | #include <boost/url/detail/config.hpp> | |||||
| 15 | #include <boost/url/url_view.hpp> | 15 | #include <boost/url/url_view.hpp> | |||||
| 16 | #include <boost/url/rfc/detail/path_rules.hpp> | 16 | #include <boost/url/rfc/detail/path_rules.hpp> | |||||
| 17 | #include <boost/url/rfc/detail/query_part_rule.hpp> | 17 | #include <boost/url/rfc/detail/query_part_rule.hpp> | |||||
| 18 | #include <boost/url/grammar/parse.hpp> | 18 | #include <boost/url/grammar/parse.hpp> | |||||
| 19 | 19 | |||||||
| 20 | namespace boost { | 20 | namespace boost { | |||||
| 21 | namespace urls { | 21 | namespace urls { | |||||
| 22 | 22 | |||||||
| 23 | BOOST_URL_CXX20_CONSTEXPR_OR_INLINE | 23 | BOOST_URL_CXX20_CONSTEXPR_OR_INLINE | |||||
| 24 | auto | 24 | auto | |||||
| HITCBC | 25 | 3059 | implementation_defined::origin_form_rule_t:: | 25 | 3059 | implementation_defined::origin_form_rule_t:: | ||
| 26 | parse( | 26 | parse( | |||||
| 27 | char const*& it, | 27 | char const*& it, | |||||
| 28 | char const* end | 28 | char const* end | |||||
| 29 | ) const noexcept -> | 29 | ) const noexcept -> | |||||
| 30 | system::result<value_type> | 30 | system::result<value_type> | |||||
| 31 | { | 31 | { | |||||
| HITCBC | 32 | 3059 | detail::url_impl u(detail::url_impl::from::string); | 32 | 3059 | detail::url_impl u(detail::url_impl::from::string); | ||
| HITCBC | 33 | 3059 | u.cs_ = it; | 33 | 3059 | u.cs_ = it; | ||
| 34 | 34 | |||||||
| 35 | // absolute-path = 1*( "/" segment ) | 35 | // absolute-path = 1*( "/" segment ) | |||||
| 36 | { | 36 | { | |||||
| HITCBC | 37 | 3059 | if(it == end || *it != '/') | 37 | 3059 | if(it == end || *it != '/') | ||
| 38 | { | 38 | { | |||||
| HITCBC | 39 | 3000 | BOOST_URL_CONSTEXPR_RETURN_EC( | 39 | 3000 | BOOST_URL_CONSTEXPR_RETURN_EC( | ||
| 40 | grammar::error::mismatch); | 40 | grammar::error::mismatch); | |||||
| 41 | } | 41 | } | |||||
| HITCBC | 42 | 59 | auto const it0 = it; | 42 | 59 | auto const it0 = it; | ||
| HITCBC | 43 | 59 | std::size_t dn = 0; | 43 | 59 | std::size_t dn = 0; | ||
| HITCBC | 44 | 59 | std::size_t nseg = 0; | 44 | 59 | std::size_t nseg = 0; | ||
| HITCBC | 45 | 185 | while(it != end) | 45 | 185 | while(it != end) | ||
| 46 | { | 46 | { | |||||
| HITCBC | 47 | 173 | if(*it == '/') | 47 | 173 | if(*it == '/') | ||
| 48 | { | 48 | { | |||||
| HITCBC | 49 | 76 | ++dn; | 49 | 76 | ++dn; | ||
| HITCBC | 50 | 76 | ++it; | 50 | 76 | ++it; | ||
| HITCBC | 51 | 76 | ++nseg; | 51 | 76 | ++nseg; | ||
| HITCBC | 52 | 76 | continue; | 52 | 76 | continue; | ||
| 53 | } | 53 | } | |||||
| HITCBC | 54 | 97 | auto rv = grammar::parse( | 54 | 97 | auto rv = grammar::parse( | ||
| 55 | it, end, detail::segment_rule); | 55 | it, end, detail::segment_rule); | |||||
| HITCBC | 56 | 97 | if(! rv) | 56 | 97 | if(! rv) | ||
| HITCBC | 57 | 2 | return rv.error(); | 57 | 2 | return rv.error(); | ||
| HITCBC | 58 | 95 | if(rv->empty()) | 58 | 95 | if(rv->empty()) | ||
| HITCBC | 59 | 45 | break; | 59 | 45 | break; | ||
| HITCBC | 60 | 50 | dn += rv->decoded_size(); | 60 | 50 | dn += rv->decoded_size(); | ||
| 61 | } | 61 | } | |||||
| HITCBC | 62 | 57 | u.apply_path( | 62 | 57 | u.apply_path( | ||
| 63 | make_pct_string_view_unsafe( | 63 | make_pct_string_view_unsafe( | |||||
| HITCBC | 64 | 57 | it0, it - it0, dn), | 64 | 57 | it0, it - it0, dn), | ||
| 65 | nseg); | 65 | nseg); | |||||
| 66 | } | 66 | } | |||||
| 67 | 67 | |||||||
| 68 | // [ "?" query ] | 68 | // [ "?" query ] | |||||
| 69 | { | 69 | { | |||||
| 70 | // query_part_rule always succeeds | 70 | // query_part_rule always succeeds | |||||
| HITCBC | 71 | 57 | auto rv = grammar::parse( | 71 | 57 | auto rv = grammar::parse( | ||
| 72 | it, end, detail::query_part_rule); | 72 | it, end, detail::query_part_rule); | |||||
| HITCBC | 73 | 57 | if(rv->has_query) | 73 | 57 | if(rv->has_query) | ||
| 74 | { | 74 | { | |||||
| 75 | // map "?" to { {} } | 75 | // map "?" to { {} } | |||||
| HITCBC | 76 | 28 | u.apply_query( | 76 | 28 | u.apply_query( | ||
| HITCBC | 77 | 14 | rv->query, | 77 | 14 | rv->query, | ||
| HITCBC | 78 | 14 | rv->count); | 78 | 14 | rv->count); | ||
| 79 | } | 79 | } | |||||
| 80 | } | 80 | } | |||||
| 81 | 81 | |||||||
| HITCBC | 82 | 57 | return url_view(u); | 82 | 57 | return url_view(u); | ||
| 83 | } | 83 | } | |||||
| 84 | 84 | |||||||
| 85 | } // urls | 85 | } // urls | |||||
| 86 | } // boost | 86 | } // boost | |||||
| 87 | 87 | |||||||
| 88 | 88 | |||||||
| 89 | #endif | 89 | #endif | |||||