commit bc7c511cb7b937089fd52fa90778f8c76175b3a1
parent e58b51d241a8c77238a56cb1627cf1ea78d65706
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sun, 19 Nov 2017 17:06:35 -0800
use consistent thousands separator and number grouping across all locales
The French locale appears (untested) to use "\a0" instead of "\xc2\a0" as separator, which would get converted to � by MultiByteToWideChar.
Diffstat:
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/receipt.cpp b/src/receipt.cpp
@@ -91,7 +91,7 @@ void ReceiptPage::setTitle(const char *title)
ostringstream stream;
// enable number formatting (ie. "1,234" instead of "1234")
- stream.imbue(locale(""));
+ String::imbueStream(stream);
stream << title << " (" << m_size << ')';
m_title = stream.str();
diff --git a/src/string.cpp b/src/string.cpp
@@ -64,3 +64,15 @@ string String::indent(const string &text)
return output;
}
+
+void String::imbueStream(ostream &stream)
+{
+ class NumPunct : public std::numpunct<char>
+ {
+ protected:
+ char do_thousands_sep() const override { return ','; }
+ std::string do_grouping() const override { return "\3"; }
+ };
+
+ stream.imbue(locale(locale::classic(), new NumPunct));
+}
diff --git a/src/string.hpp b/src/string.hpp
@@ -27,6 +27,8 @@ namespace String {
std::string format(const char *fmt, ...);
std::string indent(const std::string &);
+
+ void imbueStream(std::ostream &);
}
#endif