100.00% Lines (19/19) 100.00% Functions (3/3)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 2   // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3   // 3   //
4   // Distributed under the Boost Software License, Version 1.0. (See accompanying 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) 5   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6   // 6   //
7   // Official repository: https://github.com/boostorg/url 7   // Official repository: https://github.com/boostorg/url
8   // 8   //
9   9  
10   #ifndef BOOST_URL_DETAIL_PRINT_HPP 10   #ifndef BOOST_URL_DETAIL_PRINT_HPP
11   #define BOOST_URL_DETAIL_PRINT_HPP 11   #define BOOST_URL_DETAIL_PRINT_HPP
12   12  
13   #include <boost/core/detail/string_view.hpp> 13   #include <boost/core/detail/string_view.hpp>
14   #include <cstdint> 14   #include <cstdint>
15   #include <type_traits> 15   #include <type_traits>
16   16  
17   namespace boost { 17   namespace boost {
18   namespace urls { 18   namespace urls {
19   namespace detail { 19   namespace detail {
20   20  
21   // std::uint64_t 21   // std::uint64_t
22   // 18446744073709551615 22   // 18446744073709551615
23   // 1 2 23   // 1 2
24   template<class T> 24   template<class T>
25   struct printed 25   struct printed
26   : std::false_type 26   : std::false_type
27   { 27   {
28   }; 28   };
29   29  
30   // 16-bit unsigned 30   // 16-bit unsigned
31   template<> 31   template<>
32   class printed<std::uint16_t> 32   class printed<std::uint16_t>
33   : std::false_type 33   : std::false_type
34   { 34   {
35   char n_; 35   char n_;
36   char buf_[5]; 36   char buf_[5];
37   37  
38   public: 38   public:
HITCBC 39   215 printed(std::uint16_t n) 39   215 printed(std::uint16_t n)
HITCBC 40   215 { 40   215 {
HITCBC 41   215 char* it = 41   215 char* it =
HITCBC 42   215 buf_ + sizeof(buf_); 42   215 buf_ + sizeof(buf_);
HITCBC 43   215 if(n == 0) 43   215 if(n == 0)
44   { 44   {
HITCBC 45   16 *--it = '0'; 45   16 *--it = '0';
HITCBC 46   16 n_ = 1; 46   16 n_ = 1;
47   } 47   }
48   else 48   else
49   { 49   {
HITCBC 50   1145 while(n > 0) 50   1145 while(n > 0)
51   { 51   {
HITCBC 52   946 *--it = '0' + (n % 10); 52   946 *--it = '0' + (n % 10);
HITCBC 53   946 n /= 10; 53   946 n /= 10;
54   } 54   }
HITCBC 55   199 n_ = static_cast<char>( 55   199 n_ = static_cast<char>(
HITCBC 56   199 sizeof(buf_) - ( 56   199 sizeof(buf_) - (
HITCBC 57   199 it - buf_)); 57   199 it - buf_));
58   } 58   }
HITCBC 59   215 } 59   215 }
60   60  
61   core::string_view 61   core::string_view
HITCBC 62   645 string() const noexcept 62   645 string() const noexcept
63   { 63   {
HITCBC 64   1290 return core::string_view(buf_ + 64   1290 return core::string_view(buf_ +
HITCBC 65   645 sizeof(buf_) - n_, n_); 65   645 sizeof(buf_) - n_, n_);
66   } 66   }
67   }; 67   };
68   68  
69   template<class T> 69   template<class T>
70   printed<T> 70   printed<T>
HITCBC 71   215 make_printed(T t) 71   215 make_printed(T t)
72   { 72   {
HITCBC 73   215 return printed<T>(t); 73   215 return printed<T>(t);
74   } 74   }
75   75  
76   } // detail 76   } // detail
77   } // urls 77   } // urls
78   } // boost 78   } // boost
79   79  
80   #endif 80   #endif