GCC Code Coverage Report


Directory: libs/url/
File: libs/url/src/detail/normalize.hpp
Date: 2024-04-08 19:38:36
Exec Total Coverage
Lines: 13 13 100.0%
Functions: 4 4 100.0%
Branches: 2 2 100.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot 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 #ifndef BOOST_URL_DETAIL_NORMALIZED_HPP
12 #define BOOST_URL_DETAIL_NORMALIZED_HPP
13
14 #include <boost/core/detail/string_view.hpp>
15 #include "boost/url/segments_encoded_view.hpp"
16
17 namespace boost {
18 namespace urls {
19 namespace detail {
20
21 class fnv_1a
22 {
23 public:
24 using digest_type = std::size_t;
25
26 #if BOOST_URL_ARCH == 64
27 static constexpr std::size_t const prime =
28 static_cast<std::size_t>(0x100000001B3ULL);
29 static constexpr std::size_t init_hash =
30 static_cast<std::size_t>(0xcbf29ce484222325ULL);
31 #else
32 static constexpr std::size_t const prime =
33 static_cast<std::size_t>(0x01000193UL);
34 static constexpr std::size_t init_hash =
35 static_cast<std::size_t>(0x811C9DC5UL);
36 #endif
37
38 explicit
39 304 fnv_1a(std::size_t salt) noexcept
40 304 : h_(init_hash + salt)
41 {
42 304 }
43
44 void
45 4550 put(char c) noexcept
46 {
47 4550 h_ ^= c;
48 4550 h_ *= prime;
49 4550 }
50
51 void
52 304 put(core::string_view s) noexcept
53 {
54
2/2
✓ Branch 2 taken 96 times.
✓ Branch 3 taken 304 times.
400 for (char c: s)
55 {
56 96 put(c);
57 }
58 304 }
59
60 digest_type
61 304 digest() const noexcept
62 {
63 304 return h_;
64 }
65
66 private:
67 std::size_t h_;
68 };
69
70 void
71 pop_encoded_front(
72 core::string_view& s,
73 char& c,
74 std::size_t& n) noexcept;
75
76 // compare two core::string_views as if they are both
77 // percent-decoded
78 int
79 compare_encoded(
80 core::string_view lhs,
81 core::string_view rhs) noexcept;
82
83 // digest a core::string_view as if it were
84 // percent-decoded
85 void
86 digest_encoded(
87 core::string_view s,
88 fnv_1a& hasher) noexcept;
89
90 void
91 digest(
92 core::string_view s,
93 fnv_1a& hasher) noexcept;
94
95 // check if core::string_view lhs starts with core::string_view
96 // rhs as if they are both percent-decoded. If
97 // lhs starts with rhs, return number of chars
98 // matched in the encoded core::string_view
99 std::size_t
100 path_starts_with(
101 core::string_view lhs,
102 core::string_view rhs) noexcept;
103
104 // check if core::string_view lhs ends with core::string_view
105 // rhs as if they are both percent-decoded. If
106 // lhs ends with rhs, return number of chars
107 // matched in the encoded core::string_view
108 std::size_t
109 path_ends_with(
110 core::string_view lhs,
111 core::string_view rhs) noexcept;
112
113 // compare two core::string_views as if they are both
114 // percent-decoded and lowercase
115 int
116 ci_compare_encoded(
117 core::string_view lhs,
118 core::string_view rhs) noexcept;
119
120 // digest a core::string_view as if it were decoded
121 // and lowercase
122 void
123 ci_digest_encoded(
124 core::string_view s,
125 fnv_1a& hasher) noexcept;
126
127 // compare two ascii core::string_views
128 int
129 compare(
130 core::string_view lhs,
131 core::string_view rhs) noexcept;
132
133 // compare two core::string_views as if they are both
134 // lowercase
135 int
136 ci_compare(
137 core::string_view lhs,
138 core::string_view rhs) noexcept;
139
140 // digest a core::string_view as if it were lowercase
141 void
142 ci_digest(
143 core::string_view s,
144 fnv_1a& hasher) noexcept;
145
146 BOOST_URL_DECL
147 std::size_t
148 remove_dot_segments(
149 char* dest,
150 char const* end,
151 core::string_view input) noexcept;
152
153 void
154 pop_last_segment(
155 core::string_view& str,
156 core::string_view& seg,
157 std::size_t& level,
158 bool remove_unmatched) noexcept;
159
160 char
161 path_pop_back( core::string_view& s );
162
163 void
164 normalized_path_digest(
165 core::string_view str,
166 bool remove_unmatched,
167 fnv_1a& hasher) noexcept;
168
169 int
170 segments_compare(
171 segments_encoded_view seg0,
172 segments_encoded_view seg1) noexcept;
173
174 } // detail
175 } // urls
176 } // boost
177
178 #endif
179