segments_encoded_ref.hpp 3.4 KB

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