1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the QtCore module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
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 | #include "QtCore/qmetatype.h" |
59 | |
60 | #include "qlocale.h" |
61 | |
62 | #if defined(Q_OS_SYMBIAN) && !defined(QT_NO_SYSTEMLOCALE) |
63 | class CEnvironmentChangeNotifier; |
64 | #endif |
65 | |
66 | QT_BEGIN_NAMESPACE |
67 | |
68 | struct Q_CORE_EXPORT QLocalePrivate |
69 | { |
70 | public: |
71 | QChar decimal() const { return QChar(m_decimal); } |
72 | QChar group() const { return QChar(m_group); } |
73 | QChar list() const { return QChar(m_list); } |
74 | QChar percent() const { return QChar(m_percent); } |
75 | QChar zero() const { return QChar(m_zero); } |
76 | QChar plus() const { return QChar(m_plus); } |
77 | QChar minus() const { return QChar(m_minus); } |
78 | QChar exponential() const { return QChar(m_exponential); } |
79 | |
80 | quint16 languageId() const { return m_language_id; } |
81 | quint16 countryId() const { return m_country_id; } |
82 | |
83 | QString bcp47Name() const; |
84 | |
85 | QString languageCode() const; // ### QByteArray::fromRawData would be more optimal |
86 | QString scriptCode() const; |
87 | QString countryCode() const; |
88 | |
89 | static QLocale::Language codeToLanguage(const QString &code); |
90 | static QLocale::Script codeToScript(const QString &code); |
91 | static QLocale::Country codeToCountry(const QString &code); |
92 | static void getLangAndCountry(const QString &name, QLocale::Language &lang, |
93 | QLocale::Script &script, QLocale::Country &cntry); |
94 | static const QLocalePrivate *findLocale(QLocale::Language language, |
95 | QLocale::Script script, |
96 | QLocale::Country country); |
97 | |
98 | |
99 | QLocale::MeasurementSystem measurementSystem() const; |
100 | |
101 | enum DoubleForm { |
102 | DFExponent = 0, |
103 | DFDecimal, |
104 | DFSignificantDigits, |
105 | _DFMax = DFSignificantDigits |
106 | }; |
107 | |
108 | enum Flags { |
109 | NoFlags = 0, |
110 | Alternate = 0x01, |
111 | ZeroPadded = 0x02, |
112 | LeftAdjusted = 0x04, |
113 | BlankBeforePositive = 0x08, |
114 | AlwaysShowSign = 0x10, |
115 | ThousandsGroup = 0x20, |
116 | CapitalEorX = 0x40, |
117 | |
118 | ShowBase = 0x80, |
119 | UppercaseBase = 0x100, |
120 | ForcePoint = Alternate |
121 | }; |
122 | |
123 | enum GroupSeparatorMode { |
124 | FailOnGroupSeparators, |
125 | ParseGroupSeparators |
126 | }; |
127 | |
128 | static QString doubleToString(const QChar zero, const QChar plus, |
129 | const QChar minus, const QChar exponent, |
130 | const QChar group, const QChar decimal, |
131 | double d, int precision, |
132 | DoubleForm form, |
133 | int width, unsigned flags); |
134 | static QString longLongToString(const QChar zero, const QChar group, |
135 | const QChar plus, const QChar minus, |
136 | qint64 l, int precision, int base, |
137 | int width, unsigned flags); |
138 | static QString unsLongLongToString(const QChar zero, const QChar group, |
139 | const QChar plus, |
140 | quint64 l, int precision, |
141 | int base, int width, |
142 | unsigned flags); |
143 | |
144 | QString doubleToString(double d, |
145 | int precision = -1, |
146 | DoubleForm form = DFSignificantDigits, |
147 | int width = -1, |
148 | unsigned flags = NoFlags) const; |
149 | QString longLongToString(qint64 l, int precision = -1, |
150 | int base = 10, |
151 | int width = -1, |
152 | unsigned flags = NoFlags) const; |
153 | QString unsLongLongToString(quint64 l, int precision = -1, |
154 | int base = 10, |
155 | int width = -1, |
156 | unsigned flags = NoFlags) const; |
157 | double stringToDouble(const QString &num, bool *ok, GroupSeparatorMode group_sep_mode) const; |
158 | qint64 stringToLongLong(const QString &num, int base, bool *ok, GroupSeparatorMode group_sep_mode) const; |
159 | quint64 stringToUnsLongLong(const QString &num, int base, bool *ok, GroupSeparatorMode group_sep_mode) const; |
160 | |
161 | |
162 | static double bytearrayToDouble(const char *num, bool *ok, bool *overflow = 0); |
163 | static qint64 bytearrayToLongLong(const char *num, int base, bool *ok, bool *overflow = 0); |
164 | static quint64 bytearrayToUnsLongLong(const char *num, int base, bool *ok); |
165 | |
166 | typedef QVarLengthArray<char, 256> CharBuff; |
167 | bool numberToCLocale(const QString &num, |
168 | GroupSeparatorMode group_sep_mode, |
169 | CharBuff *result) const; |
170 | inline char digitToCLocale(const QChar &c) const; |
171 | |
172 | static void updateSystemPrivate(); |
173 | |
174 | enum NumberMode { IntegerMode, DoubleStandardMode, DoubleScientificMode }; |
175 | bool validateChars(const QString &str, NumberMode numMode, QByteArray *buff, int decDigits = -1) const; |
176 | |
177 | QString dateTimeToString(const QString &format, const QDate *date, const QTime *time, |
178 | const QLocale *q) const; |
179 | |
180 | quint16 m_language_id, m_script_id, m_country_id; |
181 | |
182 | quint16 m_decimal, m_group, m_list, m_percent, |
183 | m_zero, m_minus, m_plus, m_exponential; |
184 | quint16 m_quotation_start, m_quotation_end; |
185 | quint16 m_alternate_quotation_start, m_alternate_quotation_end; |
186 | |
187 | quint16 m_list_pattern_part_start_idx, m_list_pattern_part_start_size; |
188 | quint16 m_list_pattern_part_mid_idx, m_list_pattern_part_mid_size; |
189 | quint16 m_list_pattern_part_end_idx, m_list_pattern_part_end_size; |
190 | quint16 m_list_pattern_part_two_idx, m_list_pattern_part_two_size; |
191 | quint16 m_short_date_format_idx, m_short_date_format_size; |
192 | quint16 m_long_date_format_idx, m_long_date_format_size; |
193 | quint16 m_short_time_format_idx, m_short_time_format_size; |
194 | quint16 m_long_time_format_idx, m_long_time_format_size; |
195 | quint16 m_standalone_short_month_names_idx, m_standalone_short_month_names_size; |
196 | quint16 m_standalone_long_month_names_idx, m_standalone_long_month_names_size; |
197 | quint16 m_standalone_narrow_month_names_idx, m_standalone_narrow_month_names_size; |
198 | quint16 m_short_month_names_idx, m_short_month_names_size; |
199 | quint16 m_long_month_names_idx, m_long_month_names_size; |
200 | quint16 m_narrow_month_names_idx, m_narrow_month_names_size; |
201 | quint16 m_standalone_short_day_names_idx, m_standalone_short_day_names_size; |
202 | quint16 m_standalone_long_day_names_idx, m_standalone_long_day_names_size; |
203 | quint16 m_standalone_narrow_day_names_idx, m_standalone_narrow_day_names_size; |
204 | quint16 m_short_day_names_idx, m_short_day_names_size; |
205 | quint16 m_long_day_names_idx, m_long_day_names_size; |
206 | quint16 m_narrow_day_names_idx, m_narrow_day_names_size; |
207 | quint16 m_am_idx, m_am_size; |
208 | quint16 m_pm_idx, m_pm_size; |
209 | char m_currency_iso_code[3]; |
210 | quint16 m_currency_symbol_idx, m_currency_symbol_size; |
211 | quint16 m_currency_display_name_idx, m_currency_display_name_size; |
212 | quint8 m_currency_format_idx, m_currency_format_size; |
213 | quint8 m_currency_negative_format_idx, m_currency_negative_format_size; |
214 | quint16 m_language_endonym_idx, m_language_endonym_size; |
215 | quint16 m_country_endonym_idx, m_country_endonym_size; |
216 | quint16 m_currency_digits : 2; |
217 | quint16 m_currency_rounding : 3; |
218 | quint16 m_first_day_of_week : 3; |
219 | quint16 m_weekend_start : 3; |
220 | quint16 m_weekend_end : 3; |
221 | |
222 | }; |
223 | |
224 | inline char QLocalePrivate::digitToCLocale(const QChar &in) const |
225 | { |
226 | const QChar _zero = zero(); |
227 | const QChar _group = group(); |
228 | const ushort zeroUnicode = _zero.unicode(); |
229 | const ushort tenUnicode = zeroUnicode + 10; |
230 | |
231 | if (in.unicode() >= zeroUnicode && in.unicode() < tenUnicode) |
232 | return '0' + in.unicode() - zeroUnicode; |
233 | |
234 | if (in.unicode() >= '0' && in.unicode() <= '9') |
235 | return in.toLatin1(); |
236 | |
237 | if (in == plus()) |
238 | return '+'; |
239 | |
240 | if (in == minus()) |
241 | return '-'; |
242 | |
243 | if (in == decimal()) |
244 | return '.'; |
245 | |
246 | if (in == group()) |
247 | return ','; |
248 | |
249 | if (in == exponential() || in == exponential().toUpper()) |
250 | return 'e'; |
251 | |
252 | // In several languages group() is the char 0xA0, which looks like a space. |
253 | // People use a regular space instead of it and complain it doesn't work. |
254 | if (_group.unicode() == 0xA0 && in.unicode() == ' ') |
255 | return ','; |
256 | |
257 | return 0; |
258 | } |
259 | |
260 | #if defined(Q_OS_SYMBIAN) && !defined(QT_NO_SYSTEMLOCALE) |
261 | class QEnvironmentChangeNotifier |
262 | { |
263 | public: |
264 | QEnvironmentChangeNotifier(); |
265 | ~QEnvironmentChangeNotifier(); |
266 | |
267 | static TInt localeChanged(TAny *data); |
268 | |
269 | private: |
270 | CEnvironmentChangeNotifier *iChangeNotifier; |
271 | }; |
272 | #endif |
273 | |
274 | QString qt_readEscapedFormatString(const QString &format, int *idx); |
275 | bool qt_splitLocaleName(const QString &name, QString &lang, QString &script, QString &cntry); |
276 | int qt_repeatCount(const QString &s, int i); |
277 | |
278 | QT_END_NAMESPACE |
279 | |
280 | Q_DECLARE_METATYPE(QStringRef) |
281 | Q_DECLARE_METATYPE(QList<Qt::DayOfWeek>) |
282 | |
283 | #endif // QLOCALE_P_H |
284 | |