100.00% Lines (13/13)
100.00% Functions (1/1)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | |||||
| 3 | // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com) | 3 | // Copyright (c) 2022 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/CPPAlliance/url | 8 | // Official repository: https://github.com/CPPAlliance/url | |||||
| 9 | // | 9 | // | |||||
| 10 | 10 | |||||||
| 11 | 11 | |||||||
| 12 | #include <boost/url/detail/config.hpp> | 12 | #include <boost/url/detail/config.hpp> | |||||
| 13 | #include <boost/url/parse_query.hpp> | 13 | #include <boost/url/parse_query.hpp> | |||||
| 14 | #include <boost/url/rfc/query_rule.hpp> | 14 | #include <boost/url/rfc/query_rule.hpp> | |||||
| 15 | #include <boost/url/grammar/parse.hpp> | 15 | #include <boost/url/grammar/parse.hpp> | |||||
| 16 | 16 | |||||||
| 17 | #include <boost/url/error.hpp> | 17 | #include <boost/url/error.hpp> | |||||
| 18 | 18 | |||||||
| 19 | namespace boost { | 19 | namespace boost { | |||||
| 20 | namespace urls { | 20 | namespace urls { | |||||
| 21 | 21 | |||||||
| 22 | system::result<params_encoded_view> | 22 | system::result<params_encoded_view> | |||||
| HITCBC | 23 | 3171 | parse_query(core::string_view s) noexcept | 23 | 3171 | parse_query(core::string_view s) noexcept | ||
| 24 | { | 24 | { | |||||
| 25 | // Handle empty strings differently. | 25 | // Handle empty strings differently. | |||||
| 26 | // We produce {}, versus empty but | 26 | // We produce {}, versus empty but | |||||
| 27 | // present query in URL (e.g. "http:?") | 27 | // present query in URL (e.g. "http:?") | |||||
| 28 | // which produces {{"", none}}. | 28 | // which produces {{"", none}}. | |||||
| HITCBC | 29 | 3171 | if(s.empty()) | 29 | 3171 | if(s.empty()) | ||
| 30 | { | 30 | { | |||||
| 31 | // default-constructed string_view can return a null data pointer; | 31 | // default-constructed string_view can return a null data pointer; | |||||
| 32 | // query_ref expects a valid pointer even when the buffer is empty. | 32 | // query_ref expects a valid pointer even when the buffer is empty. | |||||
| HITCBC | 33 | 14 | auto const* data = s.data(); | 33 | 14 | auto const* data = s.data(); | ||
| HITCBC | 34 | 14 | core::string_view empty(data ? data : "", 0); | 34 | 14 | core::string_view empty(data ? data : "", 0); | ||
| HITCBC | 35 | 14 | return params_encoded_view( | 35 | 14 | return params_encoded_view( | ||
| HITCBC | 36 | 28 | detail::query_ref( | 36 | 28 | detail::query_ref( | ||
| HITCBC | 37 | 14 | empty, 0, 0)); | 37 | 14 | empty, 0, 0)); | ||
| 38 | } | 38 | } | |||||
| HITCBC | 39 | 3157 | auto rv = grammar::parse(s, query_rule); | 39 | 3157 | auto rv = grammar::parse(s, query_rule); | ||
| HITCBC | 40 | 3157 | if(! rv) | 40 | 3157 | if(! rv) | ||
| HITCBC | 41 | 2995 | return rv.error(); | 41 | 2995 | return rv.error(); | ||
| HITCBC | 42 | 162 | return params_encoded_view( | 42 | 162 | return params_encoded_view( | ||
| HITCBC | 43 | 324 | detail::query_ref( | 43 | 324 | detail::query_ref( | ||
| HITCBC | 44 | 324 | s, s.size(), rv->size())); | 44 | 324 | s, s.size(), rv->size())); | ||
| 45 | } | 45 | } | |||||
| 46 | 46 | |||||||
| 47 | } // urls | 47 | } // urls | |||||
| 48 | } // boost | 48 | } // boost | |||||