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)
10 #    include <spdlog/fmt/bundled/format-inl.h>
11 
12 FMT_BEGIN_NAMESPACE
13 namespace detail {
14 
15 template<typename T>
format_float(char * buf,std::size_t size,const char * format,int precision,T value)16 int format_float(char *buf, std::size_t size, const char *format, int precision, T value)
17 {
18 #    ifdef FMT_FUZZ
19     if (precision > 100000)
20         throw std::runtime_error("fuzz mode - avoid large allocation inside snprintf");
21 #    endif
22     // Suppress the warning about nonliteral format string.
23     int (*snprintf_ptr)(char *, size_t, const char *, ...) = FMT_SNPRINTF;
24     return precision < 0 ? snprintf_ptr(buf, size, format, value) : snprintf_ptr(buf, size, format, precision, value);
25 }
26 
27 template FMT_API dragonbox::decimal_fp<float> dragonbox::to_decimal(float x) FMT_NOEXCEPT;
28 template FMT_API dragonbox::decimal_fp<double> dragonbox::to_decimal(double x) FMT_NOEXCEPT;
29 } // namespace detail
30 
31 // Workaround a bug in MSVC2013 that prevents instantiation of format_float.
32 int (*instantiate_format_float)(double, int, detail::float_specs, detail::buffer<char> &) = detail::format_float;
33 
34 #    ifndef FMT_STATIC_THOUSANDS_SEPARATOR
35 template FMT_API detail::locale_ref::locale_ref(const std::locale &loc);
36 template FMT_API std::locale detail::locale_ref::get<std::locale>() const;
37 #    endif
38 
39 // Explicit instantiations for char.
40 
41 template FMT_API auto detail::thousands_sep_impl(locale_ref) -> thousands_sep_result<char>;
42 template FMT_API char detail::decimal_point_impl(locale_ref);
43 
44 template FMT_API void detail::buffer<char>::append(const char *, const char *);
45 
46 // DEPRECATED!
47 // There is no correspondent extern template in format.h because of
48 // incompatibility between clang and gcc (#2377).
49 template FMT_API void detail::vformat_to(
50     detail::buffer<char> &, string_view, basic_format_args<FMT_BUFFER_CONTEXT(char)>, detail::locale_ref);
51 
52 template FMT_API int detail::snprintf_float(double, int, detail::float_specs, detail::buffer<char> &);
53 template FMT_API int detail::snprintf_float(long double, int, detail::float_specs, detail::buffer<char> &);
54 template FMT_API int detail::format_float(double, int, detail::float_specs, detail::buffer<char> &);
55 template FMT_API int detail::format_float(long double, int, detail::float_specs, detail::buffer<char> &);
56 
57 // Explicit instantiations for wchar_t.
58 
59 template FMT_API auto detail::thousands_sep_impl(locale_ref) -> thousands_sep_result<wchar_t>;
60 template FMT_API wchar_t detail::decimal_point_impl(locale_ref);
61 
62 template FMT_API void detail::buffer<wchar_t>::append(const wchar_t *, const wchar_t *);
63 
64 template struct detail::basic_data<void>;
65 
66 FMT_END_NAMESPACE
67 
68 #endif // !SPDLOG_FMT_EXTERNAL
69