LCOV - code coverage report
Current view: top level - http_proto/detail - number_string.hpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 0 25 0.0 %
Date: 2023-01-15 07:18:31 Functions: 0 6 0.0 %

          Line data    Source code
       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/CPPAlliance/http_proto
       8             : //
       9             : 
      10             : #ifndef BOOST_HTTP_PROTO_DETAIL_NUMBER_STRING_HPP
      11             : #define BOOST_HTTP_PROTO_DETAIL_NUMBER_STRING_HPP
      12             : 
      13             : #include <boost/http_proto/detail/config.hpp>
      14             : #include <cstdint>
      15             : 
      16             : namespace boost {
      17             : namespace http_proto {
      18             : namespace detail {
      19             : 
      20             : // Convert integer to decimal
      21             : // string using in-place storage
      22             : class number_string
      23             : {
      24             :     static constexpr unsigned buf_size = 18;
      25             :     char buf_[buf_size + 1];
      26             :     std::size_t size_ = 0;
      27             : 
      28             :     void
      29           0 :     construct_unsigned(
      30             :         std::uint64_t n) noexcept
      31             :     {
      32           0 :         buf_[buf_size] = '\0';
      33           0 :         auto const end =
      34             :             &buf_[buf_size];
      35           0 :         auto p = end;
      36           0 :         if(n == 0)
      37             :         {
      38           0 :             *--p = '0';
      39             :         }
      40             :         else
      41             :         {
      42           0 :             while(n > 0)
      43             :             {
      44           0 :                 *--p = '0' + (n%10);
      45           0 :                 n /= 10;
      46             :             }
      47             :         }
      48           0 :         size_ = end - p;
      49           0 :     }
      50             : 
      51             : public:
      52             :     number_string() = default;
      53             :     number_string(
      54             :         number_string const&) = default;
      55             :     number_string& operator=
      56             :         (number_string const&) = default;
      57             : 
      58             :     explicit
      59           0 :     number_string(
      60             :         std::uint64_t n) noexcept
      61           0 :     {
      62           0 :         construct_unsigned(n);
      63           0 :     }
      64             : 
      65             :     char const*
      66           0 :     data() const noexcept
      67             :     {
      68           0 :         return &buf_[
      69           0 :             buf_size] - size_;
      70             :     }
      71             : 
      72             :     std::size_t
      73           0 :     size() const noexcept
      74             :     {
      75           0 :         return size_;
      76             :     }
      77             : 
      78             :     string_view
      79           0 :     str() const noexcept
      80             :     {
      81           0 :         return string_view(
      82           0 :             data(), size());
      83             :     }
      84             : 
      85           0 :     operator
      86             :     string_view() const noexcept
      87             :     {
      88           0 :         return str();
      89             :     }
      90             : };
      91             : 
      92             : } // detail
      93             : } // http_proto
      94             : } // boost
      95             : 
      96             : #endif

Generated by: LCOV version 1.15