blob: a64a1f3893a59297899f13d8382f9c79838c1ba7 [file] [log] [blame]
Jan Eilersc9bc80e2020-10-29 15:25:48 +00001// Formatting library for C++
2//
3// Copyright (c) 2012 - 2016, Victor Zverovich
4// All rights reserved.
5//
6// For the license information refer to format.h.
7
8#include "fmt/format-inl.h"
9
10FMT_BEGIN_NAMESPACE
11namespace detail {
12
13template <typename T>
14int format_float(char* buf, std::size_t size, const char* format, int precision,
15 T value) {
16#ifdef FMT_FUZZ
17 if (precision > 100000)
18 throw std::runtime_error(
19 "fuzz mode - avoid large allocation inside snprintf");
20#endif
21 // Suppress the warning about nonliteral format string.
22 int (*snprintf_ptr)(char*, size_t, const char*, ...) = FMT_SNPRINTF;
23 return precision < 0 ? snprintf_ptr(buf, size, format, value)
24 : snprintf_ptr(buf, size, format, precision, value);
25}
26} // namespace detail
27
28template struct FMT_INSTANTIATION_DEF_API detail::basic_data<void>;
29
30// Workaround a bug in MSVC2013 that prevents instantiation of format_float.
31int (*instantiate_format_float)(double, int, detail::float_specs,
32 detail::buffer<char>&) = detail::format_float;
33
34#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
35template FMT_API detail::locale_ref::locale_ref(const std::locale& loc);
36template FMT_API std::locale detail::locale_ref::get<std::locale>() const;
37#endif
38
39// Explicit instantiations for char.
40
41template FMT_API std::string detail::grouping_impl<char>(locale_ref);
42template FMT_API char detail::thousands_sep_impl(locale_ref);
43template FMT_API char detail::decimal_point_impl(locale_ref);
44
45template FMT_API void detail::buffer<char>::append(const char*, const char*);
46
47template FMT_API FMT_BUFFER_CONTEXT(char)::iterator detail::vformat_to(
48 detail::buffer<char>&, string_view,
49 basic_format_args<FMT_BUFFER_CONTEXT(char)>);
50
51template FMT_API int detail::snprintf_float(double, int, detail::float_specs,
52 detail::buffer<char>&);
53template FMT_API int detail::snprintf_float(long double, int,
54 detail::float_specs,
55 detail::buffer<char>&);
56template FMT_API int detail::format_float(double, int, detail::float_specs,
57 detail::buffer<char>&);
58template FMT_API int detail::format_float(long double, int, detail::float_specs,
59 detail::buffer<char>&);
60
61// Explicit instantiations for wchar_t.
62
63template FMT_API std::string detail::grouping_impl<wchar_t>(locale_ref);
64template FMT_API wchar_t detail::thousands_sep_impl(locale_ref);
65template FMT_API wchar_t detail::decimal_point_impl(locale_ref);
66
67template FMT_API void detail::buffer<wchar_t>::append(const wchar_t*,
68 const wchar_t*);
69FMT_END_NAMESPACE