basic locale awareness in streams (including writef/ln integration)

master
Daniel Kolesa 2017-02-26 02:06:02 +01:00
parent db991ca03d
commit 8be2e1fa56
2 changed files with 20 additions and 4 deletions

View File

@ -213,7 +213,7 @@ namespace detail {
template<typename T>
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<typename T, typename ...A>
@ -241,7 +241,8 @@ inline void writeln(T const &v, A const &...args) {
template<typename ...A>
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<typename ...A>

View File

@ -8,6 +8,7 @@
#include <sys/types.h>
#include <type_traits>
#include <locale>
#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<typename T>
@ -204,12 +218,13 @@ namespace detail {
template<typename T>
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<typename ...A>
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...);
}
}