author | eckhart.koppen@nokia.com |
Wed, 31 Mar 2010 11:06:36 +0300 | |
changeset 7 | f7bc934e204c |
parent 0 | 1918ee327afb |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtCore module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#ifndef QLOCALE_P_H |
|
43 |
#define QLOCALE_P_H |
|
44 |
||
45 |
// |
|
46 |
// W A R N I N G |
|
47 |
// ------------- |
|
48 |
// |
|
49 |
// This file is not part of the Qt API. It exists for the convenience |
|
50 |
// of internal files. This header file may change from version to version |
|
51 |
// without notice, or even be removed. |
|
52 |
// |
|
53 |
// We mean it. |
|
54 |
// |
|
55 |
||
56 |
#include "QtCore/qstring.h" |
|
57 |
#include "QtCore/qvarlengtharray.h" |
|
58 |
||
59 |
#include "qlocale.h" |
|
60 |
||
61 |
QT_BEGIN_NAMESPACE |
|
62 |
||
63 |
struct Q_CORE_EXPORT QLocalePrivate |
|
64 |
{ |
|
65 |
public: |
|
66 |
QChar decimal() const { return QChar(m_decimal); } |
|
67 |
QChar group() const { return QChar(m_group); } |
|
68 |
QChar list() const { return QChar(m_list); } |
|
69 |
QChar percent() const { return QChar(m_percent); } |
|
70 |
QChar zero() const { return QChar(m_zero); } |
|
71 |
QChar plus() const { return QChar(m_plus); } |
|
72 |
QChar minus() const { return QChar(m_minus); } |
|
73 |
QChar exponential() const { return QChar(m_exponential); } |
|
74 |
||
75 |
quint32 languageId() const { return m_language_id; } |
|
76 |
quint32 countryId() const { return m_country_id; } |
|
77 |
||
78 |
QLocale::MeasurementSystem measurementSystem() const; |
|
79 |
||
80 |
enum DoubleForm { |
|
81 |
DFExponent = 0, |
|
82 |
DFDecimal, |
|
83 |
DFSignificantDigits, |
|
84 |
_DFMax = DFSignificantDigits |
|
85 |
}; |
|
86 |
||
87 |
enum Flags { |
|
88 |
NoFlags = 0, |
|
89 |
Alternate = 0x01, |
|
90 |
ZeroPadded = 0x02, |
|
91 |
LeftAdjusted = 0x04, |
|
92 |
BlankBeforePositive = 0x08, |
|
93 |
AlwaysShowSign = 0x10, |
|
94 |
ThousandsGroup = 0x20, |
|
95 |
CapitalEorX = 0x40, |
|
96 |
||
97 |
ShowBase = 0x80, |
|
98 |
UppercaseBase = 0x100, |
|
99 |
ForcePoint = Alternate |
|
100 |
}; |
|
101 |
||
102 |
enum GroupSeparatorMode { |
|
103 |
FailOnGroupSeparators, |
|
104 |
ParseGroupSeparators |
|
105 |
}; |
|
106 |
||
107 |
QString doubleToString(double d, |
|
108 |
int precision = -1, |
|
109 |
DoubleForm form = DFSignificantDigits, |
|
110 |
int width = -1, |
|
111 |
unsigned flags = NoFlags) const; |
|
112 |
QString longLongToString(qint64 l, int precision = -1, |
|
113 |
int base = 10, |
|
114 |
int width = -1, |
|
115 |
unsigned flags = NoFlags) const; |
|
116 |
QString unsLongLongToString(quint64 l, int precision = -1, |
|
117 |
int base = 10, |
|
118 |
int width = -1, |
|
119 |
unsigned flags = NoFlags) const; |
|
120 |
double stringToDouble(const QString &num, bool *ok, GroupSeparatorMode group_sep_mode) const; |
|
121 |
qint64 stringToLongLong(const QString &num, int base, bool *ok, GroupSeparatorMode group_sep_mode) const; |
|
122 |
quint64 stringToUnsLongLong(const QString &num, int base, bool *ok, GroupSeparatorMode group_sep_mode) const; |
|
123 |
||
124 |
||
125 |
static double bytearrayToDouble(const char *num, bool *ok, bool *overflow = 0); |
|
126 |
static qint64 bytearrayToLongLong(const char *num, int base, bool *ok, bool *overflow = 0); |
|
127 |
static quint64 bytearrayToUnsLongLong(const char *num, int base, bool *ok); |
|
128 |
||
129 |
typedef QVarLengthArray<char, 256> CharBuff; |
|
130 |
bool numberToCLocale(const QString &num, |
|
131 |
GroupSeparatorMode group_sep_mode, |
|
132 |
CharBuff *result) const; |
|
133 |
inline char digitToCLocale(const QChar &c) const; |
|
134 |
||
135 |
static void updateSystemPrivate(); |
|
136 |
||
137 |
enum NumberMode { IntegerMode, DoubleStandardMode, DoubleScientificMode }; |
|
138 |
bool validateChars(const QString &str, NumberMode numMode, QByteArray *buff, int decDigits = -1) const; |
|
139 |
||
140 |
QString dateTimeToString(const QString &format, const QDate *date, const QTime *time, |
|
141 |
const QLocale *q) const; |
|
142 |
||
143 |
quint16 m_language_id, m_country_id; |
|
144 |
||
145 |
quint16 m_decimal, m_group, m_list, m_percent, |
|
146 |
m_zero, m_minus, m_plus, m_exponential; |
|
147 |
||
148 |
quint16 m_short_date_format_idx, m_short_date_format_size; |
|
149 |
quint16 m_long_date_format_idx, m_long_date_format_size; |
|
150 |
quint16 m_short_time_format_idx, m_short_time_format_size; |
|
151 |
quint16 m_long_time_format_idx, m_long_time_format_size; |
|
152 |
quint16 m_standalone_short_month_names_idx, m_standalone_short_month_names_size; |
|
153 |
quint16 m_standalone_long_month_names_idx, m_standalone_long_month_names_size; |
|
154 |
quint16 m_standalone_narrow_month_names_idx, m_standalone_narrow_month_names_size; |
|
155 |
quint16 m_short_month_names_idx, m_short_month_names_size; |
|
156 |
quint16 m_long_month_names_idx, m_long_month_names_size; |
|
157 |
quint16 m_narrow_month_names_idx, m_narrow_month_names_size; |
|
158 |
quint16 m_standalone_short_day_names_idx, m_standalone_short_day_names_size; |
|
159 |
quint16 m_standalone_long_day_names_idx, m_standalone_long_day_names_size; |
|
160 |
quint16 m_standalone_narrow_day_names_idx, m_standalone_narrow_day_names_size; |
|
161 |
quint16 m_short_day_names_idx, m_short_day_names_size; |
|
162 |
quint16 m_long_day_names_idx, m_long_day_names_size; |
|
163 |
quint16 m_narrow_day_names_idx, m_narrow_day_names_size; |
|
164 |
quint16 m_am_idx, m_am_size; |
|
165 |
quint16 m_pm_idx, m_pm_size; |
|
166 |
}; |
|
167 |
||
168 |
inline char QLocalePrivate::digitToCLocale(const QChar &in) const |
|
169 |
{ |
|
170 |
const QChar _zero = zero(); |
|
171 |
const QChar _group = group(); |
|
172 |
const ushort zeroUnicode = _zero.unicode(); |
|
173 |
const ushort tenUnicode = zeroUnicode + 10; |
|
174 |
||
175 |
if (in.unicode() >= zeroUnicode && in.unicode() < tenUnicode) |
|
176 |
return '0' + in.unicode() - zeroUnicode; |
|
177 |
||
178 |
if (in.unicode() >= '0' && in.unicode() <= '9') |
|
179 |
return in.toLatin1(); |
|
180 |
||
181 |
if (in == plus()) |
|
182 |
return '+'; |
|
183 |
||
184 |
if (in == minus()) |
|
185 |
return '-'; |
|
186 |
||
187 |
if (in == decimal()) |
|
188 |
return '.'; |
|
189 |
||
190 |
if (in == group()) |
|
191 |
return ','; |
|
192 |
||
193 |
if (in == exponential() || in == exponential().toUpper()) |
|
194 |
return 'e'; |
|
195 |
||
196 |
// In several languages group() is the char 0xA0, which looks like a space. |
|
197 |
// People use a regular space instead of it and complain it doesn't work. |
|
198 |
if (_group.unicode() == 0xA0 && in.unicode() == ' ') |
|
199 |
return ','; |
|
200 |
||
201 |
return 0; |
|
202 |
} |
|
203 |
||
204 |
QT_END_NAMESPACE |
|
205 |
||
206 |
#endif // QLOCALE_P_H |