2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
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)
7 // Official repository: https://github.com/boostorg/beast
10 #ifndef BOOST_BEAST_DETAIL_STATIC_STRING_HPP
11 #define BOOST_BEAST_DETAIL_STATIC_STRING_HPP
13 #include <boost/beast/core/string.hpp>
14 #include <boost/assert.hpp>
16 #include <type_traits>
22 // Because k-ballo said so
24 using is_input_iterator =
25 std::integral_constant<bool,
26 ! std::is_integral<T>::value>;
28 template<class CharT, class Traits>
30 lexicographical_compare(
31 CharT const* s1, std::size_t n1,
32 CharT const* s2, std::size_t n2)
35 return Traits::compare(
36 s1, s2, n1) <= 0 ? -1 : 1;
38 return Traits::compare(
39 s1, s2, n2) >= 0 ? 1 : -1;
40 return Traits::compare(s1, s2, n1);
43 template<class CharT, class Traits>
45 lexicographical_compare(
46 basic_string_view<CharT, Traits> s1,
47 CharT const* s2, std::size_t n2)
49 return detail::lexicographical_compare<
50 CharT, Traits>(s1.data(), s1.size(), s2, n2);
53 template<class CharT, class Traits>
55 lexicographical_compare(
56 basic_string_view<CharT, Traits> s1,
57 basic_string_view<CharT, Traits> s2)
59 return detail::lexicographical_compare<CharT, Traits>(
60 s1.data(), s1.size(), s2.data(), s2.size());
63 // Maximum number of characters in the decimal
64 // representation of a binary number. This includes
65 // the potential minus sign.
69 max_digits(std::size_t bytes)
71 return static_cast<std::size_t>(
72 bytes * 2.41) + 1 + 1;
75 template<class CharT, class Integer, class Traits>
78 CharT* buf, Integer x, std::true_type)
82 Traits::assign(*--buf, '0');
89 Traits::assign(*--buf ,
90 "0123456789"[x % 10]);
91 Traits::assign(*--buf, '-');
95 Traits::assign(*--buf ,
96 "0123456789"[x % 10]);
100 template<class CharT, class Integer, class Traits>
103 CharT* buf, Integer x, std::false_type)
111 Traits::assign(*--buf ,
112 "0123456789"[x % 10]);
119 class Traits = std::char_traits<CharT>>
121 raw_to_string(CharT* last, std::size_t size, Integer i)
123 boost::ignore_unused(size);
124 BOOST_ASSERT(size >= max_digits(sizeof(Integer)));
125 return raw_to_string<CharT, Integer, Traits>(
126 last, i, std::is_signed<Integer>{});