Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for missing lconv support in android #328

Merged
merged 1 commit into from
May 19, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down