2
// C++ Implementation: sclocale
7
// Author: Pierre Marchand <pierremarc@oep-h.com>, (C) 2009
9
// Copyright: See COPYING file that comes with this distribution
13
#include "scclocale.h"
16
ScCLocale * ScCLocale::m_instance = 0;
17
ScCLocale::ScCLocale()
20
qLocale.setNumberOptions(QLocale::OmitGroupSeparator);
23
cLocale = _create_locale(LC_ALL, "C");
25
#if not defined(Q_OS_SOLARIS) and not defined(Q_OS_OPENBSD) and not defined (Q_OS_FREEBSD)
26
cLocale = newlocale(LC_ALL_MASK, "C", NULL);
31
ScCLocale::~ScCLocale()
34
_free_locale(cLocale);
36
#if not defined(Q_OS_SOLARIS) and not defined(Q_OS_OPENBSD) and not defined (Q_OS_FREEBSD)
42
ScCLocale * ScCLocale::that()
46
m_instance = new ScCLocale();
52
double ScCLocale::toDoubleC(const QString & str, bool * ok)
54
double ret( that()->qLocale.toDouble(str, ok) );
58
double ScCLocale::toDoubleC(const QString& str, double defValue)
60
double ret = defValue;
64
double d = ScCLocale::toDoubleC(str, &ok);
71
float ScCLocale::toFloatC(const QString & str, bool * ok)
73
double ret( that()->qLocale.toFloat(str, ok) );
77
float ScCLocale::toFloatC(const QString& str, float defValue)
79
double ret = defValue;
83
double d = ScCLocale::toFloatC(str, &ok);
90
QString ScCLocale::toQStringC(double d, int prec)
92
return that()->qLocale.toString(d, 'f', prec);
95
double ScCLocale::strtod ( const char * str, char ** endptr )
97
if(NULL == that()->cLocale)
101
setlocale(LC_NUMERIC, "C");
102
result = strtod(str, endptr);
103
setlocale(LC_NUMERIC, "");
108
#if defined(Q_WS_WIN)
109
return _strtod_l(str, endptr, that()->cLocale);
111
#if defined(Q_OS_SOLARIS) or defined (Q_OS_OPENBSD) or defined (Q_OS_FREEBSD)
112
char *oldlocale=setlocale(LC_NUMERIC, NULL);
114
setlocale(LC_NUMERIC, "C");
115
result = strtod(str, endptr);
116
setlocale(LC_NUMERIC, oldlocale);
119
return strtod_l(str, endptr, that()->cLocale);