segments_ref.ipp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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_IPP
  11. #define BOOST_URL_IMPL_SEGMENTS_REF_IPP
  12. #include <boost/url/segments_ref.hpp>
  13. #include <boost/url/url.hpp>
  14. #include <boost/url/detail/path.hpp>
  15. #include <boost/assert.hpp>
  16. namespace boost {
  17. namespace urls {
  18. //------------------------------------------------
  19. //
  20. // Special Members
  21. //
  22. //------------------------------------------------
  23. segments_ref::
  24. segments_ref(
  25. url_base& u) noexcept
  26. : segments_base(
  27. detail::path_ref(u.impl_))
  28. , u_(&u)
  29. {
  30. }
  31. segments_ref::
  32. operator
  33. segments_view() const noexcept
  34. {
  35. return segments_view(ref_);
  36. }
  37. segments_ref&
  38. segments_ref::
  39. operator=(segments_ref const& other)
  40. {
  41. if (!ref_.alias_of(other.ref_))
  42. assign(other.begin(), other.end());
  43. return *this;
  44. }
  45. segments_ref&
  46. segments_ref::
  47. operator=(segments_view const& other)
  48. {
  49. assign(other.begin(), other.end());
  50. return *this;
  51. }
  52. segments_ref&
  53. segments_ref::
  54. operator=(std::initializer_list<
  55. string_view> init)
  56. {
  57. assign(init.begin(), init.end());
  58. return *this;
  59. }
  60. //------------------------------------------------
  61. //
  62. // Modifiers
  63. //
  64. //------------------------------------------------
  65. void
  66. segments_ref::
  67. assign(std::initializer_list<
  68. string_view> init)
  69. {
  70. assign(init.begin(), init.end());
  71. }
  72. auto
  73. segments_ref::
  74. insert(
  75. iterator before,
  76. string_view s) ->
  77. iterator
  78. {
  79. return u_->edit_segments(
  80. before.it_,
  81. before.it_,
  82. detail::segment_iter(s));
  83. }
  84. auto
  85. segments_ref::
  86. insert(
  87. iterator before,
  88. std::initializer_list<
  89. string_view> init) ->
  90. iterator
  91. {
  92. return insert(
  93. before,
  94. init.begin(),
  95. init.end());
  96. }
  97. auto
  98. segments_ref::
  99. segments_ref::
  100. erase(
  101. iterator first,
  102. iterator last) noexcept ->
  103. iterator
  104. {
  105. string_view s;
  106. return u_->edit_segments(
  107. first.it_,
  108. last.it_,
  109. detail::make_segments_encoded_iter(
  110. &s, &s));
  111. }
  112. auto
  113. segments_ref::
  114. replace(
  115. iterator pos,
  116. string_view s) ->
  117. iterator
  118. {
  119. return u_->edit_segments(
  120. pos.it_,
  121. std::next(pos).it_,
  122. detail::segment_iter(s));
  123. }
  124. auto
  125. segments_ref::
  126. replace(
  127. iterator from,
  128. iterator to,
  129. string_view s) ->
  130. iterator
  131. {
  132. return u_->edit_segments(
  133. from.it_,
  134. to.it_,
  135. detail::segment_iter(s));
  136. }
  137. auto
  138. segments_ref::
  139. replace(
  140. iterator from,
  141. iterator to,
  142. std::initializer_list<
  143. string_view> init) ->
  144. iterator
  145. {
  146. return replace(
  147. from,
  148. to,
  149. init.begin(),
  150. init.end());
  151. }
  152. } // urls
  153. } // boost
  154. #endif