blob: 10af1f543e3a2668dc70e2cea48d6db103071964 [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.
Jim Flynn0dcef532022-06-14 10:58:23 +01005// SPDX-License-Identifier: MIT
Jan Eilersc9bc80e2020-10-29 15:25:48 +00006//
7// For the license information refer to format.h.
8
9#include "fmt/format-inl.h"
10
11FMT_BEGIN_NAMESPACE
12namespace detail {
13
14template <typename T>
15int format_float(char* buf, std::size_t size, const char* format, int precision,
16 T value) {
17#ifdef FMT_FUZZ
18 if (precision > 100000)
19 throw std::runtime_error(
20 "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)
25 : snprintf_ptr(buf, size, format, precision, value);
26}
27} // namespace detail
28
29template struct FMT_INSTANTIATION_DEF_API detail::basic_data<void>;
30
31// Workaround a bug in MSVC2013 that prevents instantiation of format_float.
32int (*instantiate_format_float)(double, int, detail::float_specs,
33 detail::buffer<char>&) = detail::format_float;
34
35#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
36template FMT_API detail::locale_ref::locale_ref(const std::locale& loc);
37template FMT_API std::locale detail::locale_ref::get<std::locale>() const;
38#endif
39
40// Explicit instantiations for char.
41
42template FMT_API std::string detail::grouping_impl<char>(locale_ref);
43template FMT_API char detail::thousands_sep_impl(locale_ref);
44template FMT_API char detail::decimal_point_impl(locale_ref);
45
46template FMT_API void detail::buffer<char>::append(const char*, const char*);
47
48template FMT_API FMT_BUFFER_CONTEXT(char)::iterator detail::vformat_to(
49 detail::buffer<char>&, string_view,
50 basic_format_args<FMT_BUFFER_CONTEXT(char)>);
51
52template FMT_API int detail::snprintf_float(double, int, detail::float_specs,
53 detail::buffer<char>&);
54template FMT_API int detail::snprintf_float(long double, int,
55 detail::float_specs,
56 detail::buffer<char>&);
57template FMT_API int detail::format_float(double, int, detail::float_specs,
58 detail::buffer<char>&);
59template FMT_API int detail::format_float(long double, int, detail::float_specs,
60 detail::buffer<char>&);
61
62// Explicit instantiations for wchar_t.
63
64template FMT_API std::string detail::grouping_impl<wchar_t>(locale_ref);
65template FMT_API wchar_t detail::thousands_sep_impl(locale_ref);
66template FMT_API wchar_t detail::decimal_point_impl(locale_ref);
67
68template FMT_API void detail::buffer<wchar_t>::append(const wchar_t*,
69 const wchar_t*);
70FMT_END_NAMESPACE