GCC Code Coverage Report


Directory: libs/url/
File: libs/url/src/pct_string_view.cpp
Date: 2023-12-15 15:31:49
Exec Total Coverage
Lines: 33 33 100.0%
Functions: 3 3 100.0%
Branches: 24 24 100.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2022 Vinnie Falco (vinnie.falco@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_PCT_STRING_VIEW_IPP
11 #define BOOST_URL_IMPL_PCT_STRING_VIEW_IPP
12
13 #include <boost/url/detail/config.hpp>
14 #include <boost/url/error.hpp>
15 #include <boost/url/pct_string_view.hpp>
16 #include <boost/url/detail/decode.hpp>
17 #include <boost/url/grammar/hexdig_chars.hpp>
18 #include <boost/url/detail/except.hpp>
19
20 namespace boost {
21 namespace urls {
22
23 void
24 3297 pct_string_view::
25 decode_impl(
26 string_token::arg& dest,
27 encoding_opts opt) const
28 {
29 3297 auto p = dest.prepare(dn_);
30
2/2
✓ Branch 0 taken 2521 times.
✓ Branch 1 taken 776 times.
3297 if(dn_ > 0)
31 2521 detail::decode_unsafe(
32 2521 p, p + dn_, s_, opt);
33 3297 }
34
35 //------------------------------------------------
36
37 5560 pct_string_view::
38 pct_string_view(
39 5560 core::string_view s)
40 : pct_string_view(
41 5560 make_pct_string_view(s
42
2/2
✓ Branch 3 taken 5482 times.
✓ Branch 4 taken 78 times.
5560 ).value(BOOST_URL_POS))
43 {
44 5482 }
45
46 //------------------------------------------------
47
48 system::result<pct_string_view>
49 5575 make_pct_string_view(
50 core::string_view s) noexcept
51 {
52 5575 auto p = s.begin();
53 5575 auto const end = s.end();
54 5575 std::size_t dn = 0;
55
2/2
✓ Branch 1 taken 2874 times.
✓ Branch 2 taken 2701 times.
5575 if(s.size() >= 3)
56 {
57 2874 auto const safe_end = end - 2;
58
2/2
✓ Branch 0 taken 18868 times.
✓ Branch 1 taken 2858 times.
21726 while(p < safe_end)
59 {
60
2/2
✓ Branch 0 taken 18124 times.
✓ Branch 1 taken 744 times.
18868 if(*p != '%')
61 {
62 18124 ++p;
63 }
64 744 else if(
65
6/6
✓ Branch 1 taken 739 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 728 times.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 728 times.
✓ Branch 6 taken 16 times.
1483 grammar::hexdig_value(p[1]) >= 0 &&
66 739 grammar::hexdig_value(p[2]) >= 0)
67 {
68 // percent-escape
69 728 p += 3;
70 }
71 else
72 {
73 // invalid encoding
74 16 BOOST_URL_RETURN_EC(
75 error::bad_pct_hexdig);
76 }
77 18852 ++dn;
78 }
79 }
80 5559 auto const n = end - p;
81
6/6
✓ Branch 0 taken 4108 times.
✓ Branch 1 taken 1451 times.
✓ Branch 2 taken 4051 times.
✓ Branch 3 taken 57 times.
✓ Branch 4 taken 3162 times.
✓ Branch 5 taken 2340 times.
5559 if( (n >= 1 && p[0] == '%') ||
82
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3157 times.
3162 (n >= 2 && p[1] == '%'))
83 {
84 // invalid encoding
85 62 BOOST_URL_RETURN_EC(
86 error::incomplete_encoding);
87 }
88 5497 dn += n;
89 5497 return make_pct_string_view_unsafe(
90 5497 s.data(), s.size(), dn);
91 }
92
93 } // urls
94 } // boost
95
96 #endif
97
98