Use nl_langinfo to determine the numeric thousands separator

This commit is contained in:
Markus Gans 2016-05-24 22:30:01 +02:00
parent 6ff2fb0b32
commit 0146ae9d99
5 changed files with 23 additions and 9 deletions

View File

@ -1,3 +1,7 @@
2016-05-24 Markus Gans <guru.mail@muenster.de>
* Use nl_langinfo to determine the numeric thousands separator
for Fstring::setFormatedNumber as default parameter
2016-05-22 Markus Gans <guru.mail@muenster.de>
* Fix for menus in modal dialogs

View File

@ -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');

View File

@ -13,6 +13,7 @@
#include <sys/types.h>
#include <langinfo.h>
#include <stdint.h>
#include <cassert>
@ -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);

View File

@ -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");

View File

@ -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