GCC Code Coverage Report


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

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 23 printed(std::uint16_t n)
39 23 {
40 23 char* it =
41 23 buf_ + sizeof(buf_);
42
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 7 times.
23 if(n == 0)
43 {
44 16 *--it = '0';
45 16 n_ = 1;
46 }
47 else
48 {
49
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
35 while(n > 0)
50 {
51 28 *--it = '0' + (n % 10);
52 28 n /= 10;
53 }
54 7 n_ = static_cast<char>(
55 7 sizeof(buf_) - (
56 7 it - buf_));
57 }
58 23 }
59
60 core::string_view
61 69 string() const noexcept
62 {
63 138 return core::string_view(buf_ +
64 69 sizeof(buf_) - n_, n_);
65 }
66 };
67
68 template<class T>
69 printed<T>
70 23 make_printed(T t)
71 {
72 23 return printed<T>(t);
73 }
74
75 } // detail
76 } // urls
77 } // boost
78
79 #endif
80