include/boost/url/rfc/detail/impl/userinfo_rule.hpp
95.8% Lines (23/24)
100.0% Functions (1/1)
| Line | TLA | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) | ||
| 3 | // Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com) | ||
| 4 | // | ||
| 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) | ||
| 7 | // | ||
| 8 | // Official repository: https://github.com/boostorg/url | ||
| 9 | // | ||
| 10 | |||
| 11 | #ifndef BOOST_URL_RFC_DETAIL_IMPL_USERINFO_RULE_HPP | ||
| 12 | #define BOOST_URL_RFC_DETAIL_IMPL_USERINFO_RULE_HPP | ||
| 13 | |||
| 14 | #include <boost/url/detail/config.hpp> | ||
| 15 | #include <boost/url/rfc/pct_encoded_rule.hpp> | ||
| 16 | #include <boost/url/rfc/sub_delim_chars.hpp> | ||
| 17 | #include <boost/url/rfc/unreserved_chars.hpp> | ||
| 18 | #include <boost/url/grammar/parse.hpp> | ||
| 19 | |||
| 20 | namespace boost { | ||
| 21 | namespace urls { | ||
| 22 | namespace detail { | ||
| 23 | |||
| 24 | BOOST_URL_CXX20_CONSTEXPR_OR_INLINE | ||
| 25 | auto | ||
| 26 | 1968 | userinfo_rule_t:: | |
| 27 | parse( | ||
| 28 | char const*& it, | ||
| 29 | char const* const end | ||
| 30 | ) const noexcept -> | ||
| 31 | system::result<value_type> | ||
| 32 | { | ||
| 33 | 1968 | constexpr auto uchars = | |
| 34 | unreserved_chars + | ||
| 35 | sub_delim_chars; | ||
| 36 | 1968 | constexpr auto pwchars = | |
| 37 | uchars + ':'; | ||
| 38 | |||
| 39 | 1968 | value_type t; | |
| 40 | |||
| 41 | // user | ||
| 42 | 1968 | auto rv = grammar::parse( | |
| 43 | 1968 | it, end, pct_encoded_rule( | |
| 44 | 1968 | grammar::ref(uchars))); | |
| 45 | 1968 | if(! rv) | |
| 46 | 8 | return rv.error(); | |
| 47 | 1960 | t.user = *rv; | |
| 48 | |||
| 49 | // ':' | ||
| 50 | 1960 | if( it == end || | |
| 51 | 1672 | *it != ':') | |
| 52 | { | ||
| 53 | 1521 | t.has_password = false; | |
| 54 | 1521 | t.password = {}; | |
| 55 | 1521 | return t; | |
| 56 | } | ||
| 57 | 439 | ++it; | |
| 58 | |||
| 59 | // pass | ||
| 60 | 439 | rv = grammar::parse( | |
| 61 | 439 | it, end, pct_encoded_rule( | |
| 62 | 439 | grammar::ref(pwchars))); | |
| 63 | 439 | if(! rv) | |
| 64 | ✗ | return rv.error(); | |
| 65 | |||
| 66 | 439 | t.has_password = true; | |
| 67 | 439 | t.password = *rv; | |
| 68 | 439 | return t; | |
| 69 | } | ||
| 70 | |||
| 71 | } // detail | ||
| 72 | } // urls | ||
| 73 | } // boost | ||
| 74 | |||
| 75 | |||
| 76 | #endif | ||
| 77 |