mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-08 02:28:15 +00:00
Workaround for missing lconv support in android (#327)
This commit is contained in:
parent
5b106083e7
commit
45a1509455
18
fmt/format.h
18
fmt/format.h
@ -910,6 +910,21 @@ class ThousandsSep {
|
||||
}
|
||||
};
|
||||
|
||||
// Returns the thousands separator for the current locale.
|
||||
// On android the lconv structure is stubbed using an empty structure
|
||||
// The test is for the size only, not for the presense of
|
||||
// thousands_sep in std::lconv, because if one would add thousands_sep
|
||||
// at some point, the size of structure would be at least sizeof(char*)
|
||||
template<typename Lconv, bool=(sizeof(Lconv) >= sizeof(char*))>
|
||||
struct Locale {
|
||||
static fmt::StringRef thousands_sep() { return ""; }
|
||||
};
|
||||
|
||||
template<typename Lconv>
|
||||
struct Locale<Lconv, true> {
|
||||
static fmt::StringRef thousands_sep() { return static_cast<Lconv*>(std::localeconv())->thousands_sep; }
|
||||
};
|
||||
|
||||
// Formats a decimal unsigned integer value writing into buffer.
|
||||
// thousands_sep is a functor that is called after writing each char to
|
||||
// add a thousands separator if necessary.
|
||||
@ -2778,7 +2793,8 @@ void BasicWriter<Char>::write_int(T value, Spec spec) {
|
||||
}
|
||||
case 'n': {
|
||||
unsigned num_digits = internal::count_digits(abs_value);
|
||||
fmt::StringRef sep = std::localeconv()->thousands_sep;
|
||||
fmt::StringRef sep =
|
||||
internal::Locale<lconv>::thousands_sep();
|
||||
unsigned size = static_cast<unsigned>(
|
||||
num_digits + sep.size() * (num_digits - 1) / 3);
|
||||
CharPtr p = prepare_int_buffer(size, spec, prefix, prefix_size) + 1;
|
||||
|
Loading…
Reference in New Issue
Block a user