params_encoded_ref.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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_PARAMS_ENCODED_REF_HPP
  11. #define BOOST_URL_IMPL_PARAMS_ENCODED_REF_HPP
  12. #include <boost/url/detail/except.hpp>
  13. #include <boost/assert.hpp>
  14. namespace boost {
  15. namespace urls {
  16. //------------------------------------------------
  17. //
  18. // Modifiers
  19. //
  20. //------------------------------------------------
  21. inline
  22. void
  23. params_encoded_ref::
  24. clear() noexcept
  25. {
  26. u_->remove_query();
  27. }
  28. template<class FwdIt>
  29. void
  30. params_encoded_ref::
  31. assign(FwdIt first, FwdIt last)
  32. {
  33. /* If you get a compile error here, it
  34. means that the iterators you passed
  35. do not meet the requirements stated
  36. in the documentation.
  37. */
  38. static_assert(
  39. std::is_convertible<
  40. typename std::iterator_traits<
  41. FwdIt>::reference,
  42. param_view>::value,
  43. "Type requirements not met");
  44. assign(first, last,
  45. typename std::iterator_traits<
  46. FwdIt>::iterator_category{});
  47. }
  48. inline
  49. auto
  50. params_encoded_ref::
  51. append(
  52. param_pct_view const& p) ->
  53. iterator
  54. {
  55. return insert(end(), p);
  56. }
  57. inline
  58. auto
  59. params_encoded_ref::
  60. append(
  61. std::initializer_list<
  62. param_pct_view> init) ->
  63. iterator
  64. {
  65. return insert(end(), init);
  66. }
  67. template<class FwdIt>
  68. auto
  69. params_encoded_ref::
  70. append(
  71. FwdIt first, FwdIt last) ->
  72. iterator
  73. {
  74. /* If you get a compile error here, it
  75. means that the iterators you passed
  76. do not meet the requirements stated
  77. in the documentation.
  78. */
  79. static_assert(
  80. std::is_convertible<
  81. typename std::iterator_traits<
  82. FwdIt>::reference,
  83. param_view>::value,
  84. "Type requirements not met");
  85. return insert(
  86. end(), first, last);
  87. }
  88. template<class FwdIt>
  89. auto
  90. params_encoded_ref::
  91. insert(
  92. iterator before,
  93. FwdIt first,
  94. FwdIt last) ->
  95. iterator
  96. {
  97. /* If you get a compile error here, it
  98. means that the iterators you passed
  99. do not meet the requirements stated
  100. in the documentation.
  101. */
  102. static_assert(
  103. std::is_convertible<
  104. typename std::iterator_traits<
  105. FwdIt>::reference,
  106. param_view>::value,
  107. "Type requirements not met");
  108. return insert(
  109. before,
  110. first,
  111. last,
  112. typename std::iterator_traits<
  113. FwdIt>::iterator_category{});
  114. }
  115. template<class FwdIt>
  116. auto
  117. params_encoded_ref::
  118. replace(
  119. iterator from,
  120. iterator to,
  121. FwdIt first,
  122. FwdIt last) ->
  123. iterator
  124. {
  125. /* If you get a compile error here, it
  126. means that the iterators you passed
  127. do not meet the requirements stated
  128. in the documentation.
  129. */
  130. static_assert(
  131. std::is_convertible<
  132. typename std::iterator_traits<
  133. FwdIt>::reference,
  134. param_view>::value,
  135. "Type requirements not met");
  136. return u_->edit_params(
  137. from.it_, to.it_,
  138. detail::make_params_encoded_iter(
  139. first, last));
  140. }
  141. //------------------------------------------------
  142. //
  143. // implementation
  144. //
  145. //------------------------------------------------
  146. template<class FwdIt>
  147. void
  148. params_encoded_ref::
  149. assign(FwdIt first, FwdIt last,
  150. std::forward_iterator_tag)
  151. {
  152. u_->edit_params(
  153. begin().it_,
  154. end().it_,
  155. detail::make_params_encoded_iter(
  156. first, last));
  157. }
  158. template<class FwdIt>
  159. auto
  160. params_encoded_ref::
  161. insert(
  162. iterator before,
  163. FwdIt first,
  164. FwdIt last,
  165. std::forward_iterator_tag) ->
  166. iterator
  167. {
  168. return u_->edit_params(
  169. before.it_,
  170. before.it_,
  171. detail::make_params_encoded_iter(
  172. first, last));
  173. }
  174. } // urls
  175. } // boost
  176. #endif