| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- //
- // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
- //
- // Distributed under the Boost Software License, Version 1.0. (See accompanying
- // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- //
- // Official repository: https://github.com/boostorg/url
- //
- #ifndef BOOST_URL_IMPL_PCT_ENCODED_VIEW_HPP
- #define BOOST_URL_IMPL_PCT_ENCODED_VIEW_HPP
- #include <boost/url/grammar/type_traits.hpp>
- #include <boost/core/detail/static_assert.hpp>
- namespace boost {
- namespace urls {
- class decode_view::iterator
- {
- char const* begin_ = nullptr;
- char const* pos_ = nullptr;
- bool space_as_plus_ = true;
- friend decode_view;
- iterator(
- char const* str,
- bool space_as_plus) noexcept
- : begin_(str)
- , pos_(str)
- , space_as_plus_(
- space_as_plus)
- {
- }
- // end ctor
- iterator(
- char const* str,
- size_type n,
- bool space_as_plus) noexcept
- : begin_(str)
- , pos_(str + n)
- , space_as_plus_(space_as_plus)
- {
- }
- public:
- using value_type = char;
- using reference = char;
- using pointer = void const*;
- using const_reference = char;
- using size_type = std::size_t;
- using difference_type = std::ptrdiff_t;
- using iterator_category =
- std::bidirectional_iterator_tag;
- iterator() = default;
- iterator(iterator const&) = default;
- iterator&
- operator=(iterator const&) = default;
- BOOST_URL_DECL
- reference
- operator*() const noexcept;
- iterator&
- operator++() noexcept
- {
- BOOST_ASSERT(pos_ != nullptr);
- if (*pos_ != '%')
- ++pos_;
- else
- pos_ += 3;
- return *this;
- }
- iterator&
- operator--() noexcept
- {
- BOOST_ASSERT(pos_ != begin_);
- if (pos_ - begin_ < 3 ||
- pos_[-3] != '%')
- --pos_;
- else
- pos_ -= 3;
- return *this;
- }
- iterator
- operator++(int) noexcept
- {
- auto tmp = *this;
- ++*this;
- return tmp;
- }
- iterator
- operator--(int) noexcept
- {
- auto tmp = *this;
- --*this;
- return tmp;
- }
- char const*
- base()
- {
- return pos_;
- }
- bool
- operator==(
- iterator const& other) const noexcept
- {
- return pos_ == other.pos_;
- }
- bool
- operator!=(
- iterator const& other) const noexcept
- {
- return !(*this == other);
- }
- };
- //------------------------------------------------
- inline
- auto
- decode_view::
- begin() const noexcept ->
- const_iterator
- {
- return {p_, space_as_plus_};
- }
- inline
- auto
- decode_view::
- end() const noexcept ->
- const_iterator
- {
- return {p_, n_, space_as_plus_};
- }
- inline
- auto
- decode_view::
- front() const noexcept ->
- const_reference
- {
- BOOST_ASSERT( !empty() );
- return *begin();
- }
- inline
- auto
- decode_view::
- back() const noexcept ->
- const_reference
- {
- BOOST_ASSERT( !empty() );
- return *--end();
- }
- namespace detail {
- template <class T>
- BOOST_CXX14_CONSTEXPR
- int
- decoded_strcmp(decode_view s0, T s1)
- {
- auto const n0 = s0.size();
- auto const n1 = s1.size();
- auto n = (std::min)(n0, n1);
- auto it0 = s0.begin();
- auto it1 = s1.begin();
- while (n--)
- {
- const char c0 = *it0++;
- const char c1 = *it1++;
- if (c0 == c1)
- continue;
- return 1 - 2 * (static_cast<unsigned char>(c0)
- < static_cast<unsigned char>(c1));
- }
- return 1 - (n0 == n1) - 2 * (n0 < n1);
- }
- } // detail
- #if defined(BOOST_NO_CXX14_CONSTEXPR)
- inline
- #else
- BOOST_CXX14_CONSTEXPR
- #endif
- int
- decode_view::
- compare(core::string_view other) const noexcept
- {
- return detail::decoded_strcmp(*this, other);
- }
- #if defined(BOOST_NO_CXX14_CONSTEXPR)
- inline
- #else
- BOOST_CXX14_CONSTEXPR
- #endif
- int
- decode_view::
- compare(decode_view other) const noexcept
- {
- return detail::decoded_strcmp(*this, other);
- }
- } // urls
- } // boost
- #endif
|