GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 19 / 0 / 19
Functions: 100.0% 3 / 0 / 3
Branches: 100.0% 4 / 0 / 4

libs/url/src/detail/print.hpp
Line Branch Exec Source
1 //
2 // Copyright (c) 2019 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_DETAIL_PRINT_HPP
11 #define BOOST_URL_DETAIL_PRINT_HPP
12
13 #include <cstdint>
14 #include <type_traits>
15
16 namespace boost {
17 namespace urls {
18 namespace detail {
19
20 // std::uint64_t
21 // 18446744073709551615
22 // 1 2
23 template<class T>
24 struct printed
25 : std::false_type
26 {
27 };
28
29 // 16-bit unsigned
30 template<>
31 class printed<std::uint16_t>
32 : std::false_type
33 {
34 char n_;
35 char buf_[5];
36
37 public:
38 25 printed(std::uint16_t n)
39 25 {
40 25 char* it =
41 25 buf_ + sizeof(buf_);
42
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 9 times.
25 if(n == 0)
43 {
44 16 *--it = '0';
45 16 n_ = 1;
46 }
47 else
48 {
49
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 9 times.
45 while(n > 0)
50 {
51 36 *--it = '0' + (n % 10);
52 36 n /= 10;
53 }
54 9 n_ = static_cast<char>(
55 9 sizeof(buf_) - (
56 9 it - buf_));
57 }
58 25 }
59
60 core::string_view
61 75 string() const noexcept
62 {
63 150 return core::string_view(buf_ +
64 75 sizeof(buf_) - n_, n_);
65 }
66 };
67
68 template<class T>
69 printed<T>
70 25 make_printed(T t)
71 {
72 25 return printed<T>(t);
73 }
74
75 } // detail
76 } // urls
77 } // boost
78
79 #endif
80