1
0
mirror of https://github.com/gabime/spdlog.git synced 2025-03-06 22:25:47 +08:00
spdlog/src/fmt.cpp

63 lines
2.6 KiB
C++
Raw Normal View History

// Slightly modified version of fmt lib's format.cc source file.
// Copyright (c) 2012 - 2016, Victor Zverovich
// All rights reserved.
2020-04-15 05:51:03 +08:00
#ifndef SPDLOG_COMPILED_LIB
#error Please define SPDLOG_COMPILED_LIB to compile this file.
#endif
#if !defined(SPDLOG_FMT_EXTERNAL)
2020-03-06 21:51:07 +08:00
#include <spdlog/fmt/bundled/format-inl.h>
FMT_BEGIN_NAMESPACE
2020-08-26 05:02:09 +08:00
namespace detail {
2019-12-23 04:54:31 +08:00
2020-04-19 16:33:36 +08:00
template<typename T>
int format_float(char *buf, std::size_t size, const char *format, int precision, T value)
{
2020-08-26 05:02:09 +08:00
#ifdef FMT_FUZZ
2020-02-10 23:13:41 +08:00
if (precision > 100000)
2020-04-19 16:33:36 +08:00
throw std::runtime_error("fuzz mode - avoid large allocation inside snprintf");
2019-12-23 04:54:31 +08:00
#endif
2020-02-10 23:13:41 +08:00
// Suppress the warning about nonliteral format string.
2020-04-19 16:33:36 +08:00
int (*snprintf_ptr)(char *, size_t, const char *, ...) = FMT_SNPRINTF;
return precision < 0 ? snprintf_ptr(buf, size, format, value) : snprintf_ptr(buf, size, format, precision, value);
2020-02-10 23:13:41 +08:00
}
2020-08-26 05:02:09 +08:00
} // namespace detail
2020-02-10 23:13:41 +08:00
2020-08-26 05:02:09 +08:00
template struct FMT_INSTANTIATION_DEF_API detail::basic_data<void>;
2019-12-05 05:39:17 +08:00
// Workaround a bug in MSVC2013 that prevents instantiation of format_float.
2020-08-26 05:02:09 +08:00
int (*instantiate_format_float)(double, int, detail::float_specs, detail::buffer<char> &) = detail::format_float;
2019-12-05 05:39:17 +08:00
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
2020-08-26 05:02:09 +08:00
template FMT_API detail::locale_ref::locale_ref(const std::locale &loc);
template FMT_API std::locale detail::locale_ref::get<std::locale>() const;
2019-12-05 05:39:17 +08:00
#endif
// Explicit instantiations for char.
2019-12-05 05:39:17 +08:00
2020-08-26 05:02:09 +08:00
template FMT_API std::string detail::grouping_impl<char>(locale_ref);
template FMT_API char detail::thousands_sep_impl(locale_ref);
template FMT_API char detail::decimal_point_impl(locale_ref);
2019-12-05 05:39:17 +08:00
2020-08-26 05:02:09 +08:00
template FMT_API void detail::buffer<char>::append(const char *, const char *);
2019-12-05 05:39:17 +08:00
2020-08-26 05:02:09 +08:00
template FMT_API FMT_BUFFER_CONTEXT(char)::iterator detail::vformat_to(
detail::buffer<char> &, string_view, basic_format_args<FMT_BUFFER_CONTEXT(char)>);
2019-12-05 05:39:17 +08:00
2020-08-26 05:02:09 +08:00
template FMT_API int detail::snprintf_float(double, int, detail::float_specs, detail::buffer<char> &);
template FMT_API int detail::snprintf_float(long double, int, detail::float_specs, detail::buffer<char> &);
template FMT_API int detail::format_float(double, int, detail::float_specs, detail::buffer<char> &);
template FMT_API int detail::format_float(long double, int, detail::float_specs, detail::buffer<char> &);
// Explicit instantiations for wchar_t.
2019-12-05 05:39:17 +08:00
2020-08-26 05:02:09 +08:00
template FMT_API std::string detail::grouping_impl<wchar_t>(locale_ref);
template FMT_API wchar_t detail::thousands_sep_impl(locale_ref);
template FMT_API wchar_t detail::decimal_point_impl(locale_ref);
2019-12-05 05:39:17 +08:00
2020-08-26 05:02:09 +08:00
template FMT_API void detail::buffer<wchar_t>::append(const wchar_t *, const wchar_t *);
FMT_END_NAMESPACE
2020-04-15 05:51:03 +08:00
#endif // !SPDLOG_FMT_EXTERNAL