~ubuntu-branches/ubuntu/trusty/scribus-ng/trusty

« back to all changes in this revision

Viewing changes to scribus/scclocale.cpp

  • Committer: Package Import Robot
  • Author(s): Oleksandr Moskalenko
  • Date: 2012-02-15 15:57:12 UTC
  • mfrom: (4.2.10 sid)
  • Revision ID: package-import@ubuntu.com-20120215155712-biimoc8o875jht80
Tags: 1.4.0.dfsg+r17300-1
* Prepare a dummy transitional package to converge on the 1.4.0 release.
* debian/NEWS: update the news.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// C++ Implementation: sclocale
3
 
//
4
 
// Description: 
5
 
//
6
 
//
7
 
// Author: Pierre Marchand <pierremarc@oep-h.com>, (C) 2009
8
 
//
9
 
// Copyright: See COPYING file that comes with this distribution
10
 
//
11
 
//
12
 
 
13
 
#include "scclocale.h"
14
 
#include <QDebug>
15
 
 
16
 
ScCLocale * ScCLocale::m_instance = 0;
17
 
ScCLocale::ScCLocale()
18
 
        :qLocale(QLocale::C)
19
 
{
20
 
        qLocale.setNumberOptions(QLocale::OmitGroupSeparator);
21
 
 
22
 
#if defined(Q_WS_WIN)
23
 
        cLocale = _create_locale(LC_ALL, "C");
24
 
#else
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);
27
 
  #endif
28
 
#endif
29
 
}
30
 
 
31
 
ScCLocale::~ScCLocale()
32
 
{
33
 
#if defined(Q_WS_WIN)
34
 
        _free_locale(cLocale);
35
 
#else
36
 
  #if not defined(Q_OS_SOLARIS) and not defined(Q_OS_OPENBSD) and not defined (Q_OS_FREEBSD)
37
 
        freelocale(cLocale);
38
 
  #endif
39
 
#endif
40
 
}
41
 
 
42
 
ScCLocale * ScCLocale::that()
43
 
{
44
 
        if(!m_instance)
45
 
        {
46
 
                m_instance = new ScCLocale();
47
 
                Q_ASSERT(m_instance);
48
 
        }
49
 
        return m_instance;
50
 
}
51
 
 
52
 
double ScCLocale::toDoubleC(const QString & str, bool * ok) 
53
 
{
54
 
        double ret( that()->qLocale.toDouble(str, ok) );
55
 
        return ret;
56
 
}
57
 
 
58
 
double ScCLocale::toDoubleC(const QString& str, double defValue)
59
 
{
60
 
        double ret = defValue;
61
 
        if (!str.isEmpty())
62
 
        {
63
 
                bool ok  = false;
64
 
                double d = ScCLocale::toDoubleC(str, &ok);
65
 
                if (ok)
66
 
                        ret = d;
67
 
        }
68
 
        return ret;
69
 
}
70
 
 
71
 
float ScCLocale::toFloatC(const QString & str, bool * ok) 
72
 
{
73
 
        double ret( that()->qLocale.toFloat(str, ok) );
74
 
        return ret;
75
 
}
76
 
 
77
 
float ScCLocale::toFloatC(const QString& str, float defValue)
78
 
{
79
 
        double ret = defValue;
80
 
        if (!str.isEmpty())
81
 
        {
82
 
                bool ok  = false;
83
 
                double d = ScCLocale::toFloatC(str, &ok);
84
 
                if (ok)
85
 
                        ret = d;
86
 
        }
87
 
        return ret;
88
 
}
89
 
 
90
 
QString ScCLocale::toQStringC(double d, int prec)
91
 
{
92
 
        return that()->qLocale.toString(d, 'f', prec);
93
 
}
94
 
 
95
 
double ScCLocale::strtod ( const char * str, char ** endptr )
96
 
{
97
 
        if(NULL == that()->cLocale)
98
 
        {
99
 
                // a sade workaround
100
 
                double result(0.0);
101
 
                setlocale(LC_NUMERIC, "C");
102
 
                result = strtod(str, endptr);
103
 
                setlocale(LC_NUMERIC, "");
104
 
                return result;
105
 
        }
106
 
        else
107
 
        {
108
 
#if defined(Q_WS_WIN)
109
 
                return _strtod_l(str, endptr, that()->cLocale);
110
 
#else
111
 
  #if defined(Q_OS_SOLARIS) or defined (Q_OS_OPENBSD) or defined (Q_OS_FREEBSD)
112
 
                char *oldlocale=setlocale(LC_NUMERIC, NULL);
113
 
                double result(0.0);
114
 
                setlocale(LC_NUMERIC, "C");
115
 
                result = strtod(str, endptr);
116
 
                setlocale(LC_NUMERIC, oldlocale);
117
 
                return result;
118
 
  #else
119
 
                return strtod_l(str, endptr, that()->cLocale);
120
 
  #endif
121
 
#endif
122
 
        }
123
 
}
124