mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 02:37:36 +02:00
Simplify locale handling
This commit is contained in:
@ -796,11 +796,6 @@ using is_double_double = bool_constant<std::numeric_limits<T>::digits == 106>;
|
||||
# define FMT_USE_FULL_CACHE_DRAGONBOX 0
|
||||
#endif
|
||||
|
||||
template <typename T, typename Enable = void>
|
||||
struct is_locale : std::false_type {};
|
||||
template <typename T>
|
||||
struct is_locale<T, void_t<decltype(T::classic())>> : std::true_type {};
|
||||
|
||||
// An allocator that uses malloc/free to allow removing dependency on the C++
|
||||
// standard libary runtime.
|
||||
template <typename T> struct allocator {
|
||||
@ -4213,47 +4208,41 @@ FMT_API void format_system_error(detail::buffer<char>& out, int error_code,
|
||||
// Can be used to report errors from destructors.
|
||||
FMT_API void report_system_error(int error_code, const char* message) noexcept;
|
||||
|
||||
template <typename Locale, FMT_ENABLE_IF(detail::is_locale<Locale>::value)>
|
||||
auto vformat(const Locale& loc, string_view fmt, format_args args)
|
||||
inline auto vformat(detail::locale_ref loc, string_view fmt, format_args args)
|
||||
-> std::string {
|
||||
auto buf = memory_buffer();
|
||||
detail::vformat_to(buf, fmt, args, detail::locale_ref(loc));
|
||||
detail::vformat_to(buf, fmt, args, loc);
|
||||
return {buf.data(), buf.size()};
|
||||
}
|
||||
|
||||
template <typename Locale, typename... T,
|
||||
FMT_ENABLE_IF(detail::is_locale<Locale>::value)>
|
||||
FMT_INLINE auto format(const Locale& loc, format_string<T...> fmt, T&&... args)
|
||||
-> std::string {
|
||||
return fmt::vformat(loc, fmt.str, vargs<T...>{{args...}});
|
||||
template <typename... T>
|
||||
FMT_INLINE auto format(detail::locale_ref loc, format_string<T...> fmt,
|
||||
T&&... args) -> std::string {
|
||||
return vformat(loc, fmt.str, vargs<T...>{{args...}});
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename Locale,
|
||||
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value&&
|
||||
detail::is_locale<Locale>::value)>
|
||||
auto vformat_to(OutputIt out, const Locale& loc, string_view fmt,
|
||||
template <typename OutputIt,
|
||||
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
|
||||
auto vformat_to(OutputIt out, detail::locale_ref loc, string_view fmt,
|
||||
format_args args) -> OutputIt {
|
||||
auto&& buf = detail::get_buffer<char>(out);
|
||||
detail::vformat_to(buf, fmt, args, detail::locale_ref(loc));
|
||||
detail::vformat_to(buf, fmt, args, loc);
|
||||
return detail::get_iterator(buf, out);
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename Locale, typename... T,
|
||||
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value&&
|
||||
detail::is_locale<Locale>::value)>
|
||||
FMT_INLINE auto format_to(OutputIt out, const Locale& loc,
|
||||
template <typename OutputIt, typename... T,
|
||||
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
|
||||
FMT_INLINE auto format_to(OutputIt out, detail::locale_ref loc,
|
||||
format_string<T...> fmt, T&&... args) -> OutputIt {
|
||||
return fmt::vformat_to(out, loc, fmt.str, vargs<T...>{{args...}});
|
||||
}
|
||||
|
||||
template <typename Locale, typename... T,
|
||||
FMT_ENABLE_IF(detail::is_locale<Locale>::value)>
|
||||
FMT_NODISCARD FMT_INLINE auto formatted_size(const Locale& loc,
|
||||
template <typename... T>
|
||||
FMT_NODISCARD FMT_INLINE auto formatted_size(detail::locale_ref loc,
|
||||
format_string<T...> fmt,
|
||||
T&&... args) -> size_t {
|
||||
auto buf = detail::counting_buffer<>();
|
||||
detail::vformat_to(buf, fmt.str, vargs<T...>{{args...}},
|
||||
detail::locale_ref(loc));
|
||||
detail::vformat_to(buf, fmt.str, vargs<T...>{{args...}}, loc);
|
||||
return buf.count();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user