include/boost/url/detail/optional_string.hpp
94.0% Lines (79/84)
94.4% List of functions (17/18)
Functions (18)
Function
Calls
Lines
Blocks
std::enable_if<std::is_convertible<boost::core::basic_string_view<char>, boost::core::basic_string_view<char> >::value, boost::urls::detail::optional_string>::type boost::urls::detail::get_optional_string<boost::core::basic_string_view<char> >(boost::core::basic_string_view<char> const&)
:34
0
0.0%
0.0%
std::enable_if<std::is_convertible<char [10], boost::core::basic_string_view<char> >::value, boost::urls::detail::optional_string>::type boost::urls::detail::get_optional_string<char [10]>(char const (&) [10])
:34
1x
100.0%
100.0%
std::enable_if<std::is_convertible<char [11], boost::core::basic_string_view<char> >::value, boost::urls::detail::optional_string>::type boost::urls::detail::get_optional_string<char [11]>(char const (&) [11])
:34
5x
100.0%
100.0%
std::enable_if<std::is_convertible<char [13], boost::core::basic_string_view<char> >::value, boost::urls::detail::optional_string>::type boost::urls::detail::get_optional_string<char [13]>(char const (&) [13])
:34
1x
100.0%
100.0%
std::enable_if<std::is_convertible<char [18], boost::core::basic_string_view<char> >::value, boost::urls::detail::optional_string>::type boost::urls::detail::get_optional_string<char [18]>(char const (&) [18])
:34
1x
100.0%
100.0%
std::enable_if<std::is_convertible<char [1], boost::core::basic_string_view<char> >::value, boost::urls::detail::optional_string>::type boost::urls::detail::get_optional_string<char [1]>(char const (&) [1])
:34
57x
100.0%
100.0%
std::enable_if<std::is_convertible<char [2], boost::core::basic_string_view<char> >::value, boost::urls::detail::optional_string>::type boost::urls::detail::get_optional_string<char [2]>(char const (&) [2])
:34
26x
100.0%
100.0%
std::enable_if<std::is_convertible<char [31], boost::core::basic_string_view<char> >::value, boost::urls::detail::optional_string>::type boost::urls::detail::get_optional_string<char [31]>(char const (&) [31])
:34
36x
100.0%
100.0%
std::enable_if<std::is_convertible<char [3], boost::core::basic_string_view<char> >::value, boost::urls::detail::optional_string>::type boost::urls::detail::get_optional_string<char [3]>(char const (&) [3])
:34
44x
100.0%
100.0%
std::enable_if<std::is_convertible<char [4], boost::core::basic_string_view<char> >::value, boost::urls::detail::optional_string>::type boost::urls::detail::get_optional_string<char [4]>(char const (&) [4])
:34
96x
100.0%
100.0%
std::enable_if<std::is_convertible<char [5], boost::core::basic_string_view<char> >::value, boost::urls::detail::optional_string>::type boost::urls::detail::get_optional_string<char [5]>(char const (&) [5])
:34
91x
100.0%
100.0%
std::enable_if<std::is_convertible<char [6], boost::core::basic_string_view<char> >::value, boost::urls::detail::optional_string>::type boost::urls::detail::get_optional_string<char [6]>(char const (&) [6])
:34
51x
100.0%
100.0%
std::enable_if<std::is_convertible<char [7], boost::core::basic_string_view<char> >::value, boost::urls::detail::optional_string>::type boost::urls::detail::get_optional_string<char [7]>(char const (&) [7])
:34
21x
100.0%
100.0%
std::enable_if<std::is_convertible<char [9], boost::core::basic_string_view<char> >::value, boost::urls::detail::optional_string>::type boost::urls::detail::get_optional_string<char [9]>(char const (&) [9])
:34
24x
100.0%
100.0%
std::enable_if<std::is_convertible<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::core::basic_string_view<char> >::value, boost::urls::detail::optional_string>::type boost::urls::detail::get_optional_string<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
:34
1143x
100.0%
100.0%
std::enable_if<!std::is_convertible<boost::optional<boost::core::basic_string_view<char> >, boost::core::basic_string_view<char> >::value, boost::urls::detail::optional_string>::type boost::urls::detail::get_optional_string<boost::optional<boost::core::basic_string_view<char> > >(boost::optional<boost::core::basic_string_view<char> > const&)
:59
6x
100.0%
100.0%
boost::urls::detail::get_optional_string(decltype(nullptr))
:80
21x
100.0%
100.0%
boost::urls::detail::get_optional_string(boost::urls::no_value_t const&)
:88
929x
100.0%
100.0%
| Line | TLA | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com) | ||
| 3 | // | ||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 6 | // | ||
| 7 | // Official repository: https://github.com/boostorg/url | ||
| 8 | // | ||
| 9 | |||
| 10 | #ifndef BOOST_URL_DETAIL_OPTIONAL_STRING_HPP | ||
| 11 | #define BOOST_URL_DETAIL_OPTIONAL_STRING_HPP | ||
| 12 | |||
| 13 | #include <boost/url/detail/string_view.hpp> | ||
| 14 | #include <boost/core/detail/string_view.hpp> | ||
| 15 | |||
| 16 | namespace boost { | ||
| 17 | namespace urls { | ||
| 18 | |||
| 19 | #ifndef BOOST_URL_DOCS | ||
| 20 | struct no_value_t; | ||
| 21 | #endif | ||
| 22 | |||
| 23 | namespace detail { | ||
| 24 | struct optional_string | ||
| 25 | { | ||
| 26 | core::string_view s; | ||
| 27 | bool b = false; | ||
| 28 | }; | ||
| 29 | |||
| 30 | template <class String> | ||
| 31 | typename std::enable_if< | ||
| 32 | std::is_convertible<String, core::string_view>::value, | ||
| 33 | optional_string>::type | ||
| 34 | 1597x | get_optional_string( | |
| 35 | String const& s) | ||
| 36 | { | ||
| 37 | 1597x | optional_string r; | |
| 38 | 1597x | r.s = s; | |
| 39 | 1597x | r.b = true; | |
| 40 | 1597x | return r; | |
| 41 | } | ||
| 42 | |||
| 43 | template <class T, class = void> | ||
| 44 | struct is_dereferenceable : std::false_type | ||
| 45 | {}; | ||
| 46 | |||
| 47 | template <class T> | ||
| 48 | struct is_dereferenceable< | ||
| 49 | T, | ||
| 50 | void_t< | ||
| 51 | decltype(*std::declval<T>()) | ||
| 52 | >> : std::true_type | ||
| 53 | {}; | ||
| 54 | |||
| 55 | template <class OptionalString> | ||
| 56 | typename std::enable_if< | ||
| 57 | !std::is_convertible<OptionalString, core::string_view>::value, | ||
| 58 | optional_string>::type | ||
| 59 | 6x | get_optional_string( | |
| 60 | OptionalString const& opt) | ||
| 61 | { | ||
| 62 | // If this goes off, it means the rule | ||
| 63 | // passed in did not meet the requirements. | ||
| 64 | // Please check the documentation of functions | ||
| 65 | // that call get_optional_string. | ||
| 66 | static_assert( | ||
| 67 | is_dereferenceable<OptionalString>::value && | ||
| 68 | std::is_constructible<bool, OptionalString>::value && | ||
| 69 | !std::is_convertible<OptionalString, core::string_view>::value && | ||
| 70 | std::is_convertible<typename std::decay<decltype(*std::declval<OptionalString>())>::type, core::string_view>::value, | ||
| 71 | "OptionalString requirements not met"); | ||
| 72 | 6x | optional_string r; | |
| 73 | 6x | r.s = opt ? detail::to_sv(*opt) : core::string_view{}; | |
| 74 | 6x | r.b = static_cast<bool>(opt); | |
| 75 | 6x | return r; | |
| 76 | } | ||
| 77 | |||
| 78 | inline | ||
| 79 | optional_string | ||
| 80 | 21x | get_optional_string( | |
| 81 | std::nullptr_t) | ||
| 82 | { | ||
| 83 | 21x | return {}; | |
| 84 | } | ||
| 85 | |||
| 86 | inline | ||
| 87 | optional_string | ||
| 88 | 929x | get_optional_string( | |
| 89 | no_value_t const&) | ||
| 90 | { | ||
| 91 | 929x | return {}; | |
| 92 | } | ||
| 93 | |||
| 94 | |||
| 95 | } // detail | ||
| 96 | } // urls | ||
| 97 | } // boost | ||
| 98 | |||
| 99 | #endif | ||
| 100 |