Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:26

0001  //
0002 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/url
0008 //
0009 
0010 #ifndef BOOST_URL_DETAIL_PRINT_HPP
0011 #define BOOST_URL_DETAIL_PRINT_HPP
0012 
0013 #include <cstdint>
0014 #include <type_traits>
0015 
0016 namespace boost {
0017 namespace urls {
0018 namespace detail {
0019 
0020 // std::uint64_t
0021 // 18446744073709551615
0022 //          1          2
0023 template<class T>
0024 struct printed
0025     : std::false_type
0026 {
0027 };
0028 
0029 // 16-bit unsigned
0030 template<>
0031 class printed<std::uint16_t>
0032     : std::false_type
0033 {
0034     char n_;
0035     char buf_[5];
0036 
0037 public:
0038     printed(std::uint16_t n)
0039     {
0040         char* it =
0041             buf_ + sizeof(buf_);
0042         if(n == 0)
0043         {
0044             *--it = '0';
0045             n_ = 1;
0046         }
0047         else
0048         {
0049             while(n > 0)
0050             {
0051                 *--it = '0' + (n % 10);
0052                 n /= 10;
0053             }
0054             n_ = static_cast<char>(
0055                 sizeof(buf_) - (
0056                     it - buf_));
0057         }
0058     }
0059 
0060     core::string_view
0061     string() const noexcept
0062     {
0063         return core::string_view(buf_ +
0064             sizeof(buf_) - n_, n_);
0065     }
0066 };
0067 
0068 template<class T>
0069 printed<T>
0070 make_printed(T t)
0071 {
0072     return printed<T>(t);
0073 }
0074 
0075 } // detail
0076 } // urls
0077 } // boost
0078 
0079 #endif