1// Slightly modified version of fmt lib's format.cc source file.
2// Copyright (c) 2012 - 2016, Victor Zverovich
3// All rights reserved.
4
5#ifndef SPDLOG_COMPILED_LIB
6# error Please define SPDLOG_COMPILED_LIB to compile this file.
7#endif
8
9#if !defined(SPDLOG_FMT_EXTERNAL) && !defined(SPDLOG_USE_STD_FORMAT)
10# include <spdlog/fmt/bundled/format-inl.h>
11
12FMT_BEGIN_NAMESPACE
13namespace detail {
14
15// DEPRECATED!
16template<typename T = void>
17struct basic_data
18{
19 FMT_API static constexpr const char digits[100][2] = {{'0', '0'}, {'0', '1'}, {'0', '2'}, {'0', '3'}, {'0', '4'}, {'0', '5'},
20 {'0', '6'}, {'0', '7'}, {'0', '8'}, {'0', '9'}, {'1', '0'}, {'1', '1'}, {'1', '2'}, {'1', '3'}, {'1', '4'}, {'1', '5'}, {'1', '6'},
21 {'1', '7'}, {'1', '8'}, {'1', '9'}, {'2', '0'}, {'2', '1'}, {'2', '2'}, {'2', '3'}, {'2', '4'}, {'2', '5'}, {'2', '6'}, {'2', '7'},
22 {'2', '8'}, {'2', '9'}, {'3', '0'}, {'3', '1'}, {'3', '2'}, {'3', '3'}, {'3', '4'}, {'3', '5'}, {'3', '6'}, {'3', '7'}, {'3', '8'},
23 {'3', '9'}, {'4', '0'}, {'4', '1'}, {'4', '2'}, {'4', '3'}, {'4', '4'}, {'4', '5'}, {'4', '6'}, {'4', '7'}, {'4', '8'}, {'4', '9'},
24 {'5', '0'}, {'5', '1'}, {'5', '2'}, {'5', '3'}, {'5', '4'}, {'5', '5'}, {'5', '6'}, {'5', '7'}, {'5', '8'}, {'5', '9'}, {'6', '0'},
25 {'6', '1'}, {'6', '2'}, {'6', '3'}, {'6', '4'}, {'6', '5'}, {'6', '6'}, {'6', '7'}, {'6', '8'}, {'6', '9'}, {'7', '0'}, {'7', '1'},
26 {'7', '2'}, {'7', '3'}, {'7', '4'}, {'7', '5'}, {'7', '6'}, {'7', '7'}, {'7', '8'}, {'7', '9'}, {'8', '0'}, {'8', '1'}, {'8', '2'},
27 {'8', '3'}, {'8', '4'}, {'8', '5'}, {'8', '6'}, {'8', '7'}, {'8', '8'}, {'8', '9'}, {'9', '0'}, {'9', '1'}, {'9', '2'}, {'9', '3'},
28 {'9', '4'}, {'9', '5'}, {'9', '6'}, {'9', '7'}, {'9', '8'}, {'9', '9'}};
29 FMT_API static constexpr const char hex_digits[] = "0123456789abcdef";
30 FMT_API static constexpr const char signs[4] = {0, '-', '+', ' '};
31 FMT_API static constexpr const char left_padding_shifts[5] = {31, 31, 0, 1, 0};
32 FMT_API static constexpr const char right_padding_shifts[5] = {0, 31, 0, 1, 0};
33 FMT_API static constexpr const unsigned prefixes[4] = {0, 0, 0x1000000u | '+', 0x1000000u | ' '};
34};
35
36# ifdef FMT_SHARED
37// Required for -flto, -fivisibility=hidden and -shared to work
38extern template struct basic_data<void>;
39# endif
40
41# if __cplusplus < 201703L
42// DEPRECATED! These are here only for ABI compatiblity.
43template<typename T>
44constexpr const char basic_data<T>::digits[][2];
45template<typename T>
46constexpr const char basic_data<T>::hex_digits[];
47template<typename T>
48constexpr const char basic_data<T>::signs[];
49template<typename T>
50constexpr const char basic_data<T>::left_padding_shifts[];
51template<typename T>
52constexpr const char basic_data<T>::right_padding_shifts[];
53template<typename T>
54constexpr const unsigned basic_data<T>::prefixes[];
55# endif
56
57template<typename T>
58int format_float(char *buf, std::size_t size, const char *format, int precision, T value)
59{
60# ifdef FMT_FUZZ
61 if (precision > 100000)
62 throw std::runtime_error("fuzz mode - avoid large allocation inside snprintf");
63# endif
64 // Suppress the warning about nonliteral format string.
65 int (*snprintf_ptr)(char *, size_t, const char *, ...) = FMT_SNPRINTF;
66 return precision < 0 ? snprintf_ptr(buf, size, format, value) : snprintf_ptr(buf, size, format, precision, value);
67}
68
69template FMT_API dragonbox::decimal_fp<float> dragonbox::to_decimal(float x) FMT_NOEXCEPT;
70template FMT_API dragonbox::decimal_fp<double> dragonbox::to_decimal(double x) FMT_NOEXCEPT;
71} // namespace detail
72
73// Workaround a bug in MSVC2013 that prevents instantiation of format_float.
74int (*instantiate_format_float)(double, int, detail::float_specs, detail::buffer<char> &) = detail::format_float;
75
76# ifndef FMT_STATIC_THOUSANDS_SEPARATOR
77template FMT_API detail::locale_ref::locale_ref(const std::locale &loc);
78template FMT_API std::locale detail::locale_ref::get<std::locale>() const;
79# endif
80
81// Explicit instantiations for char.
82
83template FMT_API auto detail::thousands_sep_impl(locale_ref) -> thousands_sep_result<char>;
84template FMT_API char detail::decimal_point_impl(locale_ref);
85
86template FMT_API void detail::buffer<char>::append(const char *, const char *);
87
88// DEPRECATED!
89// There is no correspondent extern template in format.h because of
90// incompatibility between clang and gcc (#2377).
91template FMT_API void detail::vformat_to(
92 detail::buffer<char> &, string_view, basic_format_args<FMT_BUFFER_CONTEXT(char)>, detail::locale_ref);
93
94template FMT_API int detail::snprintf_float(double, int, detail::float_specs, detail::buffer<char> &);
95template FMT_API int detail::snprintf_float(long double, int, detail::float_specs, detail::buffer<char> &);
96template FMT_API int detail::format_float(double, int, detail::float_specs, detail::buffer<char> &);
97template FMT_API int detail::format_float(long double, int, detail::float_specs, detail::buffer<char> &);
98
99// Explicit instantiations for wchar_t.
100
101template FMT_API auto detail::thousands_sep_impl(locale_ref) -> thousands_sep_result<wchar_t>;
102template FMT_API wchar_t detail::decimal_point_impl(locale_ref);
103
104template FMT_API void detail::buffer<wchar_t>::append(const wchar_t *, const wchar_t *);
105
106template struct detail::basic_data<void>;
107
108FMT_END_NAMESPACE
109
110#endif // !SPDLOG_FMT_EXTERNAL
111