LCOV - code coverage report
Current view: top level - boost/url/impl/decode.hpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 24 24
Test Date: 2025-11-12 22:47:43 Functions: 100.0 % 4 4

            Line data    Source code
       1              : //
       2              : // Copyright (c) 2025 Alan de Freitas (alandefreitas@gmail.com)
       3              : //
       4              : // Distributed under the Boost Software License, Version 1.0. (See accompanying
       5              : // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
       6              : //
       7              : // Official repository: https://github.com/boostorg/url
       8              : //
       9              : 
      10              : #ifndef BOOST_URL_IMPL_DECODE_HPP
      11              : #define BOOST_URL_IMPL_DECODE_HPP
      12              : 
      13              : #include <boost/assert.hpp>
      14              : #include <boost/url/detail/decode.hpp>
      15              : #include <boost/url/detail/string_view.hpp>
      16              : #include <boost/url/pct_string_view.hpp>
      17              : #include <utility>
      18              : 
      19              : namespace boost {
      20              : namespace urls {
      21              : 
      22              : inline
      23              : system::result<std::size_t>
      24            5 : decoded_size(core::string_view s) noexcept
      25              : {
      26            5 :     auto const rv = make_pct_string_view(s);
      27            5 :     if(! rv)
      28            1 :         return rv.error();
      29            4 :     return rv->decoded_size();
      30              : }
      31              : 
      32              : inline
      33              : system::result<std::size_t>
      34            7 : decode(
      35              :     char* dest,
      36              :     std::size_t size,
      37              :     core::string_view s,
      38              :     encoding_opts opt) noexcept
      39              : {
      40            7 :     auto const rv = make_pct_string_view(s);
      41            7 :     if(! rv)
      42            1 :         return rv.error();
      43           12 :     return detail::decode_unsafe(
      44              :         dest,
      45            6 :         dest + size,
      46            6 :         detail::to_sv(rv.value()),
      47            6 :         opt);
      48              : }
      49              : 
      50              : template<
      51              :     BOOST_URL_CONSTRAINT(string_token::StringToken) StringToken>
      52              : system::result<typename StringToken::result_type>
      53            7 : decode(
      54              :     core::string_view s,
      55              :     encoding_opts opt,
      56              :     StringToken&& token) noexcept
      57              : {
      58              :     static_assert(
      59              :         string_token::is_token<
      60              :             StringToken>::value,
      61              :         "Type requirements not met");
      62              : 
      63            7 :     auto const rv = make_pct_string_view(s);
      64            7 :     if(! rv)
      65            1 :         return rv.error();
      66              : 
      67            6 :     auto const n = rv->decoded_size();
      68            6 :     auto p = token.prepare(n);
      69              :     // Some tokens might hand back a null/invalid buffer for n == 0, so skip the
      70              :     // decode call entirely in that case to avoid touching unspecified memory.
      71            6 :     if(n > 0)
      72           12 :         detail::decode_unsafe(
      73              :             p,
      74            6 :             p + n,
      75            6 :             detail::to_sv(rv.value()),
      76              :             opt);
      77            6 :     return token.result();
      78              : }
      79              : 
      80              : } // urls
      81              : } // boost
      82              : 
      83              : #endif
        

Generated by: LCOV version 2.1