diff --git a/ostd/io.hh b/ostd/io.hh index b4ccf33..d6e152a 100644 --- a/ostd/io.hh +++ b/ostd/io.hh @@ -213,7 +213,7 @@ namespace detail { template inline void write(T const &v) { - format_spec{'s'}.format_value(detail::stdout_range{}, v); + format_spec{'s', out.getloc()}.format_value(detail::stdout_range{}, v); } template @@ -241,7 +241,8 @@ inline void writeln(T const &v, A const &...args) { template inline void writef(string_range fmt, A const &...args) { - format(detail::stdout_range{}, fmt, args...); + format_spec sp{fmt, out.getloc()}; + sp.format(detail::stdout_range{}, args...); } template diff --git a/ostd/stream.hh b/ostd/stream.hh index 21fe6f4..6c9ecf1 100644 --- a/ostd/stream.hh +++ b/ostd/stream.hh @@ -8,6 +8,7 @@ #include #include +#include #include "ostd/platform.hh" #include "ostd/types.hh" @@ -132,6 +133,19 @@ struct stream { get(r); return r; } + + std::locale imbue(std::locale const &loc) { + std::locale ret{p_loc}; + p_loc = loc; + return ret; + } + + std::locale getloc() const { + return p_loc; + } + +private: + std::locale p_loc; }; template @@ -204,12 +218,13 @@ namespace detail { template inline void stream::write(T const &v) { - format_spec{'s'}.format_value(detail::fmt_stream_range{this}, v); + format_spec{'s', p_loc}.format_value(detail::fmt_stream_range{this}, v); } template inline void stream::writef(string_range fmt, A const &...args) { - format(detail::fmt_stream_range{this}, fmt, args...); + format_spec sp{fmt, p_loc}; + sp.format(detail::fmt_stream_range{this}, args...); } }