mirror of
https://github.com/fmtlib/fmt.git
synced 2025-02-28 06:39:50 +00:00
Make locales work with any character type
This commit is contained in:
parent
bdda4d6030
commit
324eac1aa5
@ -214,13 +214,10 @@ class locale {
|
|||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
FMT_FUNC Char thousands_sep(locale_provider *lp) {
|
FMT_FUNC Char thousands_sep_impl(locale_provider *lp) {
|
||||||
std::locale loc = lp ? lp->locale().get() : std::locale();
|
std::locale loc = lp ? lp->locale().get() : std::locale();
|
||||||
return std::use_facet<std::numpunct<Char>>(loc).thousands_sep();
|
return std::use_facet<std::numpunct<Char>>(loc).thousands_sep();
|
||||||
}
|
}
|
||||||
template <> FMT_FUNC char8_t thousands_sep<char8_t>(locale_provider *) {
|
|
||||||
return static_cast<char8_t>(',');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
|
@ -1034,7 +1034,17 @@ class add_thousands_sep {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
FMT_API Char thousands_sep(locale_provider *lp);
|
FMT_API Char thousands_sep_impl(locale_provider *lp);
|
||||||
|
|
||||||
|
template <typename Char>
|
||||||
|
inline Char thousands_sep(locale_provider *lp) {
|
||||||
|
return Char(thousands_sep_impl<char>(lp));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline wchar_t thousands_sep(locale_provider *lp) {
|
||||||
|
return thousands_sep_impl<wchar_t>(lp);
|
||||||
|
}
|
||||||
|
|
||||||
// Formats a decimal unsigned integer value writing into buffer.
|
// Formats a decimal unsigned integer value writing into buffer.
|
||||||
// thousands_sep is a functor that is called after writing each char to
|
// thousands_sep is a functor that is called after writing each char to
|
||||||
@ -3416,7 +3426,7 @@ struct it_category<T, typename void_<typename T::iterator_category>::type> {
|
|||||||
typedef typename T::iterator_category type;
|
typedef typename T::iterator_category type;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Detect if *any* given type models the OutputIterator concept
|
// Detect if *any* given type models the OutputIterator concept.
|
||||||
template <typename It>
|
template <typename It>
|
||||||
class is_output_iterator {
|
class is_output_iterator {
|
||||||
// Check for mutability because all iterator categories derived from
|
// Check for mutability because all iterator categories derived from
|
||||||
@ -3434,10 +3444,9 @@ class is_output_iterator {
|
|||||||
|
|
||||||
typedef decltype(test<It>(typename it_category<It>::type{})) type;
|
typedef decltype(test<It>(typename it_category<It>::type{})) type;
|
||||||
typedef typename std::remove_reference<type>::type result;
|
typedef typename std::remove_reference<type>::type result;
|
||||||
public:
|
public:
|
||||||
static const bool value = !std::is_const<result>::value;
|
static const bool value = !std::is_const<result>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // internal
|
} // internal
|
||||||
|
|
||||||
template <typename OutputIt, typename Char = char>
|
template <typename OutputIt, typename Char = char>
|
||||||
|
@ -12,7 +12,7 @@ template struct internal::basic_data<void>;
|
|||||||
|
|
||||||
// Explicit instantiations for char.
|
// Explicit instantiations for char.
|
||||||
|
|
||||||
template FMT_API char internal::thousands_sep(locale_provider *lp);
|
template FMT_API char internal::thousands_sep_impl(locale_provider *lp);
|
||||||
|
|
||||||
template void internal::basic_buffer<char>::append(const char *, const char *);
|
template void internal::basic_buffer<char>::append(const char *, const char *);
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ template FMT_API void internal::sprintf_format(
|
|||||||
|
|
||||||
// Explicit instantiations for wchar_t.
|
// Explicit instantiations for wchar_t.
|
||||||
|
|
||||||
template FMT_API wchar_t internal::thousands_sep(locale_provider *);
|
template FMT_API wchar_t internal::thousands_sep_impl(locale_provider *);
|
||||||
|
|
||||||
template void internal::basic_buffer<wchar_t>::append(
|
template void internal::basic_buffer<wchar_t>::append(
|
||||||
const wchar_t *, const wchar_t *);
|
const wchar_t *, const wchar_t *);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user