diff --git a/ChangeLog b/ChangeLog index ebce1a77..20dcc3ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-05-24 Markus Gans + * Use nl_langinfo to determine the numeric thousands separator + for Fstring::setFormatedNumber as default parameter + 2016-05-22 Markus Gans * Fix for menus in modal dialogs diff --git a/src/fstring.cpp b/src/fstring.cpp index 8fb83490..fd3c57c3 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -7,7 +7,6 @@ // class FString //---------------------------------------------------------------------- - // constructors and destructor //---------------------------------------------------------------------- FString::FString() @@ -1402,6 +1401,9 @@ FString& FString::setFormatedNumber (long num, char separator) n = 0; s = &buf[29]; + if ( separator == 0 ) + separator = ' '; + if ( num < 0 ) { neg = true; @@ -1437,6 +1439,9 @@ FString& FString::setFormatedNumber (uLong num, char separator) s = &buf[29]; *s = L'\0'; + if ( separator == 0 ) + separator = ' '; + do { *--s = wchar_t(int(num%10) + '0'); diff --git a/src/fstring.h b/src/fstring.h index df7c56fe..5ad85e29 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -13,6 +13,7 @@ #include +#include #include #include @@ -162,12 +163,12 @@ class FString FString& setNumber (double, int = 11); FString& setNumber (lDouble, int = 11); - FString& setFormatedNumber (sInt16, char = '.'); - FString& setFormatedNumber (uInt16, char = '.'); - FString& setFormatedNumber (int, char = '.'); - FString& setFormatedNumber (uInt, char = '.'); - FString& setFormatedNumber (long, char = '.'); - FString& setFormatedNumber (uLong, char = '.'); + FString& setFormatedNumber (sInt16, char = nl_langinfo(THOUSEP)[0]); + FString& setFormatedNumber (uInt16, char = nl_langinfo(THOUSEP)[0]); + FString& setFormatedNumber (int, char = nl_langinfo(THOUSEP)[0]); + FString& setFormatedNumber (uInt, char = nl_langinfo(THOUSEP)[0]); + FString& setFormatedNumber (long, char = nl_langinfo(THOUSEP)[0]); + FString& setFormatedNumber (uLong, char = nl_langinfo(THOUSEP)[0]); friend std::ostream& operator << (std::ostream& outstr, const FString& s); friend std::istream& operator >> (std::istream& instr, FString& s); diff --git a/src/fterm.cpp b/src/fterm.cpp index 9f4e4739..4e9257ca 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -1501,6 +1501,8 @@ void FTerm::init_termcaps() //---------------------------------------------------------------------- void FTerm::init_encoding() { + // detect encoding and set the Fputchar function pointer + if ( isatty(stdout_no) && ! strcmp(nl_langinfo(CODESET), "UTF-8") ) { utf8_console = true; @@ -1726,8 +1728,9 @@ void FTerm::init() init_termcaps(); init_alt_charset(); - // set the Fputchar function pointer - locale_name = setlocale(LC_ALL, ""); // init current locale + // init current locale + locale_name = setlocale(LC_ALL, ""); + locale_name = setlocale(LC_NUMERIC, ""); // get XTERM_LOCALE locale_xterm = getenv("XTERM_LOCALE"); diff --git a/test/string-operations.cpp b/test/string-operations.cpp index bc4cc606..2264e120 100644 --- a/test/string-operations.cpp +++ b/test/string-operations.cpp @@ -174,6 +174,7 @@ int main (int, char**) std::cout << " setNumber: " << num3 << " (long double)" << std::endl; + setlocale (LC_NUMERIC, ""); FString fnum1, fnum2; #if defined(__LP64__) || defined(_LP64) // 64-bit architecture