spdlog/src/fmt.cpp

68 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>
2020-12-11 22:32:39 +08:00
2021-06-24 18:22:02 +08:00
FMT_BEGIN_NAMESPACE
2020-08-26 05:02:09 +08:00
namespace detail {
2019-12-23 04:54:31 +08:00
2021-06-24 18:22:02 +08:00
template<typename T>
int format_float(char *buf, std::size_t size, const char *format, int precision, T value)
{
# ifdef FMT_FUZZ
if (precision > 100000)
throw std::runtime_error("fuzz mode - avoid large allocation inside snprintf");
# endif
// Suppress the warning about nonliteral format string.
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-12-11 22:32:39 +08:00
}
2021-06-24 18:22:02 +08:00
template FMT_API dragonbox::decimal_fp<float> dragonbox::to_decimal(float x) FMT_NOEXCEPT;
template FMT_API dragonbox::decimal_fp<double> dragonbox::to_decimal(double x) FMT_NOEXCEPT;
} // namespace detail
2019-12-05 05:39:17 +08:00
// Workaround a bug in MSVC2013 that prevents instantiation of format_float.
2021-06-24 18:22:02 +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
2021-06-24 18:22:02 +08:00
# ifndef FMT_STATIC_THOUSANDS_SEPARATOR
template FMT_API detail::locale_ref::locale_ref(const std::locale &loc);
2020-08-26 05:02:09 +08:00
template FMT_API std::locale detail::locale_ref::get<std::locale>() const;
2021-06-24 18:22:02 +08:00
# endif
// Explicit instantiations for char.
2019-12-05 05:39:17 +08:00
2021-06-24 18:22:02 +08:00
template FMT_API auto detail::thousands_sep_impl(locale_ref) -> thousands_sep_result<char>;
2020-08-26 05:02:09 +08:00
template FMT_API char detail::decimal_point_impl(locale_ref);
2019-12-05 05:39:17 +08:00
2021-06-24 18:22:02 +08:00
template FMT_API void detail::buffer<char>::append(const char *, const char *);
2019-12-05 05:39:17 +08:00
2020-12-11 22:32:39 +08:00
template FMT_API void detail::vformat_to(
2021-06-24 18:22:02 +08:00
detail::buffer<char> &, string_view, basic_format_args<FMT_BUFFER_CONTEXT(char)>, detail::locale_ref);
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
2021-06-24 18:22:02 +08:00
template FMT_API auto detail::thousands_sep_impl(locale_ref) -> thousands_sep_result<wchar_t>;
2020-08-26 05:02:09 +08:00
template FMT_API wchar_t detail::decimal_point_impl(locale_ref);
2019-12-05 05:39:17 +08:00
2021-06-24 18:22:02 +08:00
template FMT_API void detail::buffer<wchar_t>::append(const wchar_t *, const wchar_t *);
template struct detail::basic_data<void>;
FMT_END_NAMESPACE
2021-06-24 18:22:02 +08:00
2020-12-11 22:32:39 +08:00
#endif // !SPDLOG_FMT_EXTERNAL