src/segments_base.cpp
100.0% Lines (33/33)
100.0% Functions (12/12)
60.0% Branches (3/5)
src/segments_base.cpp
| Line | Branch | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // Copyright (c) 2022 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 | |||
| 12 | #include <boost/url/detail/config.hpp> | ||
| 13 | #include <boost/url/segments_base.hpp> | ||
| 14 | #include <boost/assert.hpp> | ||
| 15 | #include <ostream> | ||
| 16 | |||
| 17 | namespace boost { | ||
| 18 | namespace urls { | ||
| 19 | |||
| 20 | 404 | segments_base:: | |
| 21 | segments_base( | ||
| 22 | 404 | detail::path_ref const& ref) noexcept | |
| 23 | 404 | : ref_(ref) | |
| 24 | { | ||
| 25 | 404 | } | |
| 26 | |||
| 27 | 539 | segments_base:: | |
| 28 | iterator:: | ||
| 29 | iterator( | ||
| 30 | 539 | detail::path_ref const& ref) noexcept | |
| 31 | 539 | : it_(ref) | |
| 32 | { | ||
| 33 | 539 | } | |
| 34 | |||
| 35 | 411 | segments_base:: | |
| 36 | iterator:: | ||
| 37 | iterator( | ||
| 38 | detail::path_ref const& ref, | ||
| 39 | 411 | int) noexcept | |
| 40 | 411 | : it_(ref, 0) | |
| 41 | { | ||
| 42 | 411 | } | |
| 43 | |||
| 44 | //------------------------------------------------ | ||
| 45 | // | ||
| 46 | // segments_base | ||
| 47 | // | ||
| 48 | //------------------------------------------------ | ||
| 49 | |||
| 50 | |||
| 51 | |||
| 52 | pct_string_view | ||
| 53 | 79 | segments_base:: | |
| 54 | buffer() const noexcept | ||
| 55 | { | ||
| 56 | 79 | return ref_.buffer(); | |
| 57 | } | ||
| 58 | |||
| 59 | bool | ||
| 60 | 41 | segments_base:: | |
| 61 | is_absolute() const noexcept | ||
| 62 | { | ||
| 63 | 41 | return ref_.buffer().starts_with('/'); | |
| 64 | } | ||
| 65 | |||
| 66 | bool | ||
| 67 | 81 | segments_base:: | |
| 68 | empty() const noexcept | ||
| 69 | { | ||
| 70 | 81 | return ref_.nseg() == 0; | |
| 71 | } | ||
| 72 | |||
| 73 | std::size_t | ||
| 74 | 291 | segments_base:: | |
| 75 | size() const noexcept | ||
| 76 | { | ||
| 77 | 291 | return ref_.nseg(); | |
| 78 | } | ||
| 79 | |||
| 80 | std::string | ||
| 81 | 27 | segments_base:: | |
| 82 | front() const noexcept | ||
| 83 | { | ||
| 84 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
|
27 | BOOST_ASSERT(! empty()); |
| 85 | 27 | return *begin(); | |
| 86 | } | ||
| 87 | |||
| 88 | std::string | ||
| 89 | 20 | segments_base:: | |
| 90 | back() const noexcept | ||
| 91 | { | ||
| 92 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
|
20 | BOOST_ASSERT(! empty()); |
| 93 | 20 | return *--end(); | |
| 94 | } | ||
| 95 | |||
| 96 | auto | ||
| 97 | 539 | segments_base:: | |
| 98 | begin() const noexcept -> | ||
| 99 | iterator | ||
| 100 | { | ||
| 101 | 539 | return iterator(ref_); | |
| 102 | } | ||
| 103 | |||
| 104 | auto | ||
| 105 | 411 | segments_base:: | |
| 106 | end() const noexcept -> | ||
| 107 | iterator | ||
| 108 | { | ||
| 109 | 411 | return iterator(ref_, 0); | |
| 110 | } | ||
| 111 | |||
| 112 | //------------------------------------------------ | ||
| 113 | |||
| 114 | std::ostream& | ||
| 115 | 15 | operator<<( | |
| 116 | std::ostream& os, | ||
| 117 | segments_base const& ps) | ||
| 118 | { | ||
| 119 |
1/1✓ Branch 2 taken 15 times.
|
15 | os << ps.buffer(); |
| 120 | 15 | return os; | |
| 121 | } | ||
| 122 | |||
| 123 | } // urls | ||
| 124 | } // boost | ||
| 125 | |||
| 126 |