segments_iter_impl.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #ifndef BOOST_URL_DETAIL_SEGMENTS_ITER_IMPL_HPP
  11. #define BOOST_URL_DETAIL_SEGMENTS_ITER_IMPL_HPP
  12. #include <boost/url/detail/parts_base.hpp>
  13. #include <boost/url/detail/url_impl.hpp>
  14. #include <boost/core/detail/string_view.hpp>
  15. #include <string>
  16. namespace boost {
  17. namespace urls {
  18. namespace detail {
  19. struct segments_iter_impl
  20. : private parts_base
  21. {
  22. path_ref ref; // parent path data the iterator aliases
  23. std::size_t pos = 0; // encoded offset of current segment start
  24. std::size_t next = 0; // encoded offset one past current segment
  25. std::size_t index = 0; // segment index within the parent path
  26. std::size_t dn = 0; // decoded length of current segment
  27. std::size_t decoded_prefix = 0; // decoded chars preceding current segment
  28. private:
  29. pct_string_view s_;
  30. public:
  31. segments_iter_impl() = default;
  32. segments_iter_impl(
  33. segments_iter_impl const&) noexcept = default;
  34. segments_iter_impl& operator=(
  35. segments_iter_impl const&) noexcept = default;
  36. // begin
  37. segments_iter_impl(
  38. detail::path_ref const&) noexcept;
  39. // end
  40. segments_iter_impl(
  41. detail::path_ref const&,
  42. int) noexcept;
  43. // at index
  44. segments_iter_impl(
  45. url_impl const& u_,
  46. std::size_t pos_,
  47. std::size_t i_) noexcept;
  48. void update() noexcept;
  49. BOOST_URL_DECL
  50. void
  51. increment() noexcept;
  52. BOOST_URL_DECL
  53. void
  54. decrement() noexcept;
  55. pct_string_view
  56. dereference() const noexcept
  57. {
  58. return s_;
  59. }
  60. std::size_t
  61. decoded_prefix_size() const noexcept
  62. {
  63. return decoded_prefix;
  64. }
  65. bool
  66. equal(
  67. segments_iter_impl const& other) const noexcept
  68. {
  69. BOOST_ASSERT(ref.alias_of(other.ref));
  70. return index == other.index;
  71. }
  72. };
  73. } // detail
  74. } // urls
  75. } // boost
  76. #endif