segments_ref.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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_IMPL_SEGMENTS_REF_HPP
  11. #define BOOST_URL_IMPL_SEGMENTS_REF_HPP
  12. #include <boost/url/detail/config.hpp>
  13. #include <boost/url/detail/any_segments_iter.hpp>
  14. #include <boost/url/detail/segments_iter_impl.hpp>
  15. #include <type_traits>
  16. namespace boost {
  17. namespace urls {
  18. //------------------------------------------------
  19. //
  20. // Modifiers
  21. //
  22. //------------------------------------------------
  23. inline
  24. void
  25. segments_ref::
  26. clear() noexcept
  27. {
  28. erase(begin(), end());
  29. }
  30. template<class FwdIt>
  31. void
  32. segments_ref::
  33. assign(FwdIt first, FwdIt last)
  34. {
  35. /* If you get a compile error here, it
  36. means that the iterators you passed
  37. do not meet the requirements stated
  38. in the documentation.
  39. */
  40. static_assert(
  41. std::is_convertible<
  42. typename std::iterator_traits<
  43. FwdIt>::reference,
  44. core::string_view>::value,
  45. "Type requirements not met");
  46. u_->edit_segments(
  47. begin().it_,
  48. end().it_,
  49. detail::make_segments_iter(
  50. first, last));
  51. }
  52. template<class FwdIt>
  53. auto
  54. segments_ref::
  55. insert(
  56. iterator before,
  57. FwdIt first,
  58. FwdIt last) ->
  59. iterator
  60. {
  61. /* If you get a compile error here, it
  62. means that the iterators you passed
  63. do not meet the requirements stated
  64. in the documentation.
  65. */
  66. static_assert(
  67. std::is_convertible<
  68. typename std::iterator_traits<
  69. FwdIt>::reference,
  70. core::string_view>::value,
  71. "Type requirements not met");
  72. return insert(
  73. before,
  74. first,
  75. last,
  76. typename std::iterator_traits<
  77. FwdIt>::iterator_category{});
  78. }
  79. inline
  80. auto
  81. segments_ref::
  82. erase(
  83. iterator pos) noexcept ->
  84. iterator
  85. {
  86. return erase(pos, std::next(pos));
  87. }
  88. template<class FwdIt>
  89. auto
  90. segments_ref::
  91. replace(
  92. iterator from,
  93. iterator to,
  94. FwdIt first,
  95. FwdIt last) ->
  96. iterator
  97. {
  98. /* If you get a compile error here, it
  99. means that the iterators you passed
  100. do not meet the requirements stated
  101. in the documentation.
  102. */
  103. static_assert(
  104. std::is_convertible<
  105. typename std::iterator_traits<
  106. FwdIt>::reference,
  107. core::string_view>::value,
  108. "Type requirements not met");
  109. return u_->edit_segments(
  110. from.it_,
  111. to.it_,
  112. detail::make_segments_iter(
  113. first, last));
  114. }
  115. //------------------------------------------------
  116. inline
  117. void
  118. segments_ref::
  119. push_back(
  120. core::string_view s)
  121. {
  122. insert(end(), s);
  123. }
  124. inline
  125. void
  126. segments_ref::
  127. pop_back() noexcept
  128. {
  129. erase(std::prev(end()));
  130. }
  131. //------------------------------------------------
  132. template<class FwdIt>
  133. auto
  134. segments_ref::
  135. insert(
  136. iterator before,
  137. FwdIt first,
  138. FwdIt last,
  139. std::forward_iterator_tag) ->
  140. iterator
  141. {
  142. return u_->edit_segments(
  143. before.it_,
  144. before.it_,
  145. detail::make_segments_iter(
  146. first, last));
  147. }
  148. } // urls
  149. } // boost
  150. #endif