Skip to content

Commit

Permalink
Use overridden locale in ostream
Browse files Browse the repository at this point in the history
  • Loading branch information
dlaugt committed Nov 13, 2019
1 parent 1f91815 commit b4b5bae
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions include/fmt/ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ void write(std::basic_ostream<Char>& os, buffer<Char>& buf) {
}

template <typename Char, typename T>
void format_value(buffer<Char>& buf, const T& value) {
void format_value(buffer<Char>& buf, const T& value, internal::locale_ref loc) {
formatbuf<Char> format_buf(buf);
std::basic_ostream<Char> output(&format_buf);
output.imbue(loc.get<std::locale>());
output.exceptions(std::ios_base::failbit | std::ios_base::badbit);
output << value;
buf.resize(buf.size());
Expand All @@ -104,7 +105,7 @@ struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>
template <typename Context>
auto format(const T& value, Context& ctx) -> decltype(ctx.out()) {
basic_memory_buffer<Char> buffer;
format_value(buffer, value);
format_value(buffer, value, ctx.locale());
basic_string_view<Char> str(buffer.data(), buffer.size());
return formatter<basic_string_view<Char>, Char>::format(str, ctx);
}
Expand Down

0 comments on commit b4b5bae

Please sign in to comment.