Skip to content

Commit

Permalink
Workaround for missing lconv support in android (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Panteleev committed May 19, 2016
1 parent 5b10608 commit 0b67860
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,17 @@ class ThousandsSep {
}
};

// Returns the thousands separator for the current locale.
template<typename Lconv, bool=(sizeof(std::lconv)>1)>
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.
Expand Down Expand Up @@ -2778,7 +2789,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;
Expand Down

0 comments on commit 0b67860

Please sign in to comment.