2 // Copyright (c) 2016-2017 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>
46 lexicographical_compare(
47 basic_string_view<CharT, Traits> s1,
48 CharT const* s2, std::size_t n2)
50 return lexicographical_compare<CharT, Traits>(
51 s1.data(), s1.size(), s2, n2);
54 template<class CharT, class Traits>
57 lexicographical_compare(
58 basic_string_view<CharT, Traits> s1,
59 basic_string_view<CharT, Traits> s2)
61 return lexicographical_compare<CharT, Traits>(
62 s1.data(), s1.size(), s2.data(), s2.size());
65 // Maximum number of characters in the decimal
66 // representation of a binary number. This includes
67 // the potential minus sign.
71 max_digits(std::size_t bytes)
73 return static_cast<std::size_t>(
74 bytes * 2.41) + 1 + 1;
77 template<class CharT, class Integer, class Traits>
80 CharT* buf, Integer x, std::true_type)
84 Traits::assign(*--buf, '0');
91 Traits::assign(*--buf ,
92 "0123456789"[x % 10]);
93 Traits::assign(*--buf, '-');
97 Traits::assign(*--buf ,
98 "0123456789"[x % 10]);
102 template<class CharT, class Integer, class Traits>
105 CharT* buf, Integer x, std::false_type)
113 Traits::assign(*--buf ,
114 "0123456789"[x % 10]);
121 class Traits = std::char_traits<CharT>>
123 raw_to_string(CharT* last, std::size_t size, Integer i)
125 boost::ignore_unused(size);
126 BOOST_ASSERT(size >= max_digits(sizeof(Integer)));
127 return raw_to_string<CharT, Integer, Traits>(
128 last, i, std::is_signed<Integer>{});