LCOV - code coverage report
Current view: top level - libs/url/src/params_encoded_ref.cpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 97.4 % 76 74
Test Date: 2024-08-20 16:05:53 Functions: 100.0 % 15 15

            Line data    Source code
       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              : 
      11              : 
      12              : #include <boost/url/detail/config.hpp>
      13              : #include <boost/url/decode_view.hpp>
      14              : #include <boost/url/params_encoded_ref.hpp>
      15              : #include <boost/url/params_encoded_view.hpp>
      16              : #include <boost/url/url_base.hpp>
      17              : #include <boost/url/grammar/ci_string.hpp>
      18              : #include <boost/assert.hpp>
      19              : #include <utility>
      20              : 
      21              : namespace boost {
      22              : namespace urls {
      23              : 
      24              : //------------------------------------------------
      25              : //
      26              : // Special Members
      27              : //
      28              : //------------------------------------------------
      29              : 
      30           77 : params_encoded_ref::
      31              : params_encoded_ref(
      32           77 :     url_base& u) noexcept
      33           77 :     : params_encoded_base(u.impl_)
      34           77 :     , u_(&u)
      35              : {
      36           77 : }
      37              : 
      38              : params_encoded_ref&
      39            1 : params_encoded_ref::
      40              : operator=(
      41              :     params_encoded_ref const& other)
      42              : {
      43            1 :     if (!ref_.alias_of( other.ref_ ))
      44            1 :         assign(other.begin(), other.end());
      45            1 :     return *this;
      46              : }
      47              : 
      48              : params_encoded_ref&
      49            2 : params_encoded_ref::
      50              : operator=(std::initializer_list<
      51              :     param_pct_view> init)
      52              : {
      53            2 :     assign(init.begin(), init.end());
      54            2 :     return *this;
      55              : }
      56              : 
      57           58 : params_encoded_ref::
      58              : operator
      59              : params_encoded_view() const noexcept
      60              : {
      61           58 :     return {ref_};
      62              : }
      63              : 
      64              : //------------------------------------------------
      65              : //
      66              : // Modifiers
      67              : //
      68              : //------------------------------------------------
      69              : 
      70              : void
      71            3 : params_encoded_ref::
      72              : assign(
      73              :     std::initializer_list<
      74              :         param_pct_view> init)
      75              : {
      76            3 :     assign(init.begin(), init.end());
      77            3 : }
      78              : 
      79              : auto
      80            7 : params_encoded_ref::
      81              : insert(
      82              :     iterator before,
      83              :     param_pct_view const& p) ->
      84              :         iterator
      85              : {
      86            7 :     return u_->edit_params(
      87              :         before.it_,
      88              :         before.it_,
      89           14 :         detail::param_encoded_iter(p));
      90              : }
      91              : 
      92              : auto
      93           12 : params_encoded_ref::
      94              : insert(
      95              :     iterator before,
      96              :     std::initializer_list<
      97              :         param_pct_view> init) ->
      98              :     iterator
      99              : {
     100           12 :     return insert(
     101              :         before,
     102              :         init.begin(),
     103           12 :         init.end());
     104              : }
     105              : 
     106              : std::size_t
     107            2 : params_encoded_ref::
     108              : erase(
     109              :     pct_string_view key,
     110              :     ignore_case_param ic) noexcept
     111              : {
     112              :     // end() can't be fully cached,
     113              :     // since erase invalidates it.
     114            2 :     iterator it;
     115              :     {
     116            2 :         auto const end_ = end();
     117            2 :         it = find_last(end_, key, ic);
     118            2 :         if(it == end_)
     119            0 :             return 0;
     120              :     }
     121            2 :     std::size_t n = 0;
     122              :     for(;;)
     123              :     {
     124            5 :         ++n;
     125              :         // Use it->key instead of key,
     126              :         // to handle self-intersection
     127            5 :         auto prev = find_last(it, it->key, ic);
     128            5 :         if(prev == end())
     129            2 :             break;
     130            3 :         erase(it);
     131            3 :         it = prev;
     132            3 :     }
     133            2 :     erase(it);
     134            2 :     return n;
     135              : }
     136              : 
     137              : auto
     138            5 : params_encoded_ref::
     139              : replace(
     140              :     iterator pos,
     141              :     param_pct_view const& p) ->
     142              :         iterator
     143              : {
     144            5 :     return u_->edit_params(
     145              :         pos.it_,
     146            5 :         std::next(pos).it_,
     147           10 :         detail::param_encoded_iter(p));
     148              : }
     149              : 
     150              : auto
     151            1 : params_encoded_ref::
     152              : replace(
     153              :     iterator from,
     154              :     iterator to,
     155              :     std::initializer_list<
     156              :         param_pct_view> init) ->
     157              :     iterator
     158              : {
     159            1 :     return replace(
     160              :         from,
     161              :         to,
     162              :         init.begin(),
     163            1 :         init.end());
     164              : }
     165              : 
     166              : auto
     167            4 : params_encoded_ref::
     168              : unset(
     169              :     iterator pos) noexcept ->
     170              :         iterator
     171              : {
     172            4 :     BOOST_ASSERT(pos.it_.nk > 0);
     173            4 :     pct_string_view s;
     174            4 :     return u_->edit_params(
     175            4 :         pos.it_, pos.it_.next(),
     176            4 :         detail::param_encoded_value_iter(
     177            8 :             pos.it_.nk - 1, s, false));
     178              : }
     179              : 
     180              : auto
     181            4 : params_encoded_ref::
     182              : set(
     183              :     iterator pos,
     184              :     pct_string_view value) ->
     185              :         iterator
     186              : {
     187            4 :     BOOST_ASSERT(pos.it_.nk > 0);
     188            4 :     return u_->edit_params(
     189              :         pos.it_,
     190            4 :         pos.it_.next(),
     191            4 :         detail::param_encoded_value_iter(
     192           12 :             pos.it_.nk - 1, value, true));
     193              : }
     194              : 
     195              : auto
     196            1 : params_encoded_ref::
     197              : set(
     198              :     pct_string_view key,
     199              :     pct_string_view value,
     200              :     ignore_case_param ic) ->
     201              :         iterator
     202              : {
     203              :     // VFALCO we can't cache end() here
     204              :     // because it is invalidated
     205              :     // every time we set or erase.
     206            1 :     auto it0 = find(key, ic);
     207            1 :     if(it0 == end())
     208            0 :         return append({key, value});
     209            1 :     it0 = set(it0, value);
     210            1 :     auto it = end();
     211              :     for(;;)
     212              :     {
     213            2 :         it = find_last(it, key, ic);
     214            2 :         if(it == it0)
     215            1 :             return it0;
     216            1 :         it = erase(it);
     217              :     }
     218              : }
     219              : 
     220              : auto
     221            9 : params_encoded_ref::
     222              : erase(
     223              :     iterator pos) noexcept ->
     224              :         iterator
     225              : {
     226            9 :     return erase(
     227              :         pos,
     228            9 :         std::next(pos));
     229              : }
     230              : 
     231              : auto
     232           11 : params_encoded_ref::
     233              : erase(
     234              :     iterator first,
     235              :     iterator last) noexcept ->
     236              :         iterator
     237              : {
     238           11 :     core::string_view s("", 0);
     239           11 :     return u_->edit_params(
     240              :         first.it_,
     241              :         last.it_,
     242           22 :         detail::query_iter(s));
     243              : }
     244              : 
     245              : } // urls
     246              : } // boost
     247              : 
        

Generated by: LCOV version 2.1