Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qlocale.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||
4 | ** Copyright (C) 2016 Intel Corporation. | - | ||||||||||||||||||||||||
5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
6 | ** | - | ||||||||||||||||||||||||
7 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||||||||
8 | ** | - | ||||||||||||||||||||||||
9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||||||||
10 | ** Commercial License Usage | - | ||||||||||||||||||||||||
11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
15 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
16 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
17 | ** | - | ||||||||||||||||||||||||
18 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
20 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||||||||
21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||
22 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||
23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||
24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||
25 | ** | - | ||||||||||||||||||||||||
26 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||
27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||
28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||
29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||
30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||
31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||
32 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||
33 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||
34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||
35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||
36 | ** | - | ||||||||||||||||||||||||
37 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
38 | ** | - | ||||||||||||||||||||||||
39 | ****************************************************************************/ | - | ||||||||||||||||||||||||
40 | - | |||||||||||||||||||||||||
41 | #if !defined(QWS) && defined(Q_OS_MAC) | - | ||||||||||||||||||||||||
42 | # include "private/qcore_mac_p.h" | - | ||||||||||||||||||||||||
43 | # include <CoreFoundation/CoreFoundation.h> | - | ||||||||||||||||||||||||
44 | #endif | - | ||||||||||||||||||||||||
45 | - | |||||||||||||||||||||||||
46 | #include "qglobal.h" | - | ||||||||||||||||||||||||
47 | - | |||||||||||||||||||||||||
48 | #include "qplatformdefs.h" | - | ||||||||||||||||||||||||
49 | - | |||||||||||||||||||||||||
50 | #include "qdatastream.h" | - | ||||||||||||||||||||||||
51 | #include "qdebug.h" | - | ||||||||||||||||||||||||
52 | #include "qhashfunctions.h" | - | ||||||||||||||||||||||||
53 | #include "qstring.h" | - | ||||||||||||||||||||||||
54 | #include "qlocale.h" | - | ||||||||||||||||||||||||
55 | #include "qlocale_p.h" | - | ||||||||||||||||||||||||
56 | #include "qlocale_tools_p.h" | - | ||||||||||||||||||||||||
#include "qdatetime_p.h" | ||||||||||||||||||||||||||
57 | #include "qdatetimeparser_p.h" | - | ||||||||||||||||||||||||
58 | #include "qnamespace.h" | - | ||||||||||||||||||||||||
59 | #include "qdatetime.h" | - | ||||||||||||||||||||||||
60 | #include "qstringlist.h" | - | ||||||||||||||||||||||||
61 | #include "qvariant.h" | - | ||||||||||||||||||||||||
62 | #include "qstringbuilder.h" | - | ||||||||||||||||||||||||
63 | #include "private/qnumeric_p.h" | - | ||||||||||||||||||||||||
64 | #include "private/qsystemlibrary_p.h" | - | ||||||||||||||||||||||||
65 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
66 | # include <qt_windows.h> | - | ||||||||||||||||||||||||
67 | # include <time.h> | - | ||||||||||||||||||||||||
68 | #endif | - | ||||||||||||||||||||||||
69 | - | |||||||||||||||||||||||||
70 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
71 | - | |||||||||||||||||||||||||
72 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
73 | static QSystemLocale *_systemLocale = 0; | - | ||||||||||||||||||||||||
74 | class QSystemLocaleSingleton: public QSystemLocale | - | ||||||||||||||||||||||||
75 | { | - | ||||||||||||||||||||||||
76 | public: | - | ||||||||||||||||||||||||
77 | QSystemLocaleSingleton() : QSystemLocale(true) {} | - | ||||||||||||||||||||||||
78 | }; | - | ||||||||||||||||||||||||
79 | - | |||||||||||||||||||||||||
80 | Q_GLOBAL_STATIC(QSystemLocaleSingleton, QSystemLocale_globalSystemLocale) | - | ||||||||||||||||||||||||
81 | static QLocaleData *system_data = 0; | - | ||||||||||||||||||||||||
Q_GLOBAL_STATIC(static QLocaleData ,globalLocaleData); | ||||||||||||||||||||||||||
83 | #endif | - | ||||||||||||||||||||||||
84 | - | |||||||||||||||||||||||||
85 | /****************************************************************************** | - | ||||||||||||||||||||||||
86 | ** Helpers for accessing Qt locale database | - | ||||||||||||||||||||||||
87 | */ | - | ||||||||||||||||||||||||
88 | - | |||||||||||||||||||||||||
89 | QT_BEGIN_INCLUDE_NAMESPACE | - | ||||||||||||||||||||||||
90 | #include "qlocale_data_p.h" | - | ||||||||||||||||||||||||
91 | QT_END_INCLUDE_NAMESPACE | - | ||||||||||||||||||||||||
92 | - | |||||||||||||||||||||||||
93 | QLocale::Language QLocalePrivate::codeToLanguage(const QString &code) | - | ||||||||||||||||||||||||
{QChar *code, int len= code.length();) Q_DECL_NOTHROW | ||||||||||||||||||||||||||
94 | { | - | ||||||||||||||||||||||||
95 | if (len != 2 && len != 3)
| 0-2372 | ||||||||||||||||||||||||
96 | return QLocale::C; never executed: return QLocale::C; | 0 | ||||||||||||||||||||||||
97 | ushort uc1 = code[0].toLower().unicode(); | - | ||||||||||||||||||||||||
98 | ushort uc2 = code[1].toLower().unicode(); | - | ||||||||||||||||||||||||
99 | ushort uc3 = len > 2 ? code[2].toLower().unicode() : 0;
| 0-2372 | ||||||||||||||||||||||||
100 | - | |||||||||||||||||||||||||
101 | const unsigned char *c = language_code_list; | - | ||||||||||||||||||||||||
102 | for (; *c != 0; c += 3) {
| 7-80935 | ||||||||||||||||||||||||
103 | if (uc1 == c[0] && uc2 == c[1] && uc3 == c[2])
| 14-75733 | ||||||||||||||||||||||||
104 | return QLocale::Language((c - language_code_list)/3); executed 2365 times by 25 tests: return QLocale::Language((c - language_code_list)/3); Executed by:
| 2365 | ||||||||||||||||||||||||
105 | } executed 78570 times by 25 tests: end of block Executed by:
| 78570 | ||||||||||||||||||||||||
106 | - | |||||||||||||||||||||||||
107 | // legacy codes | - | ||||||||||||||||||||||||
108 | if (uc1 == 'n' && uc2 == 'o' && uc3 == 0) { // no -> nb
| 0-7 | ||||||||||||||||||||||||
109 | Q_STATIC_ASSERT(QLocale::Norwegian == QLocale::NorwegianBokmal); | - | ||||||||||||||||||||||||
110 | return QLocale::Norwegian; executed 7 times by 2 tests: return QLocale::Norwegian; Executed by:
| 7 | ||||||||||||||||||||||||
111 | } | - | ||||||||||||||||||||||||
112 | if (uc1 == 't' && uc2 == 'l' && uc3 == 0) { // tl -> fil
| 0 | ||||||||||||||||||||||||
113 | Q_STATIC_ASSERT(QLocale::Tagalog == QLocale::Filipino); | - | ||||||||||||||||||||||||
114 | return QLocale::Tagalog; never executed: return QLocale::Tagalog; | 0 | ||||||||||||||||||||||||
115 | } | - | ||||||||||||||||||||||||
116 | if (uc1 == 's' && uc2 == 'h' && uc3 == 0) { // sh -> sr[_Latn]
| 0 | ||||||||||||||||||||||||
117 | Q_STATIC_ASSERT(QLocale::SerboCroatian == QLocale::Serbian); | - | ||||||||||||||||||||||||
118 | return QLocale::SerboCroatian; never executed: return QLocale::SerboCroatian; | 0 | ||||||||||||||||||||||||
119 | } | - | ||||||||||||||||||||||||
120 | if (uc1 == 'm' && uc2 == 'o' && uc3 == 0) { // mo -> ro
| 0 | ||||||||||||||||||||||||
121 | Q_STATIC_ASSERT(QLocale::Moldavian == QLocale::Romanian); | - | ||||||||||||||||||||||||
122 | return QLocale::Moldavian; never executed: return QLocale::Moldavian; | 0 | ||||||||||||||||||||||||
123 | } | - | ||||||||||||||||||||||||
124 | // Android uses the following deprecated codes | - | ||||||||||||||||||||||||
125 | if (uc1 == 'i' && uc2 == 'w' && uc3 == 0) // iw -> he
| 0 | ||||||||||||||||||||||||
126 | return QLocale::Hebrew; never executed: return QLocale::Hebrew; | 0 | ||||||||||||||||||||||||
127 | if (uc1 == 'i' && uc2 == 'n' && uc3 == 0) // in -> id
| 0 | ||||||||||||||||||||||||
128 | return QLocale::Indonesian; never executed: return QLocale::Indonesian; | 0 | ||||||||||||||||||||||||
129 | if (uc1 == 'j' && uc2 == 'i' && uc3 == 0) // ji -> yi
| 0 | ||||||||||||||||||||||||
130 | return QLocale::Yiddish; never executed: return QLocale::Yiddish; | 0 | ||||||||||||||||||||||||
131 | - | |||||||||||||||||||||||||
132 | return QLocale::C; never executed: return QLocale::C; | 0 | ||||||||||||||||||||||||
133 | } | - | ||||||||||||||||||||||||
134 | - | |||||||||||||||||||||||||
135 | QLocale::Script QLocalePrivate::codeToScript(const QString &code) | - | ||||||||||||||||||||||||
{QChar *code, int len= code.length();) Q_DECL_NOTHROW | ||||||||||||||||||||||||||
136 | { | - | ||||||||||||||||||||||||
137 | if (len != 4)
| 0-2372 | ||||||||||||||||||||||||
138 | return QLocale::AnyScript; executed 2372 times by 25 tests: return QLocale::AnyScript; Executed by:
| 2372 | ||||||||||||||||||||||||
139 | - | |||||||||||||||||||||||||
140 | // script is titlecased in our data | - | ||||||||||||||||||||||||
141 | unsigned char c0 = code.at([0).].toUpper().toLatin1(); | - | ||||||||||||||||||||||||
142 | unsigned char c1 = code.at([1).].toLower().toLatin1(); | - | ||||||||||||||||||||||||
143 | unsigned char c2 = code.at([2).].toLower().toLatin1(); | - | ||||||||||||||||||||||||
144 | unsigned char c3 = code.at([3).].toLower().toLatin1(); | - | ||||||||||||||||||||||||
145 | - | |||||||||||||||||||||||||
146 | const unsigned char *c = script_code_list; | - | ||||||||||||||||||||||||
147 | for (int i = 0; i < QLocale::LastScript; ++i, c += 4) {
| 0 | ||||||||||||||||||||||||
148 | if (c0 == c[0] && c1 == c[1] && c2 == c[2] && c3 == c[3])
| 0 | ||||||||||||||||||||||||
149 | return QLocale::Script(i); never executed: return QLocale::Script(i); | 0 | ||||||||||||||||||||||||
150 | } never executed: end of block | 0 | ||||||||||||||||||||||||
151 | return QLocale::AnyScript; never executed: return QLocale::AnyScript; | 0 | ||||||||||||||||||||||||
152 | } | - | ||||||||||||||||||||||||
153 | - | |||||||||||||||||||||||||
154 | QLocale::Country QLocalePrivate::codeToCountry(const QString &code) | - | ||||||||||||||||||||||||
{QChar *code, int len= code.length();) Q_DECL_NOTHROW | ||||||||||||||||||||||||||
155 | { | - | ||||||||||||||||||||||||
156 | if (len != 2 && len != 3)
| 0-2717 | ||||||||||||||||||||||||
157 | return QLocale::AnyCountry; executed 76 times by 6 tests: return QLocale::AnyCountry; Executed by:
| 76 | ||||||||||||||||||||||||
158 | ushort uc1 = code[0].toUpper().unicode(); | - | ||||||||||||||||||||||||
159 | ushort uc2 = code[1].toUpper().unicode(); | - | ||||||||||||||||||||||||
160 | ushort uc3 = len > 2 ? code[2].toUpper().unicode() : 0;
| 0-2717 | ||||||||||||||||||||||||
161 | - | |||||||||||||||||||||||||
162 | const unsigned char *c = country_code_list; | - | ||||||||||||||||||||||||
163 | for (; *c != 0; c += 3) {
| 0-550758 | ||||||||||||||||||||||||
164 | if (uc1 == c[0] && uc2 == c[1] && uc3 == c[2])
| 0-540225 | ||||||||||||||||||||||||
165 | return QLocale::Country((c - country_code_list)/3); executed 2716 times by 22 tests: return QLocale::Country((c - country_code_list)/3); Executed by:
| 2716 | ||||||||||||||||||||||||
166 | } executed 548042 times by 22 tests: end of block Executed by:
| 548042 | ||||||||||||||||||||||||
167 | - | |||||||||||||||||||||||||
168 | return QLocale::AnyCountry; never executed: return QLocale::AnyCountry; | 0 | ||||||||||||||||||||||||
169 | } | - | ||||||||||||||||||||||||
170 | - | |||||||||||||||||||||||||
171 | QString QLocalePrivate::languageToCode(QLocale::Language language) | - | ||||||||||||||||||||||||
172 | { | - | ||||||||||||||||||||||||
173 | if (language == QLocale::AnyLanguage) | - | ||||||||||||||||||||||||
174 | return QString(); | - | ||||||||||||||||||||||||
175 | if (language == QLocale::C) | - | ||||||||||||||||||||||||
176 | return QLatin1String("C"); | - | ||||||||||||||||||||||||
177 | - | |||||||||||||||||||||||||
178 | const unsigned char *c = language_code_list + 3*(uint(language)); | - | ||||||||||||||||||||||||
179 | - | |||||||||||||||||||||||||
180 | QString code(c[2] == 0 ? 2 : 3, Qt::Uninitialized); | - | ||||||||||||||||||||||||
181 | - | |||||||||||||||||||||||||
182 | code[0] = ushort(c[0]); | - | ||||||||||||||||||||||||
183 | code[1] = ushort(c[1]); | - | ||||||||||||||||||||||||
184 | if (c[2] != 0) | - | ||||||||||||||||||||||||
185 | code[2] = ushort(c[2]); | - | ||||||||||||||||||||||||
186 | - | |||||||||||||||||||||||||
187 | return code; | - | ||||||||||||||||||||||||
188 | } | - | ||||||||||||||||||||||||
189 | - | |||||||||||||||||||||||||
190 | QString QLocalePrivate::scriptToCode(QLocale::Script script) | - | ||||||||||||||||||||||||
191 | { | - | ||||||||||||||||||||||||
192 | if (script == QLocale::AnyScript || script > QLocale::LastScript) | - | ||||||||||||||||||||||||
193 | return QString(); | - | ||||||||||||||||||||||||
194 | const unsigned char *c = script_code_list + 4*(uint(script)); | - | ||||||||||||||||||||||||
195 | return QString::fromLatin1((const char *)c, 4); | - | ||||||||||||||||||||||||
196 | } | - | ||||||||||||||||||||||||
197 | - | |||||||||||||||||||||||||
198 | QString QLocalePrivate::countryToCode(QLocale::Country country) | - | ||||||||||||||||||||||||
199 | { | - | ||||||||||||||||||||||||
200 | if (country == QLocale::AnyCountry) | - | ||||||||||||||||||||||||
201 | return QString(); | - | ||||||||||||||||||||||||
202 | - | |||||||||||||||||||||||||
203 | const unsigned char *c = country_code_list + 3*(uint(country)); | - | ||||||||||||||||||||||||
204 | - | |||||||||||||||||||||||||
205 | QString code(c[2] == 0 ? 2 : 3, Qt::Uninitialized); | - | ||||||||||||||||||||||||
206 | - | |||||||||||||||||||||||||
207 | code[0] = ushort(c[0]); | - | ||||||||||||||||||||||||
208 | code[1] = ushort(c[1]); | - | ||||||||||||||||||||||||
209 | if (c[2] != 0) | - | ||||||||||||||||||||||||
210 | code[2] = ushort(c[2]); | - | ||||||||||||||||||||||||
211 | - | |||||||||||||||||||||||||
212 | return code; | - | ||||||||||||||||||||||||
213 | } | - | ||||||||||||||||||||||||
214 | - | |||||||||||||||||||||||||
215 | // http://www.unicode.org/reports/tr35/#Likely_Subtags | - | ||||||||||||||||||||||||
216 | static bool addLikelySubtags(QLocaleId &localeId) | - | ||||||||||||||||||||||||
217 | { | - | ||||||||||||||||||||||||
218 | // ### optimize with bsearch | - | ||||||||||||||||||||||||
219 | const int likely_subtags_count = sizeof(likely_subtags) / sizeof(likely_subtags[0]); | - | ||||||||||||||||||||||||
220 | const QLocaleId *p = likely_subtags; | - | ||||||||||||||||||||||||
221 | const QLocaleId *const e = p + likely_subtags_count; | - | ||||||||||||||||||||||||
222 | for ( ; p < e; p += 2) { | - | ||||||||||||||||||||||||
223 | if (localeId == p[0]) { | - | ||||||||||||||||||||||||
224 | localeId = p[1]; | - | ||||||||||||||||||||||||
225 | return true; | - | ||||||||||||||||||||||||
226 | } | - | ||||||||||||||||||||||||
227 | } | - | ||||||||||||||||||||||||
228 | return false; | - | ||||||||||||||||||||||||
229 | } | - | ||||||||||||||||||||||||
230 | - | |||||||||||||||||||||||||
231 | QLocaleId QLocaleId::withLikelySubtagsAdded() const | - | ||||||||||||||||||||||||
232 | { | - | ||||||||||||||||||||||||
233 | // language_script_region | - | ||||||||||||||||||||||||
234 | if (language_id || script_id || country_id) { | - | ||||||||||||||||||||||||
235 | QLocaleId id = QLocaleId::fromIds(language_id, script_id, country_id); | - | ||||||||||||||||||||||||
236 | if (addLikelySubtags(id)) | - | ||||||||||||||||||||||||
237 | return id; | - | ||||||||||||||||||||||||
238 | } | - | ||||||||||||||||||||||||
239 | // language_script | - | ||||||||||||||||||||||||
240 | if (country_id) { | - | ||||||||||||||||||||||||
241 | QLocaleId id = QLocaleId::fromIds(language_id, script_id, 0); | - | ||||||||||||||||||||||||
242 | if (addLikelySubtags(id)) { | - | ||||||||||||||||||||||||
243 | id.country_id = country_id; | - | ||||||||||||||||||||||||
244 | return id; | - | ||||||||||||||||||||||||
245 | } | - | ||||||||||||||||||||||||
246 | } | - | ||||||||||||||||||||||||
247 | // language_region | - | ||||||||||||||||||||||||
248 | if (script_id) { | - | ||||||||||||||||||||||||
249 | QLocaleId id = QLocaleId::fromIds(language_id, 0, country_id); | - | ||||||||||||||||||||||||
250 | if (addLikelySubtags(id)) { | - | ||||||||||||||||||||||||
251 | id.script_id = script_id; | - | ||||||||||||||||||||||||
252 | return id; | - | ||||||||||||||||||||||||
253 | } | - | ||||||||||||||||||||||||
254 | } | - | ||||||||||||||||||||||||
255 | // language | - | ||||||||||||||||||||||||
256 | if (script_id && country_id) { | - | ||||||||||||||||||||||||
257 | QLocaleId id = QLocaleId::fromIds(language_id, 0, 0); | - | ||||||||||||||||||||||||
258 | if (addLikelySubtags(id)) { | - | ||||||||||||||||||||||||
259 | id.script_id = script_id; | - | ||||||||||||||||||||||||
260 | id.country_id = country_id; | - | ||||||||||||||||||||||||
261 | return id; | - | ||||||||||||||||||||||||
262 | } | - | ||||||||||||||||||||||||
263 | } | - | ||||||||||||||||||||||||
264 | return *this; | - | ||||||||||||||||||||||||
265 | } | - | ||||||||||||||||||||||||
266 | - | |||||||||||||||||||||||||
267 | QLocaleId QLocaleId::withLikelySubtagsRemoved() const | - | ||||||||||||||||||||||||
268 | { | - | ||||||||||||||||||||||||
269 | QLocaleId max = withLikelySubtagsAdded(); | - | ||||||||||||||||||||||||
270 | // language | - | ||||||||||||||||||||||||
271 | { | - | ||||||||||||||||||||||||
272 | QLocaleId id = QLocaleId::fromIds(language_id, 0, 0); | - | ||||||||||||||||||||||||
273 | if (id.withLikelySubtagsAdded() == max) | - | ||||||||||||||||||||||||
274 | return id; | - | ||||||||||||||||||||||||
275 | } | - | ||||||||||||||||||||||||
276 | // language_region | - | ||||||||||||||||||||||||
277 | if (country_id) { | - | ||||||||||||||||||||||||
278 | QLocaleId id = QLocaleId::fromIds(language_id, 0, country_id); | - | ||||||||||||||||||||||||
279 | if (id.withLikelySubtagsAdded() == max) | - | ||||||||||||||||||||||||
280 | return id; | - | ||||||||||||||||||||||||
281 | } | - | ||||||||||||||||||||||||
282 | // language_script | - | ||||||||||||||||||||||||
283 | if (script_id) { | - | ||||||||||||||||||||||||
284 | QLocaleId id = QLocaleId::fromIds(language_id, script_id, 0); | - | ||||||||||||||||||||||||
285 | if (id.withLikelySubtagsAdded() == max) | - | ||||||||||||||||||||||||
286 | return id; | - | ||||||||||||||||||||||||
287 | } | - | ||||||||||||||||||||||||
288 | return max; | - | ||||||||||||||||||||||||
289 | } | - | ||||||||||||||||||||||||
290 | - | |||||||||||||||||||||||||
291 | QByteArray QLocaleId::name(char separator) const | - | ||||||||||||||||||||||||
292 | { | - | ||||||||||||||||||||||||
293 | if (language_id == QLocale::AnyLanguage) | - | ||||||||||||||||||||||||
294 | return QByteArray(); | - | ||||||||||||||||||||||||
295 | if (language_id == QLocale::C) | - | ||||||||||||||||||||||||
296 | return QByteArrayLiteral("C"); | - | ||||||||||||||||||||||||
297 | - | |||||||||||||||||||||||||
298 | const unsigned char *lang = language_code_list + 3 * language_id; | - | ||||||||||||||||||||||||
299 | const unsigned char *script = | - | ||||||||||||||||||||||||
300 | (script_id != QLocale::AnyScript ? script_code_list + 4 * script_id : 0); | - | ||||||||||||||||||||||||
301 | const unsigned char *country = | - | ||||||||||||||||||||||||
302 | (country_id != QLocale::AnyCountry ? country_code_list + 3 * country_id : 0); | - | ||||||||||||||||||||||||
303 | char len = (lang[2] != 0 ? 3 : 2) + (script ? 4+1 : 0) + (country ? (country[2] != 0 ? 3 : 2)+1 : 0); | - | ||||||||||||||||||||||||
304 | QByteArray name(len, Qt::Uninitialized); | - | ||||||||||||||||||||||||
305 | char *uc = name.data(); | - | ||||||||||||||||||||||||
306 | *uc++ = lang[0]; | - | ||||||||||||||||||||||||
307 | *uc++ = lang[1]; | - | ||||||||||||||||||||||||
308 | if (lang[2] != 0) | - | ||||||||||||||||||||||||
309 | *uc++ = lang[2]; | - | ||||||||||||||||||||||||
310 | if (script) { | - | ||||||||||||||||||||||||
311 | *uc++ = separator; | - | ||||||||||||||||||||||||
312 | *uc++ = script[0]; | - | ||||||||||||||||||||||||
313 | *uc++ = script[1]; | - | ||||||||||||||||||||||||
314 | *uc++ = script[2]; | - | ||||||||||||||||||||||||
315 | *uc++ = script[3]; | - | ||||||||||||||||||||||||
316 | } | - | ||||||||||||||||||||||||
317 | if (country) { | - | ||||||||||||||||||||||||
318 | *uc++ = separator; | - | ||||||||||||||||||||||||
319 | *uc++ = country[0]; | - | ||||||||||||||||||||||||
320 | *uc++ = country[1]; | - | ||||||||||||||||||||||||
321 | if (country[2] != 0) | - | ||||||||||||||||||||||||
322 | *uc++ = country[2]; | - | ||||||||||||||||||||||||
323 | } | - | ||||||||||||||||||||||||
324 | return name; | - | ||||||||||||||||||||||||
325 | } | - | ||||||||||||||||||||||||
326 | - | |||||||||||||||||||||||||
327 | QByteArray QLocalePrivate::bcp47Name(char separator) const | - | ||||||||||||||||||||||||
328 | { | - | ||||||||||||||||||||||||
329 | if (m_data->m_language_id == QLocale::AnyLanguage) | - | ||||||||||||||||||||||||
330 | return QByteArray(); | - | ||||||||||||||||||||||||
331 | if (m_data->m_language_id == QLocale::C) | - | ||||||||||||||||||||||||
332 | return QByteArrayLiteral("C"); | - | ||||||||||||||||||||||||
333 | - | |||||||||||||||||||||||||
334 | QLocaleId localeId = QLocaleId::fromIds(m_data->m_language_id, m_data->m_script_id, m_data->m_country_id); | - | ||||||||||||||||||||||||
335 | return localeId.withLikelySubtagsRemoved().name(separator); | - | ||||||||||||||||||||||||
336 | } | - | ||||||||||||||||||||||||
337 | - | |||||||||||||||||||||||||
338 | const QLocaleData *QLocaleData::findLocaleData(QLocale::Language language, QLocale::Script script, QLocale::Country country) | - | ||||||||||||||||||||||||
339 | { | - | ||||||||||||||||||||||||
340 | QLocaleId localeId = QLocaleId::fromIds(language, script, country); | - | ||||||||||||||||||||||||
341 | localeId = localeId.withLikelySubtagsAdded(); | - | ||||||||||||||||||||||||
342 | - | |||||||||||||||||||||||||
343 | uint idx = locale_index[localeId.language_id]; | - | ||||||||||||||||||||||||
344 | - | |||||||||||||||||||||||||
345 | const QLocaleData *data = locale_data + idx; | - | ||||||||||||||||||||||||
346 | - | |||||||||||||||||||||||||
347 | if (idx == 0) // default language has no associated country | - | ||||||||||||||||||||||||
348 | return data; | - | ||||||||||||||||||||||||
349 | - | |||||||||||||||||||||||||
350 | Q_ASSERT(data->m_language_id == localeId.language_id); | - | ||||||||||||||||||||||||
351 | - | |||||||||||||||||||||||||
352 | if (localeId.script_id != QLocale::AnyScript && localeId.country_id != QLocale::AnyCountry) { | - | ||||||||||||||||||||||||
353 | // both script and country are explicitly specified | - | ||||||||||||||||||||||||
354 | do { | - | ||||||||||||||||||||||||
355 | if (data->m_script_id == localeId.script_id && data->m_country_id == localeId.country_id) | - | ||||||||||||||||||||||||
356 | return data; | - | ||||||||||||||||||||||||
357 | ++data; | - | ||||||||||||||||||||||||
358 | } while (data->m_language_id == localeId.language_id); | - | ||||||||||||||||||||||||
359 | - | |||||||||||||||||||||||||
360 | // no match; try again with default script | - | ||||||||||||||||||||||||
361 | localeId.script_id = QLocale::AnyScript; | - | ||||||||||||||||||||||||
362 | data = locale_data + idx; | - | ||||||||||||||||||||||||
363 | } | - | ||||||||||||||||||||||||
364 | - | |||||||||||||||||||||||||
365 | if (localeId.script_id == QLocale::AnyScript && localeId.country_id == QLocale::AnyCountry) | - | ||||||||||||||||||||||||
366 | return data; | - | ||||||||||||||||||||||||
367 | - | |||||||||||||||||||||||||
368 | if (localeId.script_id == QLocale::AnyScript) { | - | ||||||||||||||||||||||||
369 | do { | - | ||||||||||||||||||||||||
370 | if (data->m_country_id == localeId.country_id) | - | ||||||||||||||||||||||||
371 | return data; | - | ||||||||||||||||||||||||
372 | ++data; | - | ||||||||||||||||||||||||
373 | } while (data->m_language_id == localeId.language_id); | - | ||||||||||||||||||||||||
374 | } else if (localeId.country_id == QLocale::AnyCountry) { | - | ||||||||||||||||||||||||
375 | do { | - | ||||||||||||||||||||||||
376 | if (data->m_script_id == localeId.script_id) | - | ||||||||||||||||||||||||
377 | return data; | - | ||||||||||||||||||||||||
378 | ++data; | - | ||||||||||||||||||||||||
379 | } while (data->m_language_id == localeId.language_id); | - | ||||||||||||||||||||||||
380 | } | - | ||||||||||||||||||||||||
381 | - | |||||||||||||||||||||||||
382 | return locale_data + idx; | - | ||||||||||||||||||||||||
383 | } | - | ||||||||||||||||||||||||
384 | - | |||||||||||||||||||||||||
385 | static bool parse_locale_tag(const QString &input, int &i, QString *result, const QString &separators) | - | ||||||||||||||||||||||||
386 | { | - | ||||||||||||||||||||||||
387 | *result = QString(8, Qt::Uninitialized); // worst case according to BCP47 | - | ||||||||||||||||||||||||
388 | QChar *pch = result->data(); | - | ||||||||||||||||||||||||
389 | const QChar *uc = input.data() + i; | - | ||||||||||||||||||||||||
390 | const int l = input.length(); | - | ||||||||||||||||||||||||
391 | int size = 0; | - | ||||||||||||||||||||||||
392 | for (; i < l && size < 8; ++i, ++size) { | - | ||||||||||||||||||||||||
393 | if (separators.contains(*uc)) | - | ||||||||||||||||||||||||
394 | break; | - | ||||||||||||||||||||||||
395 | if (! ((uc->unicode() >= 'a' && uc->unicode() <= 'z') || | - | ||||||||||||||||||||||||
396 | (uc->unicode() >= 'A' && uc->unicode() <= 'Z') || | - | ||||||||||||||||||||||||
397 | (uc->unicode() >= '0' && uc->unicode() <= '9')) ) // latin only | - | ||||||||||||||||||||||||
398 | return false; | - | ||||||||||||||||||||||||
399 | *pch++ = *uc++; | - | ||||||||||||||||||||||||
400 | } | - | ||||||||||||||||||||||||
401 | result->truncate(size); | - | ||||||||||||||||||||||||
402 | return true; | - | ||||||||||||||||||||||||
403 | } | - | ||||||||||||||||||||||||
404 | - | |||||||||||||||||||||||||
405 | bool qt_splitLocaleName(const QString &name, QString &lang, QString &script, QString &cntry) | - | ||||||||||||||||||||||||
406 | { | - | ||||||||||||||||||||||||
407 | const int length = name.length(); | - | ||||||||||||||||||||||||
408 | - | |||||||||||||||||||||||||
409 | lang = script = cntry = QString(); | - | ||||||||||||||||||||||||
410 | - | |||||||||||||||||||||||||
411 | const QString separators = QStringLiteral("_-.@"); | - | ||||||||||||||||||||||||
412 | enum ParserState { NoState, LangState, ScriptState, CountryState }; | - | ||||||||||||||||||||||||
413 | ParserState state = LangState; | - | ||||||||||||||||||||||||
414 | for (int i = 0; i < length && state != NoState; ) { | - | ||||||||||||||||||||||||
415 | QString value; | - | ||||||||||||||||||||||||
416 | if (!parse_locale_tag(name, i, &value, separators) ||value.isEmpty()) | - | ||||||||||||||||||||||||
417 | break; | - | ||||||||||||||||||||||||
418 | QChar sep = i < length ? name.at(i) : QChar(); | - | ||||||||||||||||||||||||
419 | switch (state) { | - | ||||||||||||||||||||||||
420 | case LangState: | - | ||||||||||||||||||||||||
421 | if (!sep.isNull() && !separators.contains(sep)) { | - | ||||||||||||||||||||||||
422 | state = NoState; | - | ||||||||||||||||||||||||
423 | break; | - | ||||||||||||||||||||||||
424 | } | - | ||||||||||||||||||||||||
425 | lang = value; | - | ||||||||||||||||||||||||
426 | if (i == length) { | - | ||||||||||||||||||||||||
427 | // just language was specified | - | ||||||||||||||||||||||||
428 | state = NoState; | - | ||||||||||||||||||||||||
429 | break; | - | ||||||||||||||||||||||||
430 | } | - | ||||||||||||||||||||||||
431 | state = ScriptState; | - | ||||||||||||||||||||||||
432 | break; | - | ||||||||||||||||||||||||
433 | case ScriptState: { | - | ||||||||||||||||||||||||
434 | QString scripts = QString::fromLatin1((const char *)script_code_list, sizeof(script_code_list) - 1); | - | ||||||||||||||||||||||||
435 | if (value.length() == 4 && scripts.indexOf(value) % 4 == 0) { | - | ||||||||||||||||||||||||
436 | // script name is always 4 characters | - | ||||||||||||||||||||||||
437 | script = value; | - | ||||||||||||||||||||||||
438 | state = CountryState; | - | ||||||||||||||||||||||||
439 | } else { | - | ||||||||||||||||||||||||
440 | // it wasn't a script, maybe it is a country then? | - | ||||||||||||||||||||||||
441 | cntry = value; | - | ||||||||||||||||||||||||
442 | state = NoState; | - | ||||||||||||||||||||||||
443 | } | - | ||||||||||||||||||||||||
444 | break; | - | ||||||||||||||||||||||||
445 | } | - | ||||||||||||||||||||||||
446 | case CountryState: | - | ||||||||||||||||||||||||
447 | cntry = value; | - | ||||||||||||||||||||||||
448 | state = NoState; | - | ||||||||||||||||||||||||
449 | break; | - | ||||||||||||||||||||||||
450 | case NoState: | - | ||||||||||||||||||||||||
451 | // shouldn't happen | - | ||||||||||||||||||||||||
452 | qWarning("QLocale: This should never happen"); | - | ||||||||||||||||||||||||
453 | break; | - | ||||||||||||||||||||||||
454 | } | - | ||||||||||||||||||||||||
455 | ++i; | - | ||||||||||||||||||||||||
456 | } | - | ||||||||||||||||||||||||
457 | return lang.length() == 2 || lang.length() == 3; | - | ||||||||||||||||||||||||
458 | } | - | ||||||||||||||||||||||||
459 | - | |||||||||||||||||||||||||
460 | void QLocalePrivate::getLangAndCountry(const QString &name, QLocale::Language &lang, | - | ||||||||||||||||||||||||
461 | QLocale::Script &script, QLocale::Country &cntry) | - | ||||||||||||||||||||||||
462 | { | - | ||||||||||||||||||||||||
463 | lang = QLocale::C; | - | ||||||||||||||||||||||||
464 | script = QLocale::AnyScript; | - | ||||||||||||||||||||||||
465 | cntry = QLocale::AnyCountry; | - | ||||||||||||||||||||||||
466 | - | |||||||||||||||||||||||||
467 | QString lang_code; | - | ||||||||||||||||||||||||
468 | QString script_code; | - | ||||||||||||||||||||||||
469 | QString cntry_code; | - | ||||||||||||||||||||||||
470 | if (!qt_splitLocaleName(name, lang_code, script_code, cntry_code)) | - | ||||||||||||||||||||||||
471 | return; | - | ||||||||||||||||||||||||
472 | - | |||||||||||||||||||||||||
473 | lang = QLocalePrivate::codeToLanguage(lang_code); | - | ||||||||||||||||||||||||
474 | if (lang == QLocale::C) | - | ||||||||||||||||||||||||
475 | return; | - | ||||||||||||||||||||||||
476 | script = QLocalePrivate::codeToScript(script_code); | - | ||||||||||||||||||||||||
477 | cntry = QLocalePrivate::codeToCountry(cntry_code); | - | ||||||||||||||||||||||||
478 | } | - | ||||||||||||||||||||||||
479 | - | |||||||||||||||||||||||||
480 | static const QLocaleData *findLocaleData(const QString &name) | - | ||||||||||||||||||||||||
481 | { | - | ||||||||||||||||||||||||
482 | QLocale::Language lang; | - | ||||||||||||||||||||||||
483 | QLocale::Script script; | - | ||||||||||||||||||||||||
484 | QLocale::Country cntry; | - | ||||||||||||||||||||||||
485 | QLocalePrivate::getLangAndCountry(name, lang, script, cntry); | - | ||||||||||||||||||||||||
486 | - | |||||||||||||||||||||||||
487 | return QLocaleData::findLocaleData(lang, script, cntry); | - | ||||||||||||||||||||||||
488 | } | - | ||||||||||||||||||||||||
489 | - | |||||||||||||||||||||||||
490 | QString qt_readEscapedFormatString(const QString &format, int *idx) | - | ||||||||||||||||||||||||
491 | { | - | ||||||||||||||||||||||||
492 | int &i = *idx; | - | ||||||||||||||||||||||||
493 | - | |||||||||||||||||||||||||
494 | Q_ASSERT(format.at(i) == QLatin1Char('\'')); | - | ||||||||||||||||||||||||
495 | ++i; | - | ||||||||||||||||||||||||
496 | if (i == format.size()) | - | ||||||||||||||||||||||||
497 | return QString(); | - | ||||||||||||||||||||||||
498 | if (format.at(i).unicode() == '\'') { // "''" outside of a quoted stirng | - | ||||||||||||||||||||||||
499 | ++i; | - | ||||||||||||||||||||||||
500 | return QLatin1String("'"); | - | ||||||||||||||||||||||||
501 | } | - | ||||||||||||||||||||||||
502 | - | |||||||||||||||||||||||||
503 | QString result; | - | ||||||||||||||||||||||||
504 | - | |||||||||||||||||||||||||
505 | while (i < format.size()) { | - | ||||||||||||||||||||||||
506 | if (format.at(i).unicode() == '\'') { | - | ||||||||||||||||||||||||
507 | if (i + 1 < format.size() && format.at(i + 1).unicode() == '\'') { | - | ||||||||||||||||||||||||
508 | // "''" inside of a quoted string | - | ||||||||||||||||||||||||
509 | result.append(QLatin1Char('\'')); | - | ||||||||||||||||||||||||
510 | i += 2; | - | ||||||||||||||||||||||||
511 | } else { | - | ||||||||||||||||||||||||
512 | break; | - | ||||||||||||||||||||||||
513 | } | - | ||||||||||||||||||||||||
514 | } else { | - | ||||||||||||||||||||||||
515 | result.append(format.at(i++)); | - | ||||||||||||||||||||||||
516 | } | - | ||||||||||||||||||||||||
517 | } | - | ||||||||||||||||||||||||
518 | if (i < format.size()) | - | ||||||||||||||||||||||||
519 | ++i; | - | ||||||||||||||||||||||||
520 | - | |||||||||||||||||||||||||
521 | return result; | - | ||||||||||||||||||||||||
522 | } | - | ||||||||||||||||||||||||
523 | - | |||||||||||||||||||||||||
524 | int qt_repeatCount(const QString &s, int i) | - | ||||||||||||||||||||||||
525 | { | - | ||||||||||||||||||||||||
526 | QChar c = s.at(i); | - | ||||||||||||||||||||||||
527 | int j = i + 1; | - | ||||||||||||||||||||||||
528 | while (j < s.size() && s.at(j) == c) | - | ||||||||||||||||||||||||
529 | ++j; | - | ||||||||||||||||||||||||
530 | return j - i; | - | ||||||||||||||||||||||||
531 | } | - | ||||||||||||||||||||||||
532 | - | |||||||||||||||||||||||||
533 | static const QLocaleData *default_data = 0; | - | ||||||||||||||||||||||||
534 | static uintQLocale::NumberOptions default_number_options = 0QLocale::DefaultNumberOptions; | - | ||||||||||||||||||||||||
535 | - | |||||||||||||||||||||||||
536 | static const QLocaleData *const c_data = locale_data; | - | ||||||||||||||||||||||||
537 | static QLocalePrivate *c_private() | - | ||||||||||||||||||||||||
538 | { | - | ||||||||||||||||||||||||
539 | static QLocalePrivate c_locale = { c_data, Q_BASIC_ATOMIC_INITIALIZER(1), QLocale::OmitGroupSeparator }; | - | ||||||||||||||||||||||||
540 | return &c_locale; | - | ||||||||||||||||||||||||
541 | } | - | ||||||||||||||||||||||||
542 | - | |||||||||||||||||||||||||
543 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
544 | - | |||||||||||||||||||||||||
545 | - | |||||||||||||||||||||||||
546 | /****************************************************************************** | - | ||||||||||||||||||||||||
547 | ** Default system locale behavior | - | ||||||||||||||||||||||||
548 | */ | - | ||||||||||||||||||||||||
549 | - | |||||||||||||||||||||||||
550 | /*! | - | ||||||||||||||||||||||||
551 | Constructs a QSystemLocale object. The constructor will automatically | - | ||||||||||||||||||||||||
552 | install this object as the system locale and remove any earlier installed | - | ||||||||||||||||||||||||
553 | system locales. | - | ||||||||||||||||||||||||
554 | */ | - | ||||||||||||||||||||||||
555 | QSystemLocale::QSystemLocale() | - | ||||||||||||||||||||||||
556 | { | - | ||||||||||||||||||||||||
557 | delete _systemLocale; | - | ||||||||||||||||||||||||
558 | _systemLocale = this; | - | ||||||||||||||||||||||||
559 | - | |||||||||||||||||||||||||
560 | if (system_data) | - | ||||||||||||||||||||||||
561 | system_data->m_language_id = 0; | - | ||||||||||||||||||||||||
562 | } | - | ||||||||||||||||||||||||
563 | - | |||||||||||||||||||||||||
564 | /*! | - | ||||||||||||||||||||||||
565 | \internal | - | ||||||||||||||||||||||||
566 | */ | - | ||||||||||||||||||||||||
567 | QSystemLocale::QSystemLocale(bool) | - | ||||||||||||||||||||||||
568 | { } | - | ||||||||||||||||||||||||
569 | - | |||||||||||||||||||||||||
570 | /*! | - | ||||||||||||||||||||||||
571 | Deletes the object. | - | ||||||||||||||||||||||||
572 | */ | - | ||||||||||||||||||||||||
573 | QSystemLocale::~QSystemLocale() | - | ||||||||||||||||||||||||
574 | { | - | ||||||||||||||||||||||||
575 | if (_systemLocale == this) { | - | ||||||||||||||||||||||||
576 | _systemLocale = 0; | - | ||||||||||||||||||||||||
577 | - | |||||||||||||||||||||||||
578 | if (system_data) | - | ||||||||||||||||||||||||
579 | system_data->m_language_id = 0; | - | ||||||||||||||||||||||||
580 | } | - | ||||||||||||||||||||||||
581 | } | - | ||||||||||||||||||||||||
582 | - | |||||||||||||||||||||||||
583 | static const QSystemLocale *systemLocale() | - | ||||||||||||||||||||||||
584 | { | - | ||||||||||||||||||||||||
585 | if (_systemLocale) | - | ||||||||||||||||||||||||
586 | return _systemLocale; | - | ||||||||||||||||||||||||
587 | return QSystemLocale_globalSystemLocale(); | - | ||||||||||||||||||||||||
588 | } | - | ||||||||||||||||||||||||
589 | - | |||||||||||||||||||||||||
590 | void QLocalePrivate::updateSystemPrivate() | - | ||||||||||||||||||||||||
591 | { | - | ||||||||||||||||||||||||
592 | const QSystemLocale *sys_locale = systemLocale(); | - | ||||||||||||||||||||||||
593 | if (!system_data)
| 0-1016 | ||||||||||||||||||||||||
594 | system_data = globalLocaleData();&globalLocaleData; executed 1016 times by 12 tests: system_data = &globalLocaleData; Executed by:
| 1016 | ||||||||||||||||||||||||
595 | - | |||||||||||||||||||||||||
596 | // tell the object that the system locale has changed. | - | ||||||||||||||||||||||||
597 | sys_locale->query(QSystemLocale::LocaleChanged, QVariant()); | - | ||||||||||||||||||||||||
598 | - | |||||||||||||||||||||||||
599 | *system_data = *sys_locale->fallbackUiLocale().d->m_data; | - | ||||||||||||||||||||||||
600 | - | |||||||||||||||||||||||||
601 | QVariant res = sys_locale->query(QSystemLocale::LanguageId, QVariant()); | - | ||||||||||||||||||||||||
602 | if (!res.isNull()) {
| 0-1015 | ||||||||||||||||||||||||
603 | system_data->m_language_id = res.toInt(); | - | ||||||||||||||||||||||||
604 | system_data->m_script_id = QLocale::AnyScript; // default for compatibility | - | ||||||||||||||||||||||||
605 | } never executed: end of block | 0 | ||||||||||||||||||||||||
606 | res = sys_locale->query(QSystemLocale::CountryId, QVariant()); | - | ||||||||||||||||||||||||
607 | if (!res.isNull()) {
| 0-1015 | ||||||||||||||||||||||||
608 | system_data->m_country_id = res.toInt(); | - | ||||||||||||||||||||||||
609 | system_data->m_script_id = QLocale::AnyScript; // default for compatibility | - | ||||||||||||||||||||||||
610 | } never executed: end of block | 0 | ||||||||||||||||||||||||
611 | res = sys_locale->query(QSystemLocale::ScriptId, QVariant()); | - | ||||||||||||||||||||||||
612 | if (!res.isNull())
| 0-1015 | ||||||||||||||||||||||||
613 | system_data->m_script_id = res.toInt(); never executed: system_data->m_script_id = res.toInt(); | 0 | ||||||||||||||||||||||||
614 | - | |||||||||||||||||||||||||
615 | res = sys_locale->query(QSystemLocale::DecimalPoint, QVariant()); | - | ||||||||||||||||||||||||
616 | if (!res.isNull())
| 0-1015 | ||||||||||||||||||||||||
617 | system_data->m_decimal = res.toString().at(0).unicode(); executed 1015 times by 12 tests: system_data->m_decimal = res.toString().at(0).unicode(); Executed by:
| 1015 | ||||||||||||||||||||||||
618 | - | |||||||||||||||||||||||||
619 | res = sys_locale->query(QSystemLocale::GroupSeparator, QVariant()); | - | ||||||||||||||||||||||||
620 | if (!res.isNull())
| 0-1015 | ||||||||||||||||||||||||
621 | system_data->m_group = res.toString().at(0).unicode(); executed 1015 times by 12 tests: system_data->m_group = res.toString().at(0).unicode(); Executed by:
| 1015 | ||||||||||||||||||||||||
622 | - | |||||||||||||||||||||||||
623 | res = sys_locale->query(QSystemLocale::ZeroDigit, QVariant()); | - | ||||||||||||||||||||||||
624 | if (!res.isNull())
| 0-1015 | ||||||||||||||||||||||||
625 | system_data->m_zero = res.toString().at(0).unicode(); executed 1015 times by 12 tests: system_data->m_zero = res.toString().at(0).unicode(); Executed by:
| 1015 | ||||||||||||||||||||||||
626 | - | |||||||||||||||||||||||||
627 | res = sys_locale->query(QSystemLocale::NegativeSign, QVariant()); | - | ||||||||||||||||||||||||
628 | if (!res.isNull())
| 0-1015 | ||||||||||||||||||||||||
629 | system_data->m_minus = res.toString().at(0).unicode(); executed 1015 times by 12 tests: system_data->m_minus = res.toString().at(0).unicode(); Executed by:
| 1015 | ||||||||||||||||||||||||
630 | - | |||||||||||||||||||||||||
631 | res = sys_locale->query(QSystemLocale::PositiveSign, QVariant()); | - | ||||||||||||||||||||||||
632 | if (!res.isNull())
| 0-1015 | ||||||||||||||||||||||||
633 | system_data->m_plus = res.toString().at(0).unicode(); executed 1015 times by 12 tests: system_data->m_plus = res.toString().at(0).unicode(); Executed by:
| 1015 | ||||||||||||||||||||||||
634 | } executed 1015 times by 12 tests: end of block Executed by:
| 1015 | ||||||||||||||||||||||||
635 | #endif | - | ||||||||||||||||||||||||
636 | - | |||||||||||||||||||||||||
637 | static const QLocaleData *systemData() | - | ||||||||||||||||||||||||
638 | { | - | ||||||||||||||||||||||||
639 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
640 | // copy over the information from the fallback locale and modify | - | ||||||||||||||||||||||||
641 | if (!system_data || system_data->m_language_id == 0) | - | ||||||||||||||||||||||||
642 | QLocalePrivate::updateSystemPrivate(); | - | ||||||||||||||||||||||||
643 | - | |||||||||||||||||||||||||
644 | return system_data; | - | ||||||||||||||||||||||||
645 | #else | - | ||||||||||||||||||||||||
646 | return locale_data; | - | ||||||||||||||||||||||||
647 | #endif | - | ||||||||||||||||||||||||
648 | } | - | ||||||||||||||||||||||||
649 | - | |||||||||||||||||||||||||
650 | static const QLocaleData *defaultData() | - | ||||||||||||||||||||||||
651 | { | - | ||||||||||||||||||||||||
652 | if (!default_data) | - | ||||||||||||||||||||||||
653 | default_data = systemData(); | - | ||||||||||||||||||||||||
654 | return default_data; | - | ||||||||||||||||||||||||
655 | } | - | ||||||||||||||||||||||||
656 | - | |||||||||||||||||||||||||
657 | const QLocaleData *QLocaleData::c() | - | ||||||||||||||||||||||||
658 | { | - | ||||||||||||||||||||||||
659 | Q_ASSERT(locale_index[QLocale::C] == 0); | - | ||||||||||||||||||||||||
660 | return c_data; | - | ||||||||||||||||||||||||
661 | } | - | ||||||||||||||||||||||||
662 | - | |||||||||||||||||||||||||
663 | static inline QString getLocaleData(const ushort *data, int size) | - | ||||||||||||||||||||||||
664 | { | - | ||||||||||||||||||||||||
665 | return size > 0 ? QString::fromRawData(reinterpret_cast<const QChar *>(data), size) : QString(); | - | ||||||||||||||||||||||||
666 | } | - | ||||||||||||||||||||||||
667 | - | |||||||||||||||||||||||||
668 | static QString getLocaleListData(const ushort *data, int size, int index) | - | ||||||||||||||||||||||||
669 | { | - | ||||||||||||||||||||||||
670 | static const ushort separator = ';'; | - | ||||||||||||||||||||||||
671 | while (index && size > 0) { | - | ||||||||||||||||||||||||
672 | while (*data != separator) | - | ||||||||||||||||||||||||
673 | ++data, --size; | - | ||||||||||||||||||||||||
674 | --index; | - | ||||||||||||||||||||||||
675 | ++data; | - | ||||||||||||||||||||||||
676 | --size; | - | ||||||||||||||||||||||||
677 | } | - | ||||||||||||||||||||||||
678 | const ushort *end = data; | - | ||||||||||||||||||||||||
679 | while (size > 0 && *end != separator) | - | ||||||||||||||||||||||||
680 | ++end, --size; | - | ||||||||||||||||||||||||
681 | return getLocaleData(data, end - data); | - | ||||||||||||||||||||||||
682 | } | - | ||||||||||||||||||||||||
683 | - | |||||||||||||||||||||||||
684 | - | |||||||||||||||||||||||||
685 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||||||||
686 | QDataStream &operator<<(QDataStream &ds, const QLocale &l) | - | ||||||||||||||||||||||||
687 | { | - | ||||||||||||||||||||||||
688 | ds << l.name(); | - | ||||||||||||||||||||||||
689 | return ds; | - | ||||||||||||||||||||||||
690 | } | - | ||||||||||||||||||||||||
691 | - | |||||||||||||||||||||||||
692 | QDataStream &operator>>(QDataStream &ds, QLocale &l) | - | ||||||||||||||||||||||||
693 | { | - | ||||||||||||||||||||||||
694 | QString s; | - | ||||||||||||||||||||||||
695 | ds >> s; | - | ||||||||||||||||||||||||
696 | l = QLocale(s); | - | ||||||||||||||||||||||||
697 | return ds; | - | ||||||||||||||||||||||||
698 | } | - | ||||||||||||||||||||||||
699 | #endif // QT_NO_DATASTREAM | - | ||||||||||||||||||||||||
700 | - | |||||||||||||||||||||||||
701 | - | |||||||||||||||||||||||||
702 | static const int locale_data_size = sizeof(locale_data)/sizeof(QLocaleData) - 1; | - | ||||||||||||||||||||||||
703 | - | |||||||||||||||||||||||||
704 | Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer<QLocalePrivate>, defaultLocalePrivate, | - | ||||||||||||||||||||||||
705 | (QLocalePrivate::create(defaultData(), default_number_options))) | - | ||||||||||||||||||||||||
706 | - | |||||||||||||||||||||||||
707 | static QLocalePrivate *localePrivateByName(const QString &name) | - | ||||||||||||||||||||||||
708 | { | - | ||||||||||||||||||||||||
709 | if (name == QLatin1String("C"))
| 3171-7883 | ||||||||||||||||||||||||
710 | return c_private(); executed 7883 times by 6 tests: return c_private(); Executed by:
| 7883 | ||||||||||||||||||||||||
711 | const QLocaleData *data = findLocaleData(name); | - | ||||||||||||||||||||||||
712 | return QLocalePrivate::create(data, data->m_language_id == QLocale::C ? executed 3170 times by 26 tests: return QLocalePrivate::create(data, data->m_language_id == QLocale::C ? QLocale::OmitGroupSeparator : QLocale::DefaultNumberOptions); Executed by:
| 3170 | ||||||||||||||||||||||||
713 | QLocale::OmitGroupSeparator : 0QLocale::DefaultNumberOptions); executed 3170 times by 26 tests: return QLocalePrivate::create(data, data->m_language_id == QLocale::C ? QLocale::OmitGroupSeparator : QLocale::DefaultNumberOptions); Executed by:
| 3170 | ||||||||||||||||||||||||
714 | } | - | ||||||||||||||||||||||||
715 | - | |||||||||||||||||||||||||
716 | static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Script script, | - | ||||||||||||||||||||||||
717 | QLocale::Country country) | - | ||||||||||||||||||||||||
718 | { | - | ||||||||||||||||||||||||
719 | if (language == QLocale::C)
| 64-131284 | ||||||||||||||||||||||||
720 | return c_private(); executed 131284 times by 117 tests: return c_private(); Executed by:
| 131284 | ||||||||||||||||||||||||
721 | - | |||||||||||||||||||||||||
722 | const QLocaleData *data = QLocaleData::findLocaleData(language, script, country); | - | ||||||||||||||||||||||||
723 | - | |||||||||||||||||||||||||
724 | intQLocale::NumberOptions numberOptions = 0QLocale::DefaultNumberOptions; | - | ||||||||||||||||||||||||
725 | - | |||||||||||||||||||||||||
726 | // If not found, should default to system | - | ||||||||||||||||||||||||
727 | if (data->m_language_id == QLocale::C && language != QLocale::C) {
| 0-64 | ||||||||||||||||||||||||
728 | numberOptions = default_number_options; | - | ||||||||||||||||||||||||
729 | data = defaultData(); | - | ||||||||||||||||||||||||
730 | } never executed: end of block | 0 | ||||||||||||||||||||||||
731 | return QLocalePrivate::create(data, numberOptions); executed 64 times by 12 tests: return QLocalePrivate::create(data, numberOptions); Executed by:
| 64 | ||||||||||||||||||||||||
732 | } | - | ||||||||||||||||||||||||
733 | - | |||||||||||||||||||||||||
734 | - | |||||||||||||||||||||||||
735 | /*! | - | ||||||||||||||||||||||||
736 | \internal | - | ||||||||||||||||||||||||
737 | */ | - | ||||||||||||||||||||||||
738 | QLocale::QLocale(QLocalePrivate &dd) | - | ||||||||||||||||||||||||
739 | : d(&dd) | - | ||||||||||||||||||||||||
740 | {} | - | ||||||||||||||||||||||||
741 | - | |||||||||||||||||||||||||
742 | - | |||||||||||||||||||||||||
743 | /*! | - | ||||||||||||||||||||||||
744 | Constructs a QLocale object with the specified \a name, | - | ||||||||||||||||||||||||
745 | which has the format | - | ||||||||||||||||||||||||
746 | "language[_script][_country][.codeset][@modifier]" or "C", where: | - | ||||||||||||||||||||||||
747 | - | |||||||||||||||||||||||||
748 | \list | - | ||||||||||||||||||||||||
749 | \li language is a lowercase, two-letter, ISO 639 language code (also some three-letter codes), | - | ||||||||||||||||||||||||
750 | \li script is a titlecase, four-letter, ISO 15924 script code, | - | ||||||||||||||||||||||||
751 | \li country is an uppercase, two-letter, ISO 3166 country code (also "419" as defined by United Nations), | - | ||||||||||||||||||||||||
752 | \li and codeset and modifier are ignored. | - | ||||||||||||||||||||||||
753 | \endlist | - | ||||||||||||||||||||||||
754 | - | |||||||||||||||||||||||||
755 | The separator can be either underscore or a minus sign. | - | ||||||||||||||||||||||||
756 | - | |||||||||||||||||||||||||
757 | If the string violates the locale format, or language is not | - | ||||||||||||||||||||||||
758 | a valid ISO 639 code, the "C" locale is used instead. If country | - | ||||||||||||||||||||||||
759 | is not present, or is not a valid ISO 3166 code, the most | - | ||||||||||||||||||||||||
760 | appropriate country is chosen for the specified language. | - | ||||||||||||||||||||||||
761 | - | |||||||||||||||||||||||||
762 | The language, script and country codes are converted to their respective | - | ||||||||||||||||||||||||
763 | \c Language, \c Script and \c Country enums. After this conversion is | - | ||||||||||||||||||||||||
764 | performed, the constructor behaves exactly like QLocale(Country, Script, | - | ||||||||||||||||||||||||
765 | Language). | - | ||||||||||||||||||||||||
766 | - | |||||||||||||||||||||||||
767 | This constructor is much slower than QLocale(Country, Script, Language). | - | ||||||||||||||||||||||||
768 | - | |||||||||||||||||||||||||
769 | \sa bcp47Name() | - | ||||||||||||||||||||||||
770 | */ | - | ||||||||||||||||||||||||
771 | - | |||||||||||||||||||||||||
772 | QLocale::QLocale(const QString &name) | - | ||||||||||||||||||||||||
773 | : d(localePrivateByName(name)) | - | ||||||||||||||||||||||||
774 | { | - | ||||||||||||||||||||||||
775 | } | - | ||||||||||||||||||||||||
776 | - | |||||||||||||||||||||||||
777 | /*! | - | ||||||||||||||||||||||||
778 | Constructs a QLocale object initialized with the default locale. If | - | ||||||||||||||||||||||||
779 | no default locale was set using setDefault(), this locale will | - | ||||||||||||||||||||||||
780 | be the same as the one returned by system(). | - | ||||||||||||||||||||||||
781 | - | |||||||||||||||||||||||||
782 | \sa setDefault() | - | ||||||||||||||||||||||||
783 | */ | - | ||||||||||||||||||||||||
784 | - | |||||||||||||||||||||||||
785 | QLocale::QLocale() | - | ||||||||||||||||||||||||
786 | : d(*defaultLocalePrivate) | - | ||||||||||||||||||||||||
787 | { | - | ||||||||||||||||||||||||
788 | } | - | ||||||||||||||||||||||||
789 | - | |||||||||||||||||||||||||
790 | /*! | - | ||||||||||||||||||||||||
791 | Constructs a QLocale object with the specified \a language and \a | - | ||||||||||||||||||||||||
792 | country. | - | ||||||||||||||||||||||||
793 | - | |||||||||||||||||||||||||
794 | \list | - | ||||||||||||||||||||||||
795 | \li If the language/country pair is found in the database, it is used. | - | ||||||||||||||||||||||||
796 | \li If the language is found but the country is not, or if the country | - | ||||||||||||||||||||||||
797 | is \c AnyCountry, the language is used with the most | - | ||||||||||||||||||||||||
798 | appropriate available country (for example, Germany for German), | - | ||||||||||||||||||||||||
799 | \li If neither the language nor the country are found, QLocale | - | ||||||||||||||||||||||||
800 | defaults to the default locale (see setDefault()). | - | ||||||||||||||||||||||||
801 | \endlist | - | ||||||||||||||||||||||||
802 | - | |||||||||||||||||||||||||
803 | The language and country that are actually used can be queried | - | ||||||||||||||||||||||||
804 | using language() and country(). | - | ||||||||||||||||||||||||
805 | - | |||||||||||||||||||||||||
806 | \sa setDefault(), language(), country() | - | ||||||||||||||||||||||||
807 | */ | - | ||||||||||||||||||||||||
808 | - | |||||||||||||||||||||||||
809 | QLocale::QLocale(Language language, Country country) | - | ||||||||||||||||||||||||
810 | : d(findLocalePrivate(language, QLocale::AnyScript, country)) | - | ||||||||||||||||||||||||
811 | { | - | ||||||||||||||||||||||||
812 | } | - | ||||||||||||||||||||||||
813 | - | |||||||||||||||||||||||||
814 | /*! | - | ||||||||||||||||||||||||
815 | \since 4.8 | - | ||||||||||||||||||||||||
816 | - | |||||||||||||||||||||||||
817 | Constructs a QLocale object with the specified \a language, \a script and | - | ||||||||||||||||||||||||
818 | \a country. | - | ||||||||||||||||||||||||
819 | - | |||||||||||||||||||||||||
820 | \list | - | ||||||||||||||||||||||||
821 | \li If the language/script/country is found in the database, it is used. | - | ||||||||||||||||||||||||
822 | \li If both \a script is AnyScript and \a country is AnyCountry, the | - | ||||||||||||||||||||||||
823 | language is used with the most appropriate available script and country | - | ||||||||||||||||||||||||
824 | (for example, Germany for German), | - | ||||||||||||||||||||||||
825 | \li If either \a script is AnyScript or \a country is AnyCountry, the | - | ||||||||||||||||||||||||
826 | language is used with the first locale that matches the given \a script | - | ||||||||||||||||||||||||
827 | and \a country. | - | ||||||||||||||||||||||||
828 | \li If neither the language nor the country are found, QLocale | - | ||||||||||||||||||||||||
829 | defaults to the default locale (see setDefault()). | - | ||||||||||||||||||||||||
830 | \endlist | - | ||||||||||||||||||||||||
831 | - | |||||||||||||||||||||||||
832 | The language, script and country that are actually used can be queried | - | ||||||||||||||||||||||||
833 | using language(), script() and country(). | - | ||||||||||||||||||||||||
834 | - | |||||||||||||||||||||||||
835 | \sa setDefault(), language(), script(), country() | - | ||||||||||||||||||||||||
836 | */ | - | ||||||||||||||||||||||||
837 | - | |||||||||||||||||||||||||
838 | QLocale::QLocale(Language language, Script script, Country country) | - | ||||||||||||||||||||||||
839 | : d(findLocalePrivate(language, script, country)) | - | ||||||||||||||||||||||||
840 | { | - | ||||||||||||||||||||||||
841 | } | - | ||||||||||||||||||||||||
842 | - | |||||||||||||||||||||||||
843 | /*! | - | ||||||||||||||||||||||||
844 | Constructs a QLocale object as a copy of \a other. | - | ||||||||||||||||||||||||
845 | */ | - | ||||||||||||||||||||||||
846 | - | |||||||||||||||||||||||||
847 | QLocale::QLocale(const QLocale &other) | - | ||||||||||||||||||||||||
848 | { | - | ||||||||||||||||||||||||
849 | d = other.d; | - | ||||||||||||||||||||||||
850 | } | - | ||||||||||||||||||||||||
851 | - | |||||||||||||||||||||||||
852 | /*! | - | ||||||||||||||||||||||||
853 | Destructor | - | ||||||||||||||||||||||||
854 | */ | - | ||||||||||||||||||||||||
855 | - | |||||||||||||||||||||||||
856 | QLocale::~QLocale() | - | ||||||||||||||||||||||||
857 | { | - | ||||||||||||||||||||||||
858 | } | - | ||||||||||||||||||||||||
859 | - | |||||||||||||||||||||||||
860 | /*! | - | ||||||||||||||||||||||||
861 | Assigns \a other to this QLocale object and returns a reference | - | ||||||||||||||||||||||||
862 | to this QLocale object. | - | ||||||||||||||||||||||||
863 | */ | - | ||||||||||||||||||||||||
864 | - | |||||||||||||||||||||||||
865 | QLocale &QLocale::operator=(const QLocale &other) | - | ||||||||||||||||||||||||
866 | { | - | ||||||||||||||||||||||||
867 | d = other.d; | - | ||||||||||||||||||||||||
868 | return *this; | - | ||||||||||||||||||||||||
869 | } | - | ||||||||||||||||||||||||
870 | - | |||||||||||||||||||||||||
871 | bool QLocale::operator==(const QLocale &other) const | - | ||||||||||||||||||||||||
872 | { | - | ||||||||||||||||||||||||
873 | return d->m_data == other.d->m_data && d->m_numberOptions == other.d->m_numberOptions; | - | ||||||||||||||||||||||||
874 | } | - | ||||||||||||||||||||||||
875 | - | |||||||||||||||||||||||||
876 | bool QLocale::operator!=(const QLocale &other) const | - | ||||||||||||||||||||||||
877 | { | - | ||||||||||||||||||||||||
878 | return d->m_data != other.d->m_data || d->m_numberOptions != other.d->m_numberOptions; | - | ||||||||||||||||||||||||
879 | } | - | ||||||||||||||||||||||||
880 | - | |||||||||||||||||||||||||
881 | /*! | - | ||||||||||||||||||||||||
882 | \fn void QLocale::swap(QLocale &other) | - | ||||||||||||||||||||||||
883 | \since 5.6 | - | ||||||||||||||||||||||||
884 | - | |||||||||||||||||||||||||
885 | Swaps locale \a other with this locale. This operation is very fast and | - | ||||||||||||||||||||||||
886 | never fails. | - | ||||||||||||||||||||||||
887 | */ | - | ||||||||||||||||||||||||
888 | - | |||||||||||||||||||||||||
889 | /*! | - | ||||||||||||||||||||||||
890 | \since 5.6 | - | ||||||||||||||||||||||||
891 | \relates QLocale | - | ||||||||||||||||||||||||
892 | - | |||||||||||||||||||||||||
893 | Returns the hash value for \a key, using | - | ||||||||||||||||||||||||
894 | \a seed to seed the calculation. | - | ||||||||||||||||||||||||
895 | */ | - | ||||||||||||||||||||||||
896 | uint qHash(const QLocale &key, uint seed) Q_DECL_NOTHROW | - | ||||||||||||||||||||||||
897 | { | - | ||||||||||||||||||||||||
898 | QtPrivate::QHashCombine hash; | - | ||||||||||||||||||||||||
899 | seed = hash(seed, key.d->m_data); | - | ||||||||||||||||||||||||
900 | seed = hash(seed, key.d->m_numberOptions); | - | ||||||||||||||||||||||||
901 | return seed; never executed: return seed; | 0 | ||||||||||||||||||||||||
902 | } | - | ||||||||||||||||||||||||
903 | - | |||||||||||||||||||||||||
904 | /*! | - | ||||||||||||||||||||||||
905 | \since 4.2 | - | ||||||||||||||||||||||||
906 | - | |||||||||||||||||||||||||
907 | Sets the \a options related to number conversions for this | - | ||||||||||||||||||||||||
908 | QLocale instance. | - | ||||||||||||||||||||||||
909 | */ | - | ||||||||||||||||||||||||
910 | void QLocale::setNumberOptions(NumberOptions options) | - | ||||||||||||||||||||||||
911 | { | - | ||||||||||||||||||||||||
912 | d->m_numberOptions = options; | - | ||||||||||||||||||||||||
913 | } | - | ||||||||||||||||||||||||
914 | - | |||||||||||||||||||||||||
915 | /*! | - | ||||||||||||||||||||||||
916 | \since 4.2 | - | ||||||||||||||||||||||||
917 | - | |||||||||||||||||||||||||
918 | Returns the options related to number conversions for this | - | ||||||||||||||||||||||||
919 | QLocale instance. | - | ||||||||||||||||||||||||
920 | - | |||||||||||||||||||||||||
921 | By default, no options are set for the standard locales. | - | ||||||||||||||||||||||||
922 | */ | - | ||||||||||||||||||||||||
923 | QLocale::NumberOptions QLocale::numberOptions() const | - | ||||||||||||||||||||||||
924 | { | - | ||||||||||||||||||||||||
925 | return static_cast<NumberOptionNumberOptions>(d->m_numberOptions); executed 3878 times by 30 tests: return static_cast<NumberOptions>(d->m_numberOptions); Executed by:
| 3878 | ||||||||||||||||||||||||
926 | } | - | ||||||||||||||||||||||||
927 | - | |||||||||||||||||||||||||
928 | /*! | - | ||||||||||||||||||||||||
929 | \since 4.8 | - | ||||||||||||||||||||||||
930 | - | |||||||||||||||||||||||||
931 | Returns \a str quoted according to the current locale using the given | - | ||||||||||||||||||||||||
932 | quotation \a style. | - | ||||||||||||||||||||||||
933 | */ | - | ||||||||||||||||||||||||
934 | QString QLocale::quoteString(const QString &str, QuotationStyle style) const | - | ||||||||||||||||||||||||
935 | { | - | ||||||||||||||||||||||||
936 | return quoteString(&str, style); | - | ||||||||||||||||||||||||
937 | } | - | ||||||||||||||||||||||||
938 | - | |||||||||||||||||||||||||
939 | /*! | - | ||||||||||||||||||||||||
940 | \since 4.8 | - | ||||||||||||||||||||||||
941 | - | |||||||||||||||||||||||||
942 | \overload | - | ||||||||||||||||||||||||
943 | */ | - | ||||||||||||||||||||||||
944 | QString QLocale::quoteString(const QStringRef &str, QuotationStyle style) const | - | ||||||||||||||||||||||||
945 | { | - | ||||||||||||||||||||||||
946 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
947 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
948 | QVariant res; | - | ||||||||||||||||||||||||
949 | if (style == QLocale::AlternateQuotation) | - | ||||||||||||||||||||||||
950 | res = systemLocale()->query(QSystemLocale::StringToAlternateQuotation, QVariant::fromValue(str)); | - | ||||||||||||||||||||||||
951 | if (res.isNull() || style == QLocale::StandardQuotation) | - | ||||||||||||||||||||||||
952 | res = systemLocale()->query(QSystemLocale::StringToStandardQuotation, QVariant::fromValue(str)); | - | ||||||||||||||||||||||||
953 | if (!res.isNull()) | - | ||||||||||||||||||||||||
954 | return res.toString(); | - | ||||||||||||||||||||||||
955 | } | - | ||||||||||||||||||||||||
956 | #endif | - | ||||||||||||||||||||||||
957 | - | |||||||||||||||||||||||||
958 | if (style == QLocale::StandardQuotation) | - | ||||||||||||||||||||||||
959 | return QChar(d->m_data->m_quotation_start) % str % QChar(d->m_data->m_quotation_end); | - | ||||||||||||||||||||||||
960 | else | - | ||||||||||||||||||||||||
961 | return QChar(d->m_data->m_alternate_quotation_start) % str % QChar(d->m_data->m_alternate_quotation_end); | - | ||||||||||||||||||||||||
962 | } | - | ||||||||||||||||||||||||
963 | - | |||||||||||||||||||||||||
964 | /*! | - | ||||||||||||||||||||||||
965 | \since 4.8 | - | ||||||||||||||||||||||||
966 | - | |||||||||||||||||||||||||
967 | Returns a string that represents a join of a given \a list of strings with | - | ||||||||||||||||||||||||
968 | a separator defined by the locale. | - | ||||||||||||||||||||||||
969 | */ | - | ||||||||||||||||||||||||
970 | QString QLocale::createSeparatedList(const QStringList &list) const | - | ||||||||||||||||||||||||
971 | { | - | ||||||||||||||||||||||||
972 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
973 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
974 | QVariant res; | - | ||||||||||||||||||||||||
975 | res = systemLocale()->query(QSystemLocale::ListToSeparatedString, QVariant::fromValue(list)); | - | ||||||||||||||||||||||||
976 | - | |||||||||||||||||||||||||
977 | if (!res.isNull()) | - | ||||||||||||||||||||||||
978 | return res.toString(); | - | ||||||||||||||||||||||||
979 | } | - | ||||||||||||||||||||||||
980 | #endif | - | ||||||||||||||||||||||||
981 | - | |||||||||||||||||||||||||
982 | const int size = list.size(); | - | ||||||||||||||||||||||||
983 | if (size == 1) { | - | ||||||||||||||||||||||||
984 | return list.at(0); | - | ||||||||||||||||||||||||
985 | } else if (size == 2) { | - | ||||||||||||||||||||||||
986 | QString format = getLocaleData(list_pattern_part_data + d->m_data->m_list_pattern_part_two_idx, d->m_data->m_list_pattern_part_two_size); | - | ||||||||||||||||||||||||
987 | return format.arg(list.at(0), list.at(1)); | - | ||||||||||||||||||||||||
988 | } else if (size > 2) { | - | ||||||||||||||||||||||||
989 | QString formatStart = getLocaleData(list_pattern_part_data + d->m_data->m_list_pattern_part_start_idx, d->m_data->m_list_pattern_part_start_size); | - | ||||||||||||||||||||||||
990 | QString formatMid = getLocaleData(list_pattern_part_data + d->m_data->m_list_pattern_part_mid_idx, d->m_data->m_list_pattern_part_mid_size); | - | ||||||||||||||||||||||||
991 | QString formatEnd = getLocaleData(list_pattern_part_data + d->m_data->m_list_pattern_part_end_idx, d->m_data->m_list_pattern_part_end_size); | - | ||||||||||||||||||||||||
992 | QString result = formatStart.arg(list.at(0), list.at(1)); | - | ||||||||||||||||||||||||
993 | for (int i = 2; i < size - 1; ++i) | - | ||||||||||||||||||||||||
994 | result = formatMid.arg(result, list.at(i)); | - | ||||||||||||||||||||||||
995 | result = formatEnd.arg(result, list.at(size - 1)); | - | ||||||||||||||||||||||||
996 | return result; | - | ||||||||||||||||||||||||
997 | } | - | ||||||||||||||||||||||||
998 | - | |||||||||||||||||||||||||
999 | return QString(); | - | ||||||||||||||||||||||||
1000 | } | - | ||||||||||||||||||||||||
1001 | - | |||||||||||||||||||||||||
1002 | /*! | - | ||||||||||||||||||||||||
1003 | \nonreentrant | - | ||||||||||||||||||||||||
1004 | - | |||||||||||||||||||||||||
1005 | Sets the global default locale to \a locale. These | - | ||||||||||||||||||||||||
1006 | values are used when a QLocale object is constructed with | - | ||||||||||||||||||||||||
1007 | no arguments. If this function is not called, the system's | - | ||||||||||||||||||||||||
1008 | locale is used. | - | ||||||||||||||||||||||||
1009 | - | |||||||||||||||||||||||||
1010 | \warning In a multithreaded application, the default locale | - | ||||||||||||||||||||||||
1011 | should be set at application startup, before any non-GUI threads | - | ||||||||||||||||||||||||
1012 | are created. | - | ||||||||||||||||||||||||
1013 | - | |||||||||||||||||||||||||
1014 | \sa system(), c() | - | ||||||||||||||||||||||||
1015 | */ | - | ||||||||||||||||||||||||
1016 | - | |||||||||||||||||||||||||
1017 | void QLocale::setDefault(const QLocale &locale) | - | ||||||||||||||||||||||||
1018 | { | - | ||||||||||||||||||||||||
1019 | default_data = locale.d->m_data; | - | ||||||||||||||||||||||||
1020 | default_number_options = locale.numberOptions(); | - | ||||||||||||||||||||||||
1021 | - | |||||||||||||||||||||||||
1022 | if (defaultLocalePrivate.exists()) { | - | ||||||||||||||||||||||||
1023 | // update the cached private | - | ||||||||||||||||||||||||
1024 | *defaultLocalePrivate = locale.d; | - | ||||||||||||||||||||||||
1025 | } | - | ||||||||||||||||||||||||
1026 | } | - | ||||||||||||||||||||||||
1027 | - | |||||||||||||||||||||||||
1028 | /*! | - | ||||||||||||||||||||||||
1029 | Returns the language of this locale. | - | ||||||||||||||||||||||||
1030 | - | |||||||||||||||||||||||||
1031 | \sa script(), country(), languageToString(), bcp47Name() | - | ||||||||||||||||||||||||
1032 | */ | - | ||||||||||||||||||||||||
1033 | QLocale::Language QLocale::language() const | - | ||||||||||||||||||||||||
1034 | { | - | ||||||||||||||||||||||||
1035 | return Language(d->languageId()); | - | ||||||||||||||||||||||||
1036 | } | - | ||||||||||||||||||||||||
1037 | - | |||||||||||||||||||||||||
1038 | /*! | - | ||||||||||||||||||||||||
1039 | \since 4.8 | - | ||||||||||||||||||||||||
1040 | - | |||||||||||||||||||||||||
1041 | Returns the script of this locale. | - | ||||||||||||||||||||||||
1042 | - | |||||||||||||||||||||||||
1043 | \sa language(), country(), languageToString(), scriptToString(), bcp47Name() | - | ||||||||||||||||||||||||
1044 | */ | - | ||||||||||||||||||||||||
1045 | QLocale::Script QLocale::script() const | - | ||||||||||||||||||||||||
1046 | { | - | ||||||||||||||||||||||||
1047 | return Script(d->m_data->m_script_id); | - | ||||||||||||||||||||||||
1048 | } | - | ||||||||||||||||||||||||
1049 | - | |||||||||||||||||||||||||
1050 | /*! | - | ||||||||||||||||||||||||
1051 | Returns the country of this locale. | - | ||||||||||||||||||||||||
1052 | - | |||||||||||||||||||||||||
1053 | \sa language(), script(), countryToString(), bcp47Name() | - | ||||||||||||||||||||||||
1054 | */ | - | ||||||||||||||||||||||||
1055 | QLocale::Country QLocale::country() const | - | ||||||||||||||||||||||||
1056 | { | - | ||||||||||||||||||||||||
1057 | return Country(d->countryId()); | - | ||||||||||||||||||||||||
1058 | } | - | ||||||||||||||||||||||||
1059 | - | |||||||||||||||||||||||||
1060 | /*! | - | ||||||||||||||||||||||||
1061 | Returns the language and country of this locale as a | - | ||||||||||||||||||||||||
1062 | string of the form "language_country", where | - | ||||||||||||||||||||||||
1063 | language is a lowercase, two-letter ISO 639 language code, | - | ||||||||||||||||||||||||
1064 | and country is an uppercase, two- or three-letter ISO 3166 country code. | - | ||||||||||||||||||||||||
1065 | - | |||||||||||||||||||||||||
1066 | Note that even if QLocale object was constructed with an explicit script, | - | ||||||||||||||||||||||||
1067 | name() will not contain it for compatibility reasons. Use bcp47Name() instead | - | ||||||||||||||||||||||||
1068 | if you need a full locale name. | - | ||||||||||||||||||||||||
1069 | - | |||||||||||||||||||||||||
1070 | \sa QLocale(), language(), script(), country(), bcp47Name() | - | ||||||||||||||||||||||||
1071 | */ | - | ||||||||||||||||||||||||
1072 | - | |||||||||||||||||||||||||
1073 | QString QLocale::name() const | - | ||||||||||||||||||||||||
1074 | { | - | ||||||||||||||||||||||||
1075 | Language l = language(); | - | ||||||||||||||||||||||||
1076 | - | |||||||||||||||||||||||||
1077 | QString result = d->languageCode(); | - | ||||||||||||||||||||||||
1078 | - | |||||||||||||||||||||||||
1079 | if (l == C) | - | ||||||||||||||||||||||||
1080 | return result; | - | ||||||||||||||||||||||||
1081 | - | |||||||||||||||||||||||||
1082 | Country c = country(); | - | ||||||||||||||||||||||||
1083 | if (c == AnyCountry) | - | ||||||||||||||||||||||||
1084 | return result; | - | ||||||||||||||||||||||||
1085 | - | |||||||||||||||||||||||||
1086 | result.append(QLatin1Char('_')); | - | ||||||||||||||||||||||||
1087 | result.append(d->countryCode()); | - | ||||||||||||||||||||||||
1088 | - | |||||||||||||||||||||||||
1089 | return result; | - | ||||||||||||||||||||||||
1090 | } | - | ||||||||||||||||||||||||
1091 | - | |||||||||||||||||||||||||
1092 | static qlonglong toIntegral_helper(const QLocaleData *d, const QChar *data, int len, bool *ok, | - | ||||||||||||||||||||||||
1093 | QLocaleDataQLocale::GroupSeparatorModeNumberOptions mode, qlonglong) | - | ||||||||||||||||||||||||
1094 | { | - | ||||||||||||||||||||||||
1095 | return d->stringToLongLong(data, len, 10, ok, mode); executed 1226 times by 16 tests: return d->stringToLongLong(data, len, 10, ok, mode); Executed by:
| 1226 | ||||||||||||||||||||||||
1096 | } | - | ||||||||||||||||||||||||
1097 | - | |||||||||||||||||||||||||
1098 | static qulonglong toIntegral_helper(const QLocaleData *d, const QChar *data, int len, bool *ok, | - | ||||||||||||||||||||||||
1099 | QLocaleDataQLocale::GroupSeparatorModeNumberOptions mode, qulonglong) | - | ||||||||||||||||||||||||
1100 | { | - | ||||||||||||||||||||||||
1101 | return d->stringToUnsLongLong(data, len, 10, ok, mode); executed 15675 times by 11 tests: return d->stringToUnsLongLong(data, len, 10, ok, mode); Executed by:
| 15675 | ||||||||||||||||||||||||
1102 | } | - | ||||||||||||||||||||||||
1103 | - | |||||||||||||||||||||||||
1104 | template <typename T> static inline | - | ||||||||||||||||||||||||
1105 | T toIntegral_helper(const QLocalePrivate *d, const QChar *data, int len, bool *ok) | - | ||||||||||||||||||||||||
1106 | { | - | ||||||||||||||||||||||||
1107 | // ### Qt6: use std::conditional<std::is_unsigned<T>::value, qulonglong, qlonglong>::type | - | ||||||||||||||||||||||||
1108 | const bool isUnsigned = T(0) < T(-1); | - | ||||||||||||||||||||||||
1109 | typedef typename QtPrivate::QConditional<isUnsigned, qulonglong, qlonglong>::Type Int64; | - | ||||||||||||||||||||||||
QLocaleData::GroupSeparatorMode mode | ||||||||||||||||||||||||||
= d->m_numberOptions & QLocale::RejectGroupSeparator | ||||||||||||||||||||||||||
? QLocaleData::FailOnGroupSeparators | ||||||||||||||||||||||||||
: QLocaleData::ParseGroupSeparators; | ||||||||||||||||||||||||||
1110 | - | |||||||||||||||||||||||||
1111 | // we select the right overload by the last, unused parameter | - | ||||||||||||||||||||||||
1112 | Int64 val = toIntegral_helper(d->m_data, data, len, ok, moded->m_numberOptions, Int64()); | - | ||||||||||||||||||||||||
1113 | if (T(val) != val) {
| 0-16901 | ||||||||||||||||||||||||
1114 | if (ok)
| 0 | ||||||||||||||||||||||||
1115 | *ok = false; never executed: *ok = false; | 0 | ||||||||||||||||||||||||
1116 | val = 0; | - | ||||||||||||||||||||||||
1117 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1118 | return T(val); executed 16901 times by 23 tests: return T(val); Executed by:
| 16901 | ||||||||||||||||||||||||
1119 | } | - | ||||||||||||||||||||||||
1120 | - | |||||||||||||||||||||||||
1121 | - | |||||||||||||||||||||||||
1122 | /*! | - | ||||||||||||||||||||||||
1123 | \since 4.8 | - | ||||||||||||||||||||||||
1124 | - | |||||||||||||||||||||||||
1125 | Returns the dash-separated language, script and country (and possibly other BCP47 fields) | - | ||||||||||||||||||||||||
1126 | of this locale as a string. | - | ||||||||||||||||||||||||
1127 | - | |||||||||||||||||||||||||
1128 | Unlike the uiLanguages() the returned value of the bcp47Name() represents | - | ||||||||||||||||||||||||
1129 | the locale name of the QLocale data but not the language the user-interface | - | ||||||||||||||||||||||||
1130 | should be in. | - | ||||||||||||||||||||||||
1131 | - | |||||||||||||||||||||||||
1132 | This function tries to conform the locale name to BCP47. | - | ||||||||||||||||||||||||
1133 | - | |||||||||||||||||||||||||
1134 | \sa language(), country(), script(), uiLanguages() | - | ||||||||||||||||||||||||
1135 | */ | - | ||||||||||||||||||||||||
1136 | QString QLocale::bcp47Name() const | - | ||||||||||||||||||||||||
1137 | { | - | ||||||||||||||||||||||||
1138 | return QString::fromLatin1(d->bcp47Name()); | - | ||||||||||||||||||||||||
1139 | } | - | ||||||||||||||||||||||||
1140 | - | |||||||||||||||||||||||||
1141 | /*! | - | ||||||||||||||||||||||||
1142 | Returns a QString containing the name of \a language. | - | ||||||||||||||||||||||||
1143 | - | |||||||||||||||||||||||||
1144 | \sa countryToString(), scriptToString(), bcp47Name() | - | ||||||||||||||||||||||||
1145 | */ | - | ||||||||||||||||||||||||
1146 | - | |||||||||||||||||||||||||
1147 | QString QLocale::languageToString(Language language) | - | ||||||||||||||||||||||||
1148 | { | - | ||||||||||||||||||||||||
1149 | if (uint(language) > uint(QLocale::LastLanguage)) | - | ||||||||||||||||||||||||
1150 | return QLatin1String("Unknown"); | - | ||||||||||||||||||||||||
1151 | return QLatin1String(language_name_list + language_name_index[language]); | - | ||||||||||||||||||||||||
1152 | } | - | ||||||||||||||||||||||||
1153 | - | |||||||||||||||||||||||||
1154 | /*! | - | ||||||||||||||||||||||||
1155 | Returns a QString containing the name of \a country. | - | ||||||||||||||||||||||||
1156 | - | |||||||||||||||||||||||||
1157 | \sa languageToString(), scriptToString(), country(), bcp47Name() | - | ||||||||||||||||||||||||
1158 | */ | - | ||||||||||||||||||||||||
1159 | - | |||||||||||||||||||||||||
1160 | QString QLocale::countryToString(Country country) | - | ||||||||||||||||||||||||
1161 | { | - | ||||||||||||||||||||||||
1162 | if (uint(country) > uint(QLocale::LastCountry)) | - | ||||||||||||||||||||||||
1163 | return QLatin1String("Unknown"); | - | ||||||||||||||||||||||||
1164 | return QLatin1String(country_name_list + country_name_index[country]); | - | ||||||||||||||||||||||||
1165 | } | - | ||||||||||||||||||||||||
1166 | - | |||||||||||||||||||||||||
1167 | /*! | - | ||||||||||||||||||||||||
1168 | \since 4.8 | - | ||||||||||||||||||||||||
1169 | - | |||||||||||||||||||||||||
1170 | Returns a QString containing the name of \a script. | - | ||||||||||||||||||||||||
1171 | - | |||||||||||||||||||||||||
1172 | \sa languageToString(), countryToString(), script(), bcp47Name() | - | ||||||||||||||||||||||||
1173 | */ | - | ||||||||||||||||||||||||
1174 | QString QLocale::scriptToString(QLocale::Script script) | - | ||||||||||||||||||||||||
1175 | { | - | ||||||||||||||||||||||||
1176 | if (uint(script) > uint(QLocale::LastScript)) | - | ||||||||||||||||||||||||
1177 | return QLatin1String("Unknown"); | - | ||||||||||||||||||||||||
1178 | return QLatin1String(script_name_list + script_name_index[script]); | - | ||||||||||||||||||||||||
1179 | } | - | ||||||||||||||||||||||||
1180 | - | |||||||||||||||||||||||||
1181 | /*! | - | ||||||||||||||||||||||||
1182 | Returns the short int represented by the localized string \a s. | - | ||||||||||||||||||||||||
1183 | - | |||||||||||||||||||||||||
1184 | If the conversion fails the function returns 0. | - | ||||||||||||||||||||||||
1185 | - | |||||||||||||||||||||||||
1186 | If \a ok is not 0, failure is reported by setting *ok to false, and | - | ||||||||||||||||||||||||
1187 | success by setting *ok to true. | - | ||||||||||||||||||||||||
1188 | - | |||||||||||||||||||||||||
1189 | This function ignores leading and trailing whitespace. | - | ||||||||||||||||||||||||
1190 | - | |||||||||||||||||||||||||
1191 | \sa toUShort(), toString() | - | ||||||||||||||||||||||||
1192 | */ | - | ||||||||||||||||||||||||
1193 | - | |||||||||||||||||||||||||
1194 | short QLocale::toShort(const QString &s, bool *ok) const | - | ||||||||||||||||||||||||
1195 | { | - | ||||||||||||||||||||||||
1196 | return toIntegral_helper<short>(d, s.constData(), s.size(), ok); | - | ||||||||||||||||||||||||
1197 | } | - | ||||||||||||||||||||||||
1198 | - | |||||||||||||||||||||||||
1199 | /*! | - | ||||||||||||||||||||||||
1200 | Returns the unsigned short int represented by the localized string \a s. | - | ||||||||||||||||||||||||
1201 | - | |||||||||||||||||||||||||
1202 | If the conversion fails the function returns 0. | - | ||||||||||||||||||||||||
1203 | - | |||||||||||||||||||||||||
1204 | If \a ok is not 0, failure is reported by setting *ok to false, and | - | ||||||||||||||||||||||||
1205 | success by setting *ok to true. | - | ||||||||||||||||||||||||
1206 | - | |||||||||||||||||||||||||
1207 | This function ignores leading and trailing whitespace. | - | ||||||||||||||||||||||||
1208 | - | |||||||||||||||||||||||||
1209 | \sa toShort(), toString() | - | ||||||||||||||||||||||||
1210 | */ | - | ||||||||||||||||||||||||
1211 | - | |||||||||||||||||||||||||
1212 | ushort QLocale::toUShort(const QString &s, bool *ok) const | - | ||||||||||||||||||||||||
1213 | { | - | ||||||||||||||||||||||||
1214 | return toIntegral_helper<ushort>(d, s.constData(), s.size(), ok); | - | ||||||||||||||||||||||||
1215 | } | - | ||||||||||||||||||||||||
1216 | - | |||||||||||||||||||||||||
1217 | /*! | - | ||||||||||||||||||||||||
1218 | Returns the int represented by the localized string \a s. | - | ||||||||||||||||||||||||
1219 | - | |||||||||||||||||||||||||
1220 | If the conversion fails the function returns 0. | - | ||||||||||||||||||||||||
1221 | - | |||||||||||||||||||||||||
1222 | If \a ok is not 0, failure is reported by setting *ok to false, and | - | ||||||||||||||||||||||||
1223 | success by setting *ok to true. | - | ||||||||||||||||||||||||
1224 | - | |||||||||||||||||||||||||
1225 | This function ignores leading and trailing whitespace. | - | ||||||||||||||||||||||||
1226 | - | |||||||||||||||||||||||||
1227 | \sa toUInt(), toString() | - | ||||||||||||||||||||||||
1228 | */ | - | ||||||||||||||||||||||||
1229 | - | |||||||||||||||||||||||||
1230 | int QLocale::toInt(const QString &s, bool *ok) const | - | ||||||||||||||||||||||||
1231 | { | - | ||||||||||||||||||||||||
1232 | return toIntegral_helper<int>(d, s.constData(), s.size(), ok); | - | ||||||||||||||||||||||||
1233 | } | - | ||||||||||||||||||||||||
1234 | - | |||||||||||||||||||||||||
1235 | /*! | - | ||||||||||||||||||||||||
1236 | Returns the unsigned int represented by the localized string \a s. | - | ||||||||||||||||||||||||
1237 | - | |||||||||||||||||||||||||
1238 | If the conversion fails the function returns 0. | - | ||||||||||||||||||||||||
1239 | - | |||||||||||||||||||||||||
1240 | If \a ok is not 0, failure is reported by setting *ok to false, and | - | ||||||||||||||||||||||||
1241 | success by setting *ok to true. | - | ||||||||||||||||||||||||
1242 | - | |||||||||||||||||||||||||
1243 | This function ignores leading and trailing whitespace. | - | ||||||||||||||||||||||||
1244 | - | |||||||||||||||||||||||||
1245 | \sa toInt(), toString() | - | ||||||||||||||||||||||||
1246 | */ | - | ||||||||||||||||||||||||
1247 | - | |||||||||||||||||||||||||
1248 | uint QLocale::toUInt(const QString &s, bool *ok) const | - | ||||||||||||||||||||||||
1249 | { | - | ||||||||||||||||||||||||
1250 | return toIntegral_helper<uint>(d, s.constData(), s.size(), ok); | - | ||||||||||||||||||||||||
1251 | } | - | ||||||||||||||||||||||||
1252 | - | |||||||||||||||||||||||||
1253 | /*! | - | ||||||||||||||||||||||||
1254 | Returns the long long int represented by the localized string \a s. | - | ||||||||||||||||||||||||
1255 | - | |||||||||||||||||||||||||
1256 | If the conversion fails the function returns 0. | - | ||||||||||||||||||||||||
1257 | - | |||||||||||||||||||||||||
1258 | If \a ok is not 0, failure is reported by setting *ok to false, and | - | ||||||||||||||||||||||||
1259 | success by setting *ok to true. | - | ||||||||||||||||||||||||
1260 | - | |||||||||||||||||||||||||
1261 | This function ignores leading and trailing whitespace. | - | ||||||||||||||||||||||||
1262 | - | |||||||||||||||||||||||||
1263 | \sa toInt(), toULongLong(), toDouble(), toString() | - | ||||||||||||||||||||||||
1264 | */ | - | ||||||||||||||||||||||||
1265 | - | |||||||||||||||||||||||||
1266 | - | |||||||||||||||||||||||||
1267 | qlonglong QLocale::toLongLong(const QString &s, bool *ok) const | - | ||||||||||||||||||||||||
1268 | { | - | ||||||||||||||||||||||||
1269 | return toIntegral_helper<qlonglong>(d, s.constData(), s.size(), ok); | - | ||||||||||||||||||||||||
1270 | } | - | ||||||||||||||||||||||||
1271 | - | |||||||||||||||||||||||||
1272 | /*! | - | ||||||||||||||||||||||||
1273 | Returns the unsigned long long int represented by the localized | - | ||||||||||||||||||||||||
1274 | string \a s. | - | ||||||||||||||||||||||||
1275 | - | |||||||||||||||||||||||||
1276 | If the conversion fails the function returns 0. | - | ||||||||||||||||||||||||
1277 | - | |||||||||||||||||||||||||
1278 | If \a ok is not 0, failure is reported by setting *ok to false, and | - | ||||||||||||||||||||||||
1279 | success by setting *ok to true. | - | ||||||||||||||||||||||||
1280 | - | |||||||||||||||||||||||||
1281 | This function ignores leading and trailing whitespace. | - | ||||||||||||||||||||||||
1282 | - | |||||||||||||||||||||||||
1283 | \sa toLongLong(), toInt(), toDouble(), toString() | - | ||||||||||||||||||||||||
1284 | */ | - | ||||||||||||||||||||||||
1285 | - | |||||||||||||||||||||||||
1286 | qulonglong QLocale::toULongLong(const QString &s, bool *ok) const | - | ||||||||||||||||||||||||
1287 | { | - | ||||||||||||||||||||||||
1288 | return toIntegral_helper<qulonglong>(d, s.constData(), s.size(), ok); | - | ||||||||||||||||||||||||
1289 | } | - | ||||||||||||||||||||||||
1290 | - | |||||||||||||||||||||||||
1291 | /*! | - | ||||||||||||||||||||||||
1292 | Returns the float represented by the localized string \a s, or 0.0 | - | ||||||||||||||||||||||||
1293 | if the conversion failed. | - | ||||||||||||||||||||||||
1294 | - | |||||||||||||||||||||||||
1295 | If \a ok is not 0, reports failure by setting | - | ||||||||||||||||||||||||
1296 | *ok to false and success by setting *ok to true. | - | ||||||||||||||||||||||||
1297 | - | |||||||||||||||||||||||||
1298 | This function ignores leading and trailing whitespace. | - | ||||||||||||||||||||||||
1299 | - | |||||||||||||||||||||||||
1300 | \sa toDouble(), toInt(), toString() | - | ||||||||||||||||||||||||
1301 | */ | - | ||||||||||||||||||||||||
1302 | - | |||||||||||||||||||||||||
1303 | float QLocale::toFloat(const QString &s, bool *ok) const | - | ||||||||||||||||||||||||
1304 | { | - | ||||||||||||||||||||||||
1305 | return QLocaleData::convertDoubleToFloat(toDouble(s, ok), ok); | - | ||||||||||||||||||||||||
1306 | } | - | ||||||||||||||||||||||||
1307 | - | |||||||||||||||||||||||||
1308 | /*! | - | ||||||||||||||||||||||||
1309 | Returns the double represented by the localized string \a s, or | - | ||||||||||||||||||||||||
1310 | 0.0 if the conversion failed. | - | ||||||||||||||||||||||||
1311 | - | |||||||||||||||||||||||||
1312 | If \a ok is not 0, reports failure by setting | - | ||||||||||||||||||||||||
1313 | *ok to false and success by setting *ok to true. | - | ||||||||||||||||||||||||
1314 | - | |||||||||||||||||||||||||
1315 | Unlike QString::toDouble(), this function does not fall back to | - | ||||||||||||||||||||||||
1316 | the "C" locale if the string cannot be interpreted in this | - | ||||||||||||||||||||||||
1317 | locale. | - | ||||||||||||||||||||||||
1318 | - | |||||||||||||||||||||||||
1319 | \snippet code/src_corelib_tools_qlocale.cpp 3 | - | ||||||||||||||||||||||||
1320 | - | |||||||||||||||||||||||||
1321 | Notice that the last conversion returns 1234.0, because '.' is the | - | ||||||||||||||||||||||||
1322 | thousands group separator in the German locale. | - | ||||||||||||||||||||||||
1323 | - | |||||||||||||||||||||||||
1324 | This function ignores leading and trailing whitespace. | - | ||||||||||||||||||||||||
1325 | - | |||||||||||||||||||||||||
1326 | \sa toFloat(), toInt(), toString() | - | ||||||||||||||||||||||||
1327 | */ | - | ||||||||||||||||||||||||
1328 | - | |||||||||||||||||||||||||
1329 | double QLocale::toDouble(const QString &s, bool *ok) const | - | ||||||||||||||||||||||||
1330 | { | - | ||||||||||||||||||||||||
1331 | QLocaleData::GroupSeparatorMode mode executed 1212 times by 7 tests: return d->m_data->stringToDouble(s.constData(), s.size(), ok, d->m_numberOptions); Executed by:
| 1212 | ||||||||||||||||||||||||
= d->m_numberOptions & RejectGroupSeparator executed 1212 times by 7 tests: return d->m_data->stringToDouble(s.constData(), s.size(), ok, d->m_numberOptions); Executed by:
| ||||||||||||||||||||||||||
? QLocaleData::FailOnGroupSeparators executed 1212 times by 7 tests: return d->m_data->stringToDouble(s.constData(), s.size(), ok, d->m_numberOptions); Executed by:
| ||||||||||||||||||||||||||
: QLocaleData::ParseGroupSeparators; executed 1212 times by 7 tests: return d->m_data->stringToDouble(s.constData(), s.size(), ok, moded->m_numberOptions);return d->m_data->stringToDouble(s.constData(), s.size(), ok, d->m_numberOptions); Executed by:
executed 1212 times by 7 tests: return d->m_data->stringToDouble(s.constData(), s.size(), ok, d->m_numberOptions); Executed by:
| ||||||||||||||||||||||||||
1332 | } | - | ||||||||||||||||||||||||
1333 | - | |||||||||||||||||||||||||
1334 | /*! | - | ||||||||||||||||||||||||
1335 | Returns the short int represented by the localized string \a s. | - | ||||||||||||||||||||||||
1336 | - | |||||||||||||||||||||||||
1337 | If the conversion fails the function returns 0. | - | ||||||||||||||||||||||||
1338 | - | |||||||||||||||||||||||||
1339 | If \a ok is not null, failure is reported by setting *ok to false, and | - | ||||||||||||||||||||||||
1340 | success by setting *ok to true. | - | ||||||||||||||||||||||||
1341 | - | |||||||||||||||||||||||||
1342 | This function ignores leading and trailing whitespace. | - | ||||||||||||||||||||||||
1343 | - | |||||||||||||||||||||||||
1344 | \sa toUShort(), toString() | - | ||||||||||||||||||||||||
1345 | - | |||||||||||||||||||||||||
1346 | \since 5.1 | - | ||||||||||||||||||||||||
1347 | */ | - | ||||||||||||||||||||||||
1348 | - | |||||||||||||||||||||||||
1349 | short QLocale::toShort(const QStringRef &s, bool *ok) const | - | ||||||||||||||||||||||||
1350 | { | - | ||||||||||||||||||||||||
1351 | return toIntegral_helper<short>(d, s.constData(), s.size(), ok); | - | ||||||||||||||||||||||||
1352 | } | - | ||||||||||||||||||||||||
1353 | - | |||||||||||||||||||||||||
1354 | /*! | - | ||||||||||||||||||||||||
1355 | Returns the unsigned short int represented by the localized string \a s. | - | ||||||||||||||||||||||||
1356 | - | |||||||||||||||||||||||||
1357 | If the conversion fails the function returns 0. | - | ||||||||||||||||||||||||
1358 | - | |||||||||||||||||||||||||
1359 | If \a ok is not null, failure is reported by setting *ok to false, and | - | ||||||||||||||||||||||||
1360 | success by setting *ok to true. | - | ||||||||||||||||||||||||
1361 | - | |||||||||||||||||||||||||
1362 | This function ignores leading and trailing whitespace. | - | ||||||||||||||||||||||||
1363 | - | |||||||||||||||||||||||||
1364 | \sa toShort(), toString() | - | ||||||||||||||||||||||||
1365 | - | |||||||||||||||||||||||||
1366 | \since 5.1 | - | ||||||||||||||||||||||||
1367 | */ | - | ||||||||||||||||||||||||
1368 | - | |||||||||||||||||||||||||
1369 | ushort QLocale::toUShort(const QStringRef &s, bool *ok) const | - | ||||||||||||||||||||||||
1370 | { | - | ||||||||||||||||||||||||
1371 | return toIntegral_helper<ushort>(d, s.constData(), s.size(), ok); | - | ||||||||||||||||||||||||
1372 | } | - | ||||||||||||||||||||||||
1373 | - | |||||||||||||||||||||||||
1374 | /*! | - | ||||||||||||||||||||||||
1375 | Returns the int represented by the localized string \a s. | - | ||||||||||||||||||||||||
1376 | - | |||||||||||||||||||||||||
1377 | If the conversion fails the function returns 0. | - | ||||||||||||||||||||||||
1378 | - | |||||||||||||||||||||||||
1379 | If \a ok is not null, failure is reported by setting *ok to false, and | - | ||||||||||||||||||||||||
1380 | success by setting *ok to true. | - | ||||||||||||||||||||||||
1381 | - | |||||||||||||||||||||||||
1382 | This function ignores leading and trailing whitespace. | - | ||||||||||||||||||||||||
1383 | - | |||||||||||||||||||||||||
1384 | \sa toUInt(), toString() | - | ||||||||||||||||||||||||
1385 | - | |||||||||||||||||||||||||
1386 | \since 5.1 | - | ||||||||||||||||||||||||
1387 | */ | - | ||||||||||||||||||||||||
1388 | - | |||||||||||||||||||||||||
1389 | int QLocale::toInt(const QStringRef &s, bool *ok) const | - | ||||||||||||||||||||||||
1390 | { | - | ||||||||||||||||||||||||
1391 | return toIntegral_helper<int>(d, s.constData(), s.size(), ok); | - | ||||||||||||||||||||||||
1392 | } | - | ||||||||||||||||||||||||
1393 | - | |||||||||||||||||||||||||
1394 | /*! | - | ||||||||||||||||||||||||
1395 | Returns the unsigned int represented by the localized string \a s. | - | ||||||||||||||||||||||||
1396 | - | |||||||||||||||||||||||||
1397 | If the conversion fails the function returns 0. | - | ||||||||||||||||||||||||
1398 | - | |||||||||||||||||||||||||
1399 | If \a ok is not null, failure is reported by setting *ok to false, and | - | ||||||||||||||||||||||||
1400 | success by setting *ok to true. | - | ||||||||||||||||||||||||
1401 | - | |||||||||||||||||||||||||
1402 | This function ignores leading and trailing whitespace. | - | ||||||||||||||||||||||||
1403 | - | |||||||||||||||||||||||||
1404 | \sa toInt(), toString() | - | ||||||||||||||||||||||||
1405 | - | |||||||||||||||||||||||||
1406 | \since 5.1 | - | ||||||||||||||||||||||||
1407 | */ | - | ||||||||||||||||||||||||
1408 | - | |||||||||||||||||||||||||
1409 | uint QLocale::toUInt(const QStringRef &s, bool *ok) const | - | ||||||||||||||||||||||||
1410 | { | - | ||||||||||||||||||||||||
1411 | return toIntegral_helper<uint>(d, s.constData(), s.size(), ok); | - | ||||||||||||||||||||||||
1412 | } | - | ||||||||||||||||||||||||
1413 | - | |||||||||||||||||||||||||
1414 | /*! | - | ||||||||||||||||||||||||
1415 | Returns the long long int represented by the localized string \a s. | - | ||||||||||||||||||||||||
1416 | - | |||||||||||||||||||||||||
1417 | If the conversion fails the function returns 0. | - | ||||||||||||||||||||||||
1418 | - | |||||||||||||||||||||||||
1419 | If \a ok is not null, failure is reported by setting *ok to false, and | - | ||||||||||||||||||||||||
1420 | success by setting *ok to true. | - | ||||||||||||||||||||||||
1421 | - | |||||||||||||||||||||||||
1422 | This function ignores leading and trailing whitespace. | - | ||||||||||||||||||||||||
1423 | - | |||||||||||||||||||||||||
1424 | \sa toInt(), toULongLong(), toDouble(), toString() | - | ||||||||||||||||||||||||
1425 | - | |||||||||||||||||||||||||
1426 | \since 5.1 | - | ||||||||||||||||||||||||
1427 | */ | - | ||||||||||||||||||||||||
1428 | - | |||||||||||||||||||||||||
1429 | - | |||||||||||||||||||||||||
1430 | qlonglong QLocale::toLongLong(const QStringRef &s, bool *ok) const | - | ||||||||||||||||||||||||
1431 | { | - | ||||||||||||||||||||||||
1432 | return toIntegral_helper<qlonglong>(d, s.constData(), s.size(), ok); | - | ||||||||||||||||||||||||
1433 | } | - | ||||||||||||||||||||||||
1434 | - | |||||||||||||||||||||||||
1435 | /*! | - | ||||||||||||||||||||||||
1436 | Returns the unsigned long long int represented by the localized | - | ||||||||||||||||||||||||
1437 | string \a s. | - | ||||||||||||||||||||||||
1438 | - | |||||||||||||||||||||||||
1439 | If the conversion fails the function returns 0. | - | ||||||||||||||||||||||||
1440 | - | |||||||||||||||||||||||||
1441 | If \a ok is not null, failure is reported by setting *ok to false, and | - | ||||||||||||||||||||||||
1442 | success by setting *ok to true. | - | ||||||||||||||||||||||||
1443 | - | |||||||||||||||||||||||||
1444 | This function ignores leading and trailing whitespace. | - | ||||||||||||||||||||||||
1445 | - | |||||||||||||||||||||||||
1446 | \sa toLongLong(), toInt(), toDouble(), toString() | - | ||||||||||||||||||||||||
1447 | - | |||||||||||||||||||||||||
1448 | \since 5.1 | - | ||||||||||||||||||||||||
1449 | */ | - | ||||||||||||||||||||||||
1450 | - | |||||||||||||||||||||||||
1451 | qulonglong QLocale::toULongLong(const QStringRef &s, bool *ok) const | - | ||||||||||||||||||||||||
1452 | { | - | ||||||||||||||||||||||||
1453 | return toIntegral_helper<qulonglong>(d, s.constData(), s.size(), ok); | - | ||||||||||||||||||||||||
1454 | } | - | ||||||||||||||||||||||||
1455 | - | |||||||||||||||||||||||||
1456 | /*! | - | ||||||||||||||||||||||||
1457 | Returns the float represented by the localized string \a s, or 0.0 | - | ||||||||||||||||||||||||
1458 | if the conversion failed. | - | ||||||||||||||||||||||||
1459 | - | |||||||||||||||||||||||||
1460 | If \a ok is not null, reports failure by setting | - | ||||||||||||||||||||||||
1461 | *ok to false and success by setting *ok to true. | - | ||||||||||||||||||||||||
1462 | - | |||||||||||||||||||||||||
1463 | This function ignores leading and trailing whitespace. | - | ||||||||||||||||||||||||
1464 | - | |||||||||||||||||||||||||
1465 | \sa toDouble(), toInt(), toString() | - | ||||||||||||||||||||||||
1466 | - | |||||||||||||||||||||||||
1467 | \since 5.1 | - | ||||||||||||||||||||||||
1468 | */ | - | ||||||||||||||||||||||||
1469 | - | |||||||||||||||||||||||||
1470 | float QLocale::toFloat(const QStringRef &s, bool *ok) const | - | ||||||||||||||||||||||||
1471 | { | - | ||||||||||||||||||||||||
1472 | return QLocaleData::convertDoubleToFloat(toDouble(s, ok), ok); | - | ||||||||||||||||||||||||
1473 | } | - | ||||||||||||||||||||||||
1474 | - | |||||||||||||||||||||||||
1475 | /*! | - | ||||||||||||||||||||||||
1476 | Returns the double represented by the localized string \a s, or | - | ||||||||||||||||||||||||
1477 | 0.0 if the conversion failed. | - | ||||||||||||||||||||||||
1478 | - | |||||||||||||||||||||||||
1479 | If \a ok is not null, reports failure by setting | - | ||||||||||||||||||||||||
1480 | *ok to false and success by setting *ok to true. | - | ||||||||||||||||||||||||
1481 | - | |||||||||||||||||||||||||
1482 | Unlike QString::toDouble(), this function does not fall back to | - | ||||||||||||||||||||||||
1483 | the "C" locale if the string cannot be interpreted in this | - | ||||||||||||||||||||||||
1484 | locale. | - | ||||||||||||||||||||||||
1485 | - | |||||||||||||||||||||||||
1486 | \snippet code/src_corelib_tools_qlocale.cpp 3 | - | ||||||||||||||||||||||||
1487 | - | |||||||||||||||||||||||||
1488 | Notice that the last conversion returns 1234.0, because '.' is the | - | ||||||||||||||||||||||||
1489 | thousands group separator in the German locale. | - | ||||||||||||||||||||||||
1490 | - | |||||||||||||||||||||||||
1491 | This function ignores leading and trailing whitespace. | - | ||||||||||||||||||||||||
1492 | - | |||||||||||||||||||||||||
1493 | \sa toFloat(), toInt(), toString() | - | ||||||||||||||||||||||||
1494 | - | |||||||||||||||||||||||||
1495 | \since 5.1 | - | ||||||||||||||||||||||||
1496 | */ | - | ||||||||||||||||||||||||
1497 | - | |||||||||||||||||||||||||
1498 | double QLocale::toDouble(const QStringRef &s, bool *ok) const | - | ||||||||||||||||||||||||
1499 | { | - | ||||||||||||||||||||||||
1500 | QLocaleData::GroupSeparatorMode mode never executed: return d->m_data->stringToDouble(s.constData(), s.size(), ok, d->m_numberOptions); | 0 | ||||||||||||||||||||||||
= d->m_numberOptions & RejectGroupSeparator never executed: return d->m_data->stringToDouble(s.constData(), s.size(), ok, d->m_numberOptions); | ||||||||||||||||||||||||||
? QLocaleData::FailOnGroupSeparators never executed: return d->m_data->stringToDouble(s.constData(), s.size(), ok, d->m_numberOptions); | ||||||||||||||||||||||||||
: QLocaleData::ParseGroupSeparators; never executed: return d->m_data->stringToDouble(s.constData(), s.size(), ok, moded->m_numberOptions);return d->m_data->stringToDouble(s.constData(), s.size(), ok, d->m_numberOptions); never executed: return d->m_data->stringToDouble(s.constData(), s.size(), ok, d->m_numberOptions); | ||||||||||||||||||||||||||
1501 | } | - | ||||||||||||||||||||||||
1502 | - | |||||||||||||||||||||||||
1503 | - | |||||||||||||||||||||||||
1504 | /*! | - | ||||||||||||||||||||||||
1505 | Returns a localized string representation of \a i. | - | ||||||||||||||||||||||||
1506 | - | |||||||||||||||||||||||||
1507 | \sa toLongLong() | - | ||||||||||||||||||||||||
1508 | */ | - | ||||||||||||||||||||||||
1509 | - | |||||||||||||||||||||||||
1510 | QString QLocale::toString(qlonglong i) const | - | ||||||||||||||||||||||||
1511 | { | - | ||||||||||||||||||||||||
1512 | int flags = d->m_numberOptions & OmitGroupSeparator | - | ||||||||||||||||||||||||
1513 | ? 0 | - | ||||||||||||||||||||||||
1514 | : QLocaleData::ThousandsGroup; | - | ||||||||||||||||||||||||
1515 | - | |||||||||||||||||||||||||
1516 | return d->m_data->longLongToString(i, -1, 10, -1, flags); | - | ||||||||||||||||||||||||
1517 | } | - | ||||||||||||||||||||||||
1518 | - | |||||||||||||||||||||||||
1519 | /*! | - | ||||||||||||||||||||||||
1520 | \overload | - | ||||||||||||||||||||||||
1521 | - | |||||||||||||||||||||||||
1522 | \sa toULongLong() | - | ||||||||||||||||||||||||
1523 | */ | - | ||||||||||||||||||||||||
1524 | - | |||||||||||||||||||||||||
1525 | QString QLocale::toString(qulonglong i) const | - | ||||||||||||||||||||||||
1526 | { | - | ||||||||||||||||||||||||
1527 | int flags = d->m_numberOptions & OmitGroupSeparator | - | ||||||||||||||||||||||||
1528 | ? 0 | - | ||||||||||||||||||||||||
1529 | : QLocaleData::ThousandsGroup; | - | ||||||||||||||||||||||||
1530 | - | |||||||||||||||||||||||||
1531 | return d->m_data->unsLongLongToString(i, -1, 10, -1, flags); | - | ||||||||||||||||||||||||
1532 | } | - | ||||||||||||||||||||||||
1533 | - | |||||||||||||||||||||||||
1534 | /*! | - | ||||||||||||||||||||||||
1535 | Returns a localized string representation of the given \a date in the | - | ||||||||||||||||||||||||
1536 | specified \a format. | - | ||||||||||||||||||||||||
1537 | If \a format is an empty string, an empty string is returned. | - | ||||||||||||||||||||||||
1538 | */ | - | ||||||||||||||||||||||||
1539 | - | |||||||||||||||||||||||||
1540 | QString QLocale::toString(const QDate &date, const QString &format) const | - | ||||||||||||||||||||||||
1541 | { | - | ||||||||||||||||||||||||
1542 | return d->dateTimeToString(format, QDateTime(), date, QTime(), this); | - | ||||||||||||||||||||||||
1543 | } | - | ||||||||||||||||||||||||
1544 | - | |||||||||||||||||||||||||
1545 | /*! | - | ||||||||||||||||||||||||
1546 | Returns a localized string representation of the given \a date according | - | ||||||||||||||||||||||||
1547 | to the specified \a format. | - | ||||||||||||||||||||||||
1548 | */ | - | ||||||||||||||||||||||||
1549 | - | |||||||||||||||||||||||||
1550 | QString QLocale::toString(const QDate &date, FormatType format) const | - | ||||||||||||||||||||||||
1551 | { | - | ||||||||||||||||||||||||
1552 | if (!date.isValid()) | - | ||||||||||||||||||||||||
1553 | return QString(); | - | ||||||||||||||||||||||||
1554 | - | |||||||||||||||||||||||||
1555 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
1556 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
1557 | QVariant res = systemLocale()->query(format == LongFormat | - | ||||||||||||||||||||||||
1558 | ? QSystemLocale::DateToStringLong : QSystemLocale::DateToStringShort, | - | ||||||||||||||||||||||||
1559 | date); | - | ||||||||||||||||||||||||
1560 | if (!res.isNull()) | - | ||||||||||||||||||||||||
1561 | return res.toString(); | - | ||||||||||||||||||||||||
1562 | } | - | ||||||||||||||||||||||||
1563 | #endif | - | ||||||||||||||||||||||||
1564 | - | |||||||||||||||||||||||||
1565 | QString format_str = dateFormat(format); | - | ||||||||||||||||||||||||
1566 | return toString(date, format_str); | - | ||||||||||||||||||||||||
1567 | } | - | ||||||||||||||||||||||||
1568 | - | |||||||||||||||||||||||||
1569 | static bool timeFormatContainsAP(const QString &format) | - | ||||||||||||||||||||||||
1570 | { | - | ||||||||||||||||||||||||
1571 | int i = 0; | - | ||||||||||||||||||||||||
1572 | while (i < format.size()) { | - | ||||||||||||||||||||||||
1573 | if (format.at(i).unicode() == '\'') { | - | ||||||||||||||||||||||||
1574 | qt_readEscapedFormatString(format, &i); | - | ||||||||||||||||||||||||
1575 | continue; | - | ||||||||||||||||||||||||
1576 | } | - | ||||||||||||||||||||||||
1577 | - | |||||||||||||||||||||||||
1578 | if (format.at(i).toLower().unicode() == 'a') | - | ||||||||||||||||||||||||
1579 | return true; | - | ||||||||||||||||||||||||
1580 | - | |||||||||||||||||||||||||
1581 | ++i; | - | ||||||||||||||||||||||||
1582 | } | - | ||||||||||||||||||||||||
1583 | return false; | - | ||||||||||||||||||||||||
1584 | } | - | ||||||||||||||||||||||||
1585 | - | |||||||||||||||||||||||||
1586 | /*! | - | ||||||||||||||||||||||||
1587 | Returns a localized string representation of the given \a time according | - | ||||||||||||||||||||||||
1588 | to the specified \a format. | - | ||||||||||||||||||||||||
1589 | If \a format is an empty string, an empty string is returned. | - | ||||||||||||||||||||||||
1590 | */ | - | ||||||||||||||||||||||||
1591 | QString QLocale::toString(const QTime &time, const QString &format) const | - | ||||||||||||||||||||||||
1592 | { | - | ||||||||||||||||||||||||
1593 | return d->dateTimeToString(format, QDateTime(), QDate(), time, this); | - | ||||||||||||||||||||||||
1594 | } | - | ||||||||||||||||||||||||
1595 | - | |||||||||||||||||||||||||
1596 | /*! | - | ||||||||||||||||||||||||
1597 | \since 4.4 | - | ||||||||||||||||||||||||
1598 | - | |||||||||||||||||||||||||
1599 | Returns a localized string representation of the given \a dateTime according | - | ||||||||||||||||||||||||
1600 | to the specified \a format. | - | ||||||||||||||||||||||||
1601 | If \a format is an empty string, an empty string is returned. | - | ||||||||||||||||||||||||
1602 | */ | - | ||||||||||||||||||||||||
1603 | - | |||||||||||||||||||||||||
1604 | QString QLocale::toString(const QDateTime &dateTime, const QString &format) const | - | ||||||||||||||||||||||||
1605 | { | - | ||||||||||||||||||||||||
1606 | return d->dateTimeToString(format, dateTime, QDate(), QTime(), this); | - | ||||||||||||||||||||||||
1607 | } | - | ||||||||||||||||||||||||
1608 | - | |||||||||||||||||||||||||
1609 | /*! | - | ||||||||||||||||||||||||
1610 | \since 4.4 | - | ||||||||||||||||||||||||
1611 | - | |||||||||||||||||||||||||
1612 | Returns a localized string representation of the given \a dateTime according | - | ||||||||||||||||||||||||
1613 | to the specified \a format. | - | ||||||||||||||||||||||||
1614 | */ | - | ||||||||||||||||||||||||
1615 | - | |||||||||||||||||||||||||
1616 | QString QLocale::toString(const QDateTime &dateTime, FormatType format) const | - | ||||||||||||||||||||||||
1617 | { | - | ||||||||||||||||||||||||
1618 | if (!dateTime.isValid()) | - | ||||||||||||||||||||||||
1619 | return QString(); | - | ||||||||||||||||||||||||
1620 | - | |||||||||||||||||||||||||
1621 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
1622 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
1623 | QVariant res = systemLocale()->query(format == LongFormat | - | ||||||||||||||||||||||||
1624 | ? QSystemLocale::DateTimeToStringLong | - | ||||||||||||||||||||||||
1625 | : QSystemLocale::DateTimeToStringShort, | - | ||||||||||||||||||||||||
1626 | dateTime); | - | ||||||||||||||||||||||||
1627 | if (!res.isNull()) | - | ||||||||||||||||||||||||
1628 | return res.toString(); | - | ||||||||||||||||||||||||
1629 | } | - | ||||||||||||||||||||||||
1630 | #endif | - | ||||||||||||||||||||||||
1631 | - | |||||||||||||||||||||||||
1632 | const QString format_str = dateTimeFormat(format); | - | ||||||||||||||||||||||||
1633 | return toString(dateTime, format_str); | - | ||||||||||||||||||||||||
1634 | } | - | ||||||||||||||||||||||||
1635 | - | |||||||||||||||||||||||||
1636 | - | |||||||||||||||||||||||||
1637 | /*! | - | ||||||||||||||||||||||||
1638 | Returns a localized string representation of the given \a time in the | - | ||||||||||||||||||||||||
1639 | specified \a format. | - | ||||||||||||||||||||||||
1640 | */ | - | ||||||||||||||||||||||||
1641 | - | |||||||||||||||||||||||||
1642 | QString QLocale::toString(const QTime &time, FormatType format) const | - | ||||||||||||||||||||||||
1643 | { | - | ||||||||||||||||||||||||
1644 | if (!time.isValid()) | - | ||||||||||||||||||||||||
1645 | return QString(); | - | ||||||||||||||||||||||||
1646 | - | |||||||||||||||||||||||||
1647 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
1648 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
1649 | QVariant res = systemLocale()->query(format == LongFormat | - | ||||||||||||||||||||||||
1650 | ? QSystemLocale::TimeToStringLong : QSystemLocale::TimeToStringShort, | - | ||||||||||||||||||||||||
1651 | time); | - | ||||||||||||||||||||||||
1652 | if (!res.isNull()) | - | ||||||||||||||||||||||||
1653 | return res.toString(); | - | ||||||||||||||||||||||||
1654 | } | - | ||||||||||||||||||||||||
1655 | #endif | - | ||||||||||||||||||||||||
1656 | - | |||||||||||||||||||||||||
1657 | QString format_str = timeFormat(format); | - | ||||||||||||||||||||||||
1658 | return toString(time, format_str); | - | ||||||||||||||||||||||||
1659 | } | - | ||||||||||||||||||||||||
1660 | - | |||||||||||||||||||||||||
1661 | /*! | - | ||||||||||||||||||||||||
1662 | \since 4.1 | - | ||||||||||||||||||||||||
1663 | - | |||||||||||||||||||||||||
1664 | Returns the date format used for the current locale. | - | ||||||||||||||||||||||||
1665 | - | |||||||||||||||||||||||||
1666 | If \a format is LongFormat the format will be a long version. | - | ||||||||||||||||||||||||
1667 | Otherwise it uses a shorter version. | - | ||||||||||||||||||||||||
1668 | - | |||||||||||||||||||||||||
1669 | \sa QDate::toString(), QDate::fromString() | - | ||||||||||||||||||||||||
1670 | */ | - | ||||||||||||||||||||||||
1671 | - | |||||||||||||||||||||||||
1672 | QString QLocale::dateFormat(FormatType format) const | - | ||||||||||||||||||||||||
1673 | { | - | ||||||||||||||||||||||||
1674 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
1675 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
1676 | QVariant res = systemLocale()->query(format == LongFormat | - | ||||||||||||||||||||||||
1677 | ? QSystemLocale::DateFormatLong : QSystemLocale::DateFormatShort, | - | ||||||||||||||||||||||||
1678 | QVariant()); | - | ||||||||||||||||||||||||
1679 | if (!res.isNull()) | - | ||||||||||||||||||||||||
1680 | return res.toString(); | - | ||||||||||||||||||||||||
1681 | } | - | ||||||||||||||||||||||||
1682 | #endif | - | ||||||||||||||||||||||||
1683 | - | |||||||||||||||||||||||||
1684 | quint32 idx, size; | - | ||||||||||||||||||||||||
1685 | switch (format) { | - | ||||||||||||||||||||||||
1686 | case LongFormat: | - | ||||||||||||||||||||||||
1687 | idx = d->m_data->m_long_date_format_idx; | - | ||||||||||||||||||||||||
1688 | size = d->m_data->m_long_date_format_size; | - | ||||||||||||||||||||||||
1689 | break; | - | ||||||||||||||||||||||||
1690 | default: | - | ||||||||||||||||||||||||
1691 | idx = d->m_data->m_short_date_format_idx; | - | ||||||||||||||||||||||||
1692 | size = d->m_data->m_short_date_format_size; | - | ||||||||||||||||||||||||
1693 | break; | - | ||||||||||||||||||||||||
1694 | } | - | ||||||||||||||||||||||||
1695 | return getLocaleData(date_format_data + idx, size); | - | ||||||||||||||||||||||||
1696 | } | - | ||||||||||||||||||||||||
1697 | - | |||||||||||||||||||||||||
1698 | /*! | - | ||||||||||||||||||||||||
1699 | \since 4.1 | - | ||||||||||||||||||||||||
1700 | - | |||||||||||||||||||||||||
1701 | Returns the time format used for the current locale. | - | ||||||||||||||||||||||||
1702 | - | |||||||||||||||||||||||||
1703 | If \a format is LongFormat the format will be a long version. | - | ||||||||||||||||||||||||
1704 | Otherwise it uses a shorter version. | - | ||||||||||||||||||||||||
1705 | - | |||||||||||||||||||||||||
1706 | \sa QTime::toString(), QTime::fromString() | - | ||||||||||||||||||||||||
1707 | */ | - | ||||||||||||||||||||||||
1708 | - | |||||||||||||||||||||||||
1709 | QString QLocale::timeFormat(FormatType format) const | - | ||||||||||||||||||||||||
1710 | { | - | ||||||||||||||||||||||||
1711 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
1712 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
1713 | QVariant res = systemLocale()->query(format == LongFormat | - | ||||||||||||||||||||||||
1714 | ? QSystemLocale::TimeFormatLong : QSystemLocale::TimeFormatShort, | - | ||||||||||||||||||||||||
1715 | QVariant()); | - | ||||||||||||||||||||||||
1716 | if (!res.isNull()) | - | ||||||||||||||||||||||||
1717 | return res.toString(); | - | ||||||||||||||||||||||||
1718 | } | - | ||||||||||||||||||||||||
1719 | #endif | - | ||||||||||||||||||||||||
1720 | - | |||||||||||||||||||||||||
1721 | quint32 idx, size; | - | ||||||||||||||||||||||||
1722 | switch (format) { | - | ||||||||||||||||||||||||
1723 | case LongFormat: | - | ||||||||||||||||||||||||
1724 | idx = d->m_data->m_long_time_format_idx; | - | ||||||||||||||||||||||||
1725 | size = d->m_data->m_long_time_format_size; | - | ||||||||||||||||||||||||
1726 | break; | - | ||||||||||||||||||||||||
1727 | default: | - | ||||||||||||||||||||||||
1728 | idx = d->m_data->m_short_time_format_idx; | - | ||||||||||||||||||||||||
1729 | size = d->m_data->m_short_time_format_size; | - | ||||||||||||||||||||||||
1730 | break; | - | ||||||||||||||||||||||||
1731 | } | - | ||||||||||||||||||||||||
1732 | return getLocaleData(time_format_data + idx, size); | - | ||||||||||||||||||||||||
1733 | } | - | ||||||||||||||||||||||||
1734 | - | |||||||||||||||||||||||||
1735 | /*! | - | ||||||||||||||||||||||||
1736 | \since 4.4 | - | ||||||||||||||||||||||||
1737 | - | |||||||||||||||||||||||||
1738 | Returns the date time format used for the current locale. | - | ||||||||||||||||||||||||
1739 | - | |||||||||||||||||||||||||
1740 | If \a format is ShortFormat the format will be a short version. | - | ||||||||||||||||||||||||
1741 | Otherwise it uses a longer version. | - | ||||||||||||||||||||||||
1742 | - | |||||||||||||||||||||||||
1743 | \sa QDateTime::toString(), QDateTime::fromString() | - | ||||||||||||||||||||||||
1744 | */ | - | ||||||||||||||||||||||||
1745 | - | |||||||||||||||||||||||||
1746 | QString QLocale::dateTimeFormat(FormatType format) const | - | ||||||||||||||||||||||||
1747 | { | - | ||||||||||||||||||||||||
1748 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
1749 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
1750 | QVariant res = systemLocale()->query(format == LongFormat | - | ||||||||||||||||||||||||
1751 | ? QSystemLocale::DateTimeFormatLong | - | ||||||||||||||||||||||||
1752 | : QSystemLocale::DateTimeFormatShort, | - | ||||||||||||||||||||||||
1753 | QVariant()); | - | ||||||||||||||||||||||||
1754 | if (!res.isNull()) { | - | ||||||||||||||||||||||||
1755 | return res.toString(); | - | ||||||||||||||||||||||||
1756 | } | - | ||||||||||||||||||||||||
1757 | } | - | ||||||||||||||||||||||||
1758 | #endif | - | ||||||||||||||||||||||||
1759 | return dateFormat(format) + QLatin1Char(' ') + timeFormat(format); | - | ||||||||||||||||||||||||
1760 | } | - | ||||||||||||||||||||||||
1761 | - | |||||||||||||||||||||||||
1762 | /*! | - | ||||||||||||||||||||||||
1763 | \since 4.4 | - | ||||||||||||||||||||||||
1764 | - | |||||||||||||||||||||||||
1765 | Parses the time string given in \a string and returns the | - | ||||||||||||||||||||||||
1766 | time. The format of the time string is chosen according to the | - | ||||||||||||||||||||||||
1767 | \a format parameter (see timeFormat()). | - | ||||||||||||||||||||||||
1768 | - | |||||||||||||||||||||||||
1769 | If the time could not be parsed, returns an invalid time. | - | ||||||||||||||||||||||||
1770 | - | |||||||||||||||||||||||||
1771 | \sa timeFormat(), toDate(), toDateTime(), QTime::fromString() | - | ||||||||||||||||||||||||
1772 | */ | - | ||||||||||||||||||||||||
1773 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||||||||
1774 | QTime QLocale::toTime(const QString &string, FormatType format) const | - | ||||||||||||||||||||||||
1775 | { | - | ||||||||||||||||||||||||
1776 | return toTime(string, timeFormat(format)); | - | ||||||||||||||||||||||||
1777 | } | - | ||||||||||||||||||||||||
1778 | #endif | - | ||||||||||||||||||||||||
1779 | - | |||||||||||||||||||||||||
1780 | /*! | - | ||||||||||||||||||||||||
1781 | \since 4.4 | - | ||||||||||||||||||||||||
1782 | - | |||||||||||||||||||||||||
1783 | Parses the date string given in \a string and returns the | - | ||||||||||||||||||||||||
1784 | date. The format of the date string is chosen according to the | - | ||||||||||||||||||||||||
1785 | \a format parameter (see dateFormat()). | - | ||||||||||||||||||||||||
1786 | - | |||||||||||||||||||||||||
1787 | If the date could not be parsed, returns an invalid date. | - | ||||||||||||||||||||||||
1788 | - | |||||||||||||||||||||||||
1789 | \sa dateFormat(), toTime(), toDateTime(), QDate::fromString() | - | ||||||||||||||||||||||||
1790 | */ | - | ||||||||||||||||||||||||
1791 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||||||||
1792 | QDate QLocale::toDate(const QString &string, FormatType format) const | - | ||||||||||||||||||||||||
1793 | { | - | ||||||||||||||||||||||||
1794 | return toDate(string, dateFormat(format)); | - | ||||||||||||||||||||||||
1795 | } | - | ||||||||||||||||||||||||
1796 | #endif | - | ||||||||||||||||||||||||
1797 | - | |||||||||||||||||||||||||
1798 | /*! | - | ||||||||||||||||||||||||
1799 | \since 4.4 | - | ||||||||||||||||||||||||
1800 | - | |||||||||||||||||||||||||
1801 | Parses the date/time string given in \a string and returns the | - | ||||||||||||||||||||||||
1802 | time. The format of the date/time string is chosen according to the | - | ||||||||||||||||||||||||
1803 | \a format parameter (see dateTimeFormat()). | - | ||||||||||||||||||||||||
1804 | - | |||||||||||||||||||||||||
1805 | If the string could not be parsed, returns an invalid QDateTime. | - | ||||||||||||||||||||||||
1806 | - | |||||||||||||||||||||||||
1807 | \sa dateTimeFormat(), toTime(), toDate(), QDateTime::fromString() | - | ||||||||||||||||||||||||
1808 | */ | - | ||||||||||||||||||||||||
1809 | - | |||||||||||||||||||||||||
1810 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||||||||
1811 | QDateTime QLocale::toDateTime(const QString &string, FormatType format) const | - | ||||||||||||||||||||||||
1812 | { | - | ||||||||||||||||||||||||
1813 | return toDateTime(string, dateTimeFormat(format)); | - | ||||||||||||||||||||||||
1814 | } | - | ||||||||||||||||||||||||
1815 | #endif | - | ||||||||||||||||||||||||
1816 | - | |||||||||||||||||||||||||
1817 | /*! | - | ||||||||||||||||||||||||
1818 | \since 4.4 | - | ||||||||||||||||||||||||
1819 | - | |||||||||||||||||||||||||
1820 | Parses the time string given in \a string and returns the | - | ||||||||||||||||||||||||
1821 | time. See QTime::fromString() for information on what is a valid | - | ||||||||||||||||||||||||
1822 | format string. | - | ||||||||||||||||||||||||
1823 | - | |||||||||||||||||||||||||
1824 | If the time could not be parsed, returns an invalid time. | - | ||||||||||||||||||||||||
1825 | - | |||||||||||||||||||||||||
1826 | \sa timeFormat(), toDate(), toDateTime(), QTime::fromString() | - | ||||||||||||||||||||||||
1827 | */ | - | ||||||||||||||||||||||||
1828 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||||||||
1829 | QTime QLocale::toTime(const QString &string, const QString &format) const | - | ||||||||||||||||||||||||
1830 | { | - | ||||||||||||||||||||||||
1831 | QTime time; | - | ||||||||||||||||||||||||
1832 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
1833 | QDateTimeParser dt(QVariant::Time, QDateTimeParser::FromString); | - | ||||||||||||||||||||||||
1834 | dt.setDefaultLocale(*this); | - | ||||||||||||||||||||||||
1835 | if (dt.parseFormat(format)) | - | ||||||||||||||||||||||||
1836 | dt.fromString(string, 0, &time); | - | ||||||||||||||||||||||||
1837 | #else | - | ||||||||||||||||||||||||
1838 | Q_UNUSED(string); | - | ||||||||||||||||||||||||
1839 | Q_UNUSED(format); | - | ||||||||||||||||||||||||
1840 | #endif | - | ||||||||||||||||||||||||
1841 | return time; | - | ||||||||||||||||||||||||
1842 | } | - | ||||||||||||||||||||||||
1843 | #endif | - | ||||||||||||||||||||||||
1844 | - | |||||||||||||||||||||||||
1845 | /*! | - | ||||||||||||||||||||||||
1846 | \since 4.4 | - | ||||||||||||||||||||||||
1847 | - | |||||||||||||||||||||||||
1848 | Parses the date string given in \a string and returns the | - | ||||||||||||||||||||||||
1849 | date. See QDate::fromString() for information on the expressions | - | ||||||||||||||||||||||||
1850 | that can be used with this function. | - | ||||||||||||||||||||||||
1851 | - | |||||||||||||||||||||||||
1852 | This function searches month names and the names of the days of | - | ||||||||||||||||||||||||
1853 | the week in the current locale. | - | ||||||||||||||||||||||||
1854 | - | |||||||||||||||||||||||||
1855 | If the date could not be parsed, returns an invalid date. | - | ||||||||||||||||||||||||
1856 | - | |||||||||||||||||||||||||
1857 | \sa dateFormat(), toTime(), toDateTime(), QDate::fromString() | - | ||||||||||||||||||||||||
1858 | */ | - | ||||||||||||||||||||||||
1859 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||||||||
1860 | QDate QLocale::toDate(const QString &string, const QString &format) const | - | ||||||||||||||||||||||||
1861 | { | - | ||||||||||||||||||||||||
1862 | QDate date; | - | ||||||||||||||||||||||||
1863 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
1864 | QDateTimeParser dt(QVariant::Date, QDateTimeParser::FromString); | - | ||||||||||||||||||||||||
1865 | dt.setDefaultLocale(*this); | - | ||||||||||||||||||||||||
1866 | if (dt.parseFormat(format)) | - | ||||||||||||||||||||||||
1867 | dt.fromString(string, &date, 0); | - | ||||||||||||||||||||||||
1868 | #else | - | ||||||||||||||||||||||||
1869 | Q_UNUSED(string); | - | ||||||||||||||||||||||||
1870 | Q_UNUSED(format); | - | ||||||||||||||||||||||||
1871 | #endif | - | ||||||||||||||||||||||||
1872 | return date; | - | ||||||||||||||||||||||||
1873 | } | - | ||||||||||||||||||||||||
1874 | #endif | - | ||||||||||||||||||||||||
1875 | - | |||||||||||||||||||||||||
1876 | /*! | - | ||||||||||||||||||||||||
1877 | \since 4.4 | - | ||||||||||||||||||||||||
1878 | - | |||||||||||||||||||||||||
1879 | Parses the date/time string given in \a string and returns the | - | ||||||||||||||||||||||||
1880 | time. See QDateTime::fromString() for information on the expressions | - | ||||||||||||||||||||||||
1881 | that can be used with this function. | - | ||||||||||||||||||||||||
1882 | - | |||||||||||||||||||||||||
1883 | \note The month and day names used must be given in the user's local | - | ||||||||||||||||||||||||
1884 | language. | - | ||||||||||||||||||||||||
1885 | - | |||||||||||||||||||||||||
1886 | If the string could not be parsed, returns an invalid QDateTime. | - | ||||||||||||||||||||||||
1887 | - | |||||||||||||||||||||||||
1888 | \sa dateTimeFormat(), toTime(), toDate(), QDateTime::fromString() | - | ||||||||||||||||||||||||
1889 | */ | - | ||||||||||||||||||||||||
1890 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||||||||
1891 | QDateTime QLocale::toDateTime(const QString &string, const QString &format) const | - | ||||||||||||||||||||||||
1892 | { | - | ||||||||||||||||||||||||
1893 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
1894 | QTime time; | - | ||||||||||||||||||||||||
1895 | QDate date; | - | ||||||||||||||||||||||||
1896 | - | |||||||||||||||||||||||||
1897 | QDateTimeParser dt(QVariant::DateTime, QDateTimeParser::FromString); | - | ||||||||||||||||||||||||
1898 | dt.setDefaultLocale(*this); | - | ||||||||||||||||||||||||
1899 | if (dt.parseFormat(format) && dt.fromString(string, &date, &time)) | - | ||||||||||||||||||||||||
1900 | return QDateTime(date, time); | - | ||||||||||||||||||||||||
1901 | #else | - | ||||||||||||||||||||||||
1902 | Q_UNUSED(string); | - | ||||||||||||||||||||||||
1903 | Q_UNUSED(format); | - | ||||||||||||||||||||||||
1904 | #endif | - | ||||||||||||||||||||||||
1905 | return QDateTime(QDate(), QTime(-1, -1, -1)); | - | ||||||||||||||||||||||||
1906 | } | - | ||||||||||||||||||||||||
1907 | #endif | - | ||||||||||||||||||||||||
1908 | - | |||||||||||||||||||||||||
1909 | - | |||||||||||||||||||||||||
1910 | /*! | - | ||||||||||||||||||||||||
1911 | \since 4.1 | - | ||||||||||||||||||||||||
1912 | - | |||||||||||||||||||||||||
1913 | Returns the decimal point character of this locale. | - | ||||||||||||||||||||||||
1914 | */ | - | ||||||||||||||||||||||||
1915 | QChar QLocale::decimalPoint() const | - | ||||||||||||||||||||||||
1916 | { | - | ||||||||||||||||||||||||
1917 | return d->decimal(); | - | ||||||||||||||||||||||||
1918 | } | - | ||||||||||||||||||||||||
1919 | - | |||||||||||||||||||||||||
1920 | /*! | - | ||||||||||||||||||||||||
1921 | \since 4.1 | - | ||||||||||||||||||||||||
1922 | - | |||||||||||||||||||||||||
1923 | Returns the group separator character of this locale. | - | ||||||||||||||||||||||||
1924 | */ | - | ||||||||||||||||||||||||
1925 | QChar QLocale::groupSeparator() const | - | ||||||||||||||||||||||||
1926 | { | - | ||||||||||||||||||||||||
1927 | return d->group(); | - | ||||||||||||||||||||||||
1928 | } | - | ||||||||||||||||||||||||
1929 | - | |||||||||||||||||||||||||
1930 | /*! | - | ||||||||||||||||||||||||
1931 | \since 4.1 | - | ||||||||||||||||||||||||
1932 | - | |||||||||||||||||||||||||
1933 | Returns the percent character of this locale. | - | ||||||||||||||||||||||||
1934 | */ | - | ||||||||||||||||||||||||
1935 | QChar QLocale::percent() const | - | ||||||||||||||||||||||||
1936 | { | - | ||||||||||||||||||||||||
1937 | return d->percent(); | - | ||||||||||||||||||||||||
1938 | } | - | ||||||||||||||||||||||||
1939 | - | |||||||||||||||||||||||||
1940 | /*! | - | ||||||||||||||||||||||||
1941 | \since 4.1 | - | ||||||||||||||||||||||||
1942 | - | |||||||||||||||||||||||||
1943 | Returns the zero digit character of this locale. | - | ||||||||||||||||||||||||
1944 | */ | - | ||||||||||||||||||||||||
1945 | QChar QLocale::zeroDigit() const | - | ||||||||||||||||||||||||
1946 | { | - | ||||||||||||||||||||||||
1947 | return d->zero(); | - | ||||||||||||||||||||||||
1948 | } | - | ||||||||||||||||||||||||
1949 | - | |||||||||||||||||||||||||
1950 | /*! | - | ||||||||||||||||||||||||
1951 | \since 4.1 | - | ||||||||||||||||||||||||
1952 | - | |||||||||||||||||||||||||
1953 | Returns the negative sign character of this locale. | - | ||||||||||||||||||||||||
1954 | */ | - | ||||||||||||||||||||||||
1955 | QChar QLocale::negativeSign() const | - | ||||||||||||||||||||||||
1956 | { | - | ||||||||||||||||||||||||
1957 | return d->minus(); | - | ||||||||||||||||||||||||
1958 | } | - | ||||||||||||||||||||||||
1959 | - | |||||||||||||||||||||||||
1960 | /*! | - | ||||||||||||||||||||||||
1961 | \since 4.5 | - | ||||||||||||||||||||||||
1962 | - | |||||||||||||||||||||||||
1963 | Returns the positive sign character of this locale. | - | ||||||||||||||||||||||||
1964 | */ | - | ||||||||||||||||||||||||
1965 | QChar QLocale::positiveSign() const | - | ||||||||||||||||||||||||
1966 | { | - | ||||||||||||||||||||||||
1967 | return d->plus(); | - | ||||||||||||||||||||||||
1968 | } | - | ||||||||||||||||||||||||
1969 | - | |||||||||||||||||||||||||
1970 | /*! | - | ||||||||||||||||||||||||
1971 | \since 4.1 | - | ||||||||||||||||||||||||
1972 | - | |||||||||||||||||||||||||
1973 | Returns the exponential character of this locale. | - | ||||||||||||||||||||||||
1974 | */ | - | ||||||||||||||||||||||||
1975 | QChar QLocale::exponential() const | - | ||||||||||||||||||||||||
1976 | { | - | ||||||||||||||||||||||||
1977 | return d->exponential(); | - | ||||||||||||||||||||||||
1978 | } | - | ||||||||||||||||||||||||
1979 | - | |||||||||||||||||||||||||
1980 | static bool qIsUpper(char c) | - | ||||||||||||||||||||||||
1981 | { | - | ||||||||||||||||||||||||
1982 | return c >= 'A' && c <= 'Z'; | - | ||||||||||||||||||||||||
1983 | } | - | ||||||||||||||||||||||||
1984 | - | |||||||||||||||||||||||||
1985 | static char qToLower(char c) | - | ||||||||||||||||||||||||
1986 | { | - | ||||||||||||||||||||||||
1987 | if (c >= 'A' && c <= 'Z') | - | ||||||||||||||||||||||||
1988 | return c - 'A' + 'a'; | - | ||||||||||||||||||||||||
1989 | else | - | ||||||||||||||||||||||||
1990 | return c; | - | ||||||||||||||||||||||||
1991 | } | - | ||||||||||||||||||||||||
1992 | - | |||||||||||||||||||||||||
1993 | /*! | - | ||||||||||||||||||||||||
1994 | \overload | - | ||||||||||||||||||||||||
1995 | - | |||||||||||||||||||||||||
1996 | \a f and \a prec have the same meaning as in QString::number(double, char, int). | - | ||||||||||||||||||||||||
1997 | - | |||||||||||||||||||||||||
1998 | \sa toDouble() | - | ||||||||||||||||||||||||
1999 | */ | - | ||||||||||||||||||||||||
2000 | - | |||||||||||||||||||||||||
2001 | QString QLocale::toString(double i, char f, int prec) const | - | ||||||||||||||||||||||||
2002 | { | - | ||||||||||||||||||||||||
2003 | QLocaleData::DoubleForm form = QLocaleData::DFDecimal; | - | ||||||||||||||||||||||||
2004 | uint flags = 0; | - | ||||||||||||||||||||||||
2005 | - | |||||||||||||||||||||||||
2006 | if (qIsUpper(f))
| 0-1272 | ||||||||||||||||||||||||
2007 | flags = QLocaleData::CapitalEorX; never executed: flags = QLocaleData::CapitalEorX; | 0 | ||||||||||||||||||||||||
2008 | f = qToLower(f); | - | ||||||||||||||||||||||||
2009 | - | |||||||||||||||||||||||||
2010 | switch (f) { | - | ||||||||||||||||||||||||
2011 | case 'f': executed 1197 times by 10 tests: case 'f': Executed by:
| 1197 | ||||||||||||||||||||||||
2012 | form = QLocaleData::DFDecimal; | - | ||||||||||||||||||||||||
2013 | break; executed 1197 times by 10 tests: break; Executed by:
| 1197 | ||||||||||||||||||||||||
2014 | case 'e': never executed: case 'e': | 0 | ||||||||||||||||||||||||
2015 | form = QLocaleData::DFExponent; | - | ||||||||||||||||||||||||
2016 | break; never executed: break; | 0 | ||||||||||||||||||||||||
2017 | case 'g': executed 75 times by 3 tests: case 'g': Executed by:
| 75 | ||||||||||||||||||||||||
2018 | form = QLocaleData::DFSignificantDigits; | - | ||||||||||||||||||||||||
2019 | break; executed 75 times by 3 tests: break; Executed by:
| 75 | ||||||||||||||||||||||||
2020 | default: never executed: default: | 0 | ||||||||||||||||||||||||
2021 | break; never executed: break; | 0 | ||||||||||||||||||||||||
2022 | } | - | ||||||||||||||||||||||||
2023 | - | |||||||||||||||||||||||||
2024 | if (!(d->m_numberOptions & OmitGroupSeparator))
| 587-685 | ||||||||||||||||||||||||
2025 | flags |= QLocaleData::ThousandsGroup; executed 587 times by 9 tests: flags |= QLocaleData::ThousandsGroup; Executed by:
| 587 | ||||||||||||||||||||||||
2026 | if (!(d->m_numberOptions & OmitLeadingZeroInExponent))
| 0-1272 | ||||||||||||||||||||||||
2027 | flags |= QLocaleData::ZeroPadExponent executed 1272 times by 10 tests: ;flags |= QLocaleData::ZeroPadExponent; Executed by:
executed 1272 times by 10 tests: flags |= QLocaleData::ZeroPadExponent; Executed by:
| 1272 | ||||||||||||||||||||||||
2028 | return d->m_data->doubleToString(i, prec, form, -1, flags); executed 1272 times by 10 tests: return d->m_data->doubleToString(i, prec, form, -1, flags); Executed by:
| 1272 | ||||||||||||||||||||||||
2029 | } | - | ||||||||||||||||||||||||
2030 | - | |||||||||||||||||||||||||
2031 | /*! | - | ||||||||||||||||||||||||
2032 | \fn QLocale QLocale::c() | - | ||||||||||||||||||||||||
2033 | - | |||||||||||||||||||||||||
2034 | Returns a QLocale object initialized to the "C" locale. | - | ||||||||||||||||||||||||
2035 | - | |||||||||||||||||||||||||
2036 | \sa system() | - | ||||||||||||||||||||||||
2037 | */ | - | ||||||||||||||||||||||||
2038 | - | |||||||||||||||||||||||||
2039 | /*! | - | ||||||||||||||||||||||||
2040 | Returns a QLocale object initialized to the system locale. | - | ||||||||||||||||||||||||
2041 | - | |||||||||||||||||||||||||
2042 | On Windows and Mac, this locale will use the decimal/grouping characters and date/time | - | ||||||||||||||||||||||||
2043 | formats specified in the system configuration panel. | - | ||||||||||||||||||||||||
2044 | - | |||||||||||||||||||||||||
2045 | \sa c() | - | ||||||||||||||||||||||||
2046 | */ | - | ||||||||||||||||||||||||
2047 | - | |||||||||||||||||||||||||
2048 | QLocale QLocale::system() | - | ||||||||||||||||||||||||
2049 | { | - | ||||||||||||||||||||||||
2050 | return QLocale(*QLocalePrivate::create(systemData())); | - | ||||||||||||||||||||||||
2051 | } | - | ||||||||||||||||||||||||
2052 | - | |||||||||||||||||||||||||
2053 | - | |||||||||||||||||||||||||
2054 | /*! | - | ||||||||||||||||||||||||
2055 | \since 4.8 | - | ||||||||||||||||||||||||
2056 | - | |||||||||||||||||||||||||
2057 | Returns a list of valid locale objects that match the given \a language, \a | - | ||||||||||||||||||||||||
2058 | script and \a country. | - | ||||||||||||||||||||||||
2059 | - | |||||||||||||||||||||||||
2060 | Getting a list of all locales: | - | ||||||||||||||||||||||||
2061 | QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry); | - | ||||||||||||||||||||||||
2062 | - | |||||||||||||||||||||||||
2063 | Getting a list of locales suitable for Russia: | - | ||||||||||||||||||||||||
2064 | QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::Russia); | - | ||||||||||||||||||||||||
2065 | */ | - | ||||||||||||||||||||||||
2066 | QList<QLocale> QLocale::matchingLocales(QLocale::Language language, | - | ||||||||||||||||||||||||
2067 | QLocale::Script script, | - | ||||||||||||||||||||||||
2068 | QLocale::Country country) | - | ||||||||||||||||||||||||
2069 | { | - | ||||||||||||||||||||||||
2070 | if (uint(language) > QLocale::LastLanguage || uint(script) > QLocale::LastScript || | - | ||||||||||||||||||||||||
2071 | uint(country) > QLocale::LastCountry) | - | ||||||||||||||||||||||||
2072 | return QList<QLocale>(); | - | ||||||||||||||||||||||||
2073 | - | |||||||||||||||||||||||||
2074 | if (language == QLocale::C) | - | ||||||||||||||||||||||||
2075 | return QList<QLocale>() << QLocale(QLocale::C); | - | ||||||||||||||||||||||||
2076 | - | |||||||||||||||||||||||||
2077 | QList<QLocale> result; | - | ||||||||||||||||||||||||
2078 | if (language == QLocale::AnyLanguage && script == QLocale::AnyScript && country == QLocale::AnyCountry) | - | ||||||||||||||||||||||||
2079 | result.reserve(locale_data_size); | - | ||||||||||||||||||||||||
2080 | const QLocaleData *data = locale_data + locale_index[language]; | - | ||||||||||||||||||||||||
2081 | while ( (data != locale_data + locale_data_size) | - | ||||||||||||||||||||||||
2082 | && (language == QLocale::AnyLanguage || data->m_language_id == uint(language))) { | - | ||||||||||||||||||||||||
2083 | if ((script == QLocale::AnyScript || data->m_script_id == uint(script)) | - | ||||||||||||||||||||||||
2084 | && (country == QLocale::AnyCountry || data->m_country_id == uint(country))) { | - | ||||||||||||||||||||||||
2085 | QLocale locale(*QLocalePrivate::create(data)); | - | ||||||||||||||||||||||||
2086 | result.append(locale); | - | ||||||||||||||||||||||||
2087 | } | - | ||||||||||||||||||||||||
2088 | ++data; | - | ||||||||||||||||||||||||
2089 | } | - | ||||||||||||||||||||||||
2090 | return result; | - | ||||||||||||||||||||||||
2091 | } | - | ||||||||||||||||||||||||
2092 | - | |||||||||||||||||||||||||
2093 | /*! | - | ||||||||||||||||||||||||
2094 | \obsolete | - | ||||||||||||||||||||||||
2095 | \since 4.3 | - | ||||||||||||||||||||||||
2096 | - | |||||||||||||||||||||||||
2097 | Returns the list of countries that have entries for \a language in Qt's locale | - | ||||||||||||||||||||||||
2098 | database. If the result is an empty list, then \a language is not represented in | - | ||||||||||||||||||||||||
2099 | Qt's locale database. | - | ||||||||||||||||||||||||
2100 | - | |||||||||||||||||||||||||
2101 | \sa matchingLocales() | - | ||||||||||||||||||||||||
2102 | */ | - | ||||||||||||||||||||||||
2103 | QList<QLocale::Country> QLocale::countriesForLanguage(Language language) | - | ||||||||||||||||||||||||
2104 | { | - | ||||||||||||||||||||||||
2105 | QList<Country> result; | - | ||||||||||||||||||||||||
2106 | if (language == C) { | - | ||||||||||||||||||||||||
2107 | result << AnyCountry; | - | ||||||||||||||||||||||||
2108 | return result; | - | ||||||||||||||||||||||||
2109 | } | - | ||||||||||||||||||||||||
2110 | - | |||||||||||||||||||||||||
2111 | unsigned language_id = language; | - | ||||||||||||||||||||||||
2112 | const QLocaleData *data = locale_data + locale_index[language_id]; | - | ||||||||||||||||||||||||
2113 | while (data->m_language_id == language_id) { | - | ||||||||||||||||||||||||
2114 | const QLocale::Country country = static_cast<Country>(data->m_country_id); | - | ||||||||||||||||||||||||
2115 | if (!result.contains(country)) | - | ||||||||||||||||||||||||
2116 | result.append(country); | - | ||||||||||||||||||||||||
2117 | ++data; | - | ||||||||||||||||||||||||
2118 | } | - | ||||||||||||||||||||||||
2119 | - | |||||||||||||||||||||||||
2120 | return result; | - | ||||||||||||||||||||||||
2121 | } | - | ||||||||||||||||||||||||
2122 | - | |||||||||||||||||||||||||
2123 | /*! | - | ||||||||||||||||||||||||
2124 | \since 4.2 | - | ||||||||||||||||||||||||
2125 | - | |||||||||||||||||||||||||
2126 | Returns the localized name of \a month, in the format specified | - | ||||||||||||||||||||||||
2127 | by \a type. | - | ||||||||||||||||||||||||
2128 | - | |||||||||||||||||||||||||
2129 | \sa dayName(), standaloneMonthName() | - | ||||||||||||||||||||||||
2130 | */ | - | ||||||||||||||||||||||||
2131 | QString QLocale::monthName(int month, FormatType type) const | - | ||||||||||||||||||||||||
2132 | { | - | ||||||||||||||||||||||||
2133 | if (month < 1 || month > 12) | - | ||||||||||||||||||||||||
2134 | return QString(); | - | ||||||||||||||||||||||||
2135 | - | |||||||||||||||||||||||||
2136 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
2137 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
2138 | QVariant res = systemLocale()->query(type == LongFormat | - | ||||||||||||||||||||||||
2139 | ? QSystemLocale::MonthNameLong : QSystemLocale::MonthNameShort, | - | ||||||||||||||||||||||||
2140 | month); | - | ||||||||||||||||||||||||
2141 | if (!res.isNull()) | - | ||||||||||||||||||||||||
2142 | return res.toString(); | - | ||||||||||||||||||||||||
2143 | } | - | ||||||||||||||||||||||||
2144 | #endif | - | ||||||||||||||||||||||||
2145 | - | |||||||||||||||||||||||||
2146 | quint32 idx, size; | - | ||||||||||||||||||||||||
2147 | switch (type) { | - | ||||||||||||||||||||||||
2148 | case QLocale::LongFormat: | - | ||||||||||||||||||||||||
2149 | idx = d->m_data->m_long_month_names_idx; | - | ||||||||||||||||||||||||
2150 | size = d->m_data->m_long_month_names_size; | - | ||||||||||||||||||||||||
2151 | break; | - | ||||||||||||||||||||||||
2152 | case QLocale::ShortFormat: | - | ||||||||||||||||||||||||
2153 | idx = d->m_data->m_short_month_names_idx; | - | ||||||||||||||||||||||||
2154 | size = d->m_data->m_short_month_names_size; | - | ||||||||||||||||||||||||
2155 | break; | - | ||||||||||||||||||||||||
2156 | case QLocale::NarrowFormat: | - | ||||||||||||||||||||||||
2157 | idx = d->m_data->m_narrow_month_names_idx; | - | ||||||||||||||||||||||||
2158 | size = d->m_data->m_narrow_month_names_size; | - | ||||||||||||||||||||||||
2159 | break; | - | ||||||||||||||||||||||||
2160 | default: | - | ||||||||||||||||||||||||
2161 | return QString(); | - | ||||||||||||||||||||||||
2162 | } | - | ||||||||||||||||||||||||
2163 | return getLocaleListData(months_data + idx, size, month - 1); | - | ||||||||||||||||||||||||
2164 | } | - | ||||||||||||||||||||||||
2165 | - | |||||||||||||||||||||||||
2166 | /*! | - | ||||||||||||||||||||||||
2167 | \since 4.5 | - | ||||||||||||||||||||||||
2168 | - | |||||||||||||||||||||||||
2169 | Returns the localized name of \a month that is used as a | - | ||||||||||||||||||||||||
2170 | standalone text, in the format specified by \a type. | - | ||||||||||||||||||||||||
2171 | - | |||||||||||||||||||||||||
2172 | If the locale information doesn't specify the standalone month | - | ||||||||||||||||||||||||
2173 | name then return value is the same as in monthName(). | - | ||||||||||||||||||||||||
2174 | - | |||||||||||||||||||||||||
2175 | \sa monthName(), standaloneDayName() | - | ||||||||||||||||||||||||
2176 | */ | - | ||||||||||||||||||||||||
2177 | QString QLocale::standaloneMonthName(int month, FormatType type) const | - | ||||||||||||||||||||||||
2178 | { | - | ||||||||||||||||||||||||
2179 | if (month < 1 || month > 12) | - | ||||||||||||||||||||||||
2180 | return QString(); | - | ||||||||||||||||||||||||
2181 | - | |||||||||||||||||||||||||
2182 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
2183 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
2184 | QVariant res = systemLocale()->query(type == LongFormat | - | ||||||||||||||||||||||||
2185 | ? QSystemLocale::StandaloneMonthNameLong : QSystemLocale::StandaloneMonthNameShort, | - | ||||||||||||||||||||||||
2186 | month); | - | ||||||||||||||||||||||||
2187 | if (!res.isNull()) | - | ||||||||||||||||||||||||
2188 | return res.toString(); | - | ||||||||||||||||||||||||
2189 | } | - | ||||||||||||||||||||||||
2190 | #endif | - | ||||||||||||||||||||||||
2191 | - | |||||||||||||||||||||||||
2192 | quint32 idx, size; | - | ||||||||||||||||||||||||
2193 | switch (type) { | - | ||||||||||||||||||||||||
2194 | case QLocale::LongFormat: | - | ||||||||||||||||||||||||
2195 | idx = d->m_data->m_standalone_long_month_names_idx; | - | ||||||||||||||||||||||||
2196 | size = d->m_data->m_standalone_long_month_names_size; | - | ||||||||||||||||||||||||
2197 | break; | - | ||||||||||||||||||||||||
2198 | case QLocale::ShortFormat: | - | ||||||||||||||||||||||||
2199 | idx = d->m_data->m_standalone_short_month_names_idx; | - | ||||||||||||||||||||||||
2200 | size = d->m_data->m_standalone_short_month_names_size; | - | ||||||||||||||||||||||||
2201 | break; | - | ||||||||||||||||||||||||
2202 | case QLocale::NarrowFormat: | - | ||||||||||||||||||||||||
2203 | idx = d->m_data->m_standalone_narrow_month_names_idx; | - | ||||||||||||||||||||||||
2204 | size = d->m_data->m_standalone_narrow_month_names_size; | - | ||||||||||||||||||||||||
2205 | break; | - | ||||||||||||||||||||||||
2206 | default: | - | ||||||||||||||||||||||||
2207 | return QString(); | - | ||||||||||||||||||||||||
2208 | } | - | ||||||||||||||||||||||||
2209 | QString name = getLocaleListData(months_data + idx, size, month - 1); | - | ||||||||||||||||||||||||
2210 | if (name.isEmpty()) | - | ||||||||||||||||||||||||
2211 | return monthName(month, type); | - | ||||||||||||||||||||||||
2212 | return name; | - | ||||||||||||||||||||||||
2213 | } | - | ||||||||||||||||||||||||
2214 | - | |||||||||||||||||||||||||
2215 | /*! | - | ||||||||||||||||||||||||
2216 | \since 4.2 | - | ||||||||||||||||||||||||
2217 | - | |||||||||||||||||||||||||
2218 | Returns the localized name of the \a day (where 1 represents | - | ||||||||||||||||||||||||
2219 | Monday, 2 represents Tuesday and so on), in the format specified | - | ||||||||||||||||||||||||
2220 | by \a type. | - | ||||||||||||||||||||||||
2221 | - | |||||||||||||||||||||||||
2222 | \sa monthName(), standaloneDayName() | - | ||||||||||||||||||||||||
2223 | */ | - | ||||||||||||||||||||||||
2224 | QString QLocale::dayName(int day, FormatType type) const | - | ||||||||||||||||||||||||
2225 | { | - | ||||||||||||||||||||||||
2226 | if (day < 1 || day > 7) | - | ||||||||||||||||||||||||
2227 | return QString(); | - | ||||||||||||||||||||||||
2228 | - | |||||||||||||||||||||||||
2229 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
2230 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
2231 | QVariant res = systemLocale()->query(type == LongFormat | - | ||||||||||||||||||||||||
2232 | ? QSystemLocale::DayNameLong : QSystemLocale::DayNameShort, | - | ||||||||||||||||||||||||
2233 | day); | - | ||||||||||||||||||||||||
2234 | if (!res.isNull()) | - | ||||||||||||||||||||||||
2235 | return res.toString(); | - | ||||||||||||||||||||||||
2236 | } | - | ||||||||||||||||||||||||
2237 | #endif | - | ||||||||||||||||||||||||
2238 | if (day == 7) | - | ||||||||||||||||||||||||
2239 | day = 0; | - | ||||||||||||||||||||||||
2240 | - | |||||||||||||||||||||||||
2241 | quint32 idx, size; | - | ||||||||||||||||||||||||
2242 | switch (type) { | - | ||||||||||||||||||||||||
2243 | case QLocale::LongFormat: | - | ||||||||||||||||||||||||
2244 | idx = d->m_data->m_long_day_names_idx; | - | ||||||||||||||||||||||||
2245 | size = d->m_data->m_long_day_names_size; | - | ||||||||||||||||||||||||
2246 | break; | - | ||||||||||||||||||||||||
2247 | case QLocale::ShortFormat: | - | ||||||||||||||||||||||||
2248 | idx = d->m_data->m_short_day_names_idx; | - | ||||||||||||||||||||||||
2249 | size = d->m_data->m_short_day_names_size; | - | ||||||||||||||||||||||||
2250 | break; | - | ||||||||||||||||||||||||
2251 | case QLocale::NarrowFormat: | - | ||||||||||||||||||||||||
2252 | idx = d->m_data->m_narrow_day_names_idx; | - | ||||||||||||||||||||||||
2253 | size = d->m_data->m_narrow_day_names_size; | - | ||||||||||||||||||||||||
2254 | break; | - | ||||||||||||||||||||||||
2255 | default: | - | ||||||||||||||||||||||||
2256 | return QString(); | - | ||||||||||||||||||||||||
2257 | } | - | ||||||||||||||||||||||||
2258 | return getLocaleListData(days_data + idx, size, day); | - | ||||||||||||||||||||||||
2259 | } | - | ||||||||||||||||||||||||
2260 | - | |||||||||||||||||||||||||
2261 | /*! | - | ||||||||||||||||||||||||
2262 | \since 4.5 | - | ||||||||||||||||||||||||
2263 | - | |||||||||||||||||||||||||
2264 | Returns the localized name of the \a day (where 1 represents | - | ||||||||||||||||||||||||
2265 | Monday, 2 represents Tuesday and so on) that is used as a | - | ||||||||||||||||||||||||
2266 | standalone text, in the format specified by \a type. | - | ||||||||||||||||||||||||
2267 | - | |||||||||||||||||||||||||
2268 | If the locale information does not specify the standalone day | - | ||||||||||||||||||||||||
2269 | name then return value is the same as in dayName(). | - | ||||||||||||||||||||||||
2270 | - | |||||||||||||||||||||||||
2271 | \sa dayName(), standaloneMonthName() | - | ||||||||||||||||||||||||
2272 | */ | - | ||||||||||||||||||||||||
2273 | QString QLocale::standaloneDayName(int day, FormatType type) const | - | ||||||||||||||||||||||||
2274 | { | - | ||||||||||||||||||||||||
2275 | if (day < 1 || day > 7) | - | ||||||||||||||||||||||||
2276 | return QString(); | - | ||||||||||||||||||||||||
2277 | - | |||||||||||||||||||||||||
2278 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
2279 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
2280 | QVariant res = systemLocale()->query(type == LongFormat | - | ||||||||||||||||||||||||
2281 | ? QSystemLocale::DayNameLong : QSystemLocale::DayNameShort, | - | ||||||||||||||||||||||||
2282 | day); | - | ||||||||||||||||||||||||
2283 | if (!res.isNull()) | - | ||||||||||||||||||||||||
2284 | return res.toString(); | - | ||||||||||||||||||||||||
2285 | } | - | ||||||||||||||||||||||||
2286 | #endif | - | ||||||||||||||||||||||||
2287 | if (day == 7) | - | ||||||||||||||||||||||||
2288 | day = 0; | - | ||||||||||||||||||||||||
2289 | - | |||||||||||||||||||||||||
2290 | quint32 idx, size; | - | ||||||||||||||||||||||||
2291 | switch (type) { | - | ||||||||||||||||||||||||
2292 | case QLocale::LongFormat: | - | ||||||||||||||||||||||||
2293 | idx = d->m_data->m_standalone_long_day_names_idx; | - | ||||||||||||||||||||||||
2294 | size = d->m_data->m_standalone_long_day_names_size; | - | ||||||||||||||||||||||||
2295 | break; | - | ||||||||||||||||||||||||
2296 | case QLocale::ShortFormat: | - | ||||||||||||||||||||||||
2297 | idx = d->m_data->m_standalone_short_day_names_idx; | - | ||||||||||||||||||||||||
2298 | size = d->m_data->m_standalone_short_day_names_size; | - | ||||||||||||||||||||||||
2299 | break; | - | ||||||||||||||||||||||||
2300 | case QLocale::NarrowFormat: | - | ||||||||||||||||||||||||
2301 | idx = d->m_data->m_standalone_narrow_day_names_idx; | - | ||||||||||||||||||||||||
2302 | size = d->m_data->m_standalone_narrow_day_names_size; | - | ||||||||||||||||||||||||
2303 | break; | - | ||||||||||||||||||||||||
2304 | default: | - | ||||||||||||||||||||||||
2305 | return QString(); | - | ||||||||||||||||||||||||
2306 | } | - | ||||||||||||||||||||||||
2307 | QString name = getLocaleListData(days_data + idx, size, day); | - | ||||||||||||||||||||||||
2308 | if (name.isEmpty()) | - | ||||||||||||||||||||||||
2309 | return dayName(day == 0 ? 7 : day, type); | - | ||||||||||||||||||||||||
2310 | return name; | - | ||||||||||||||||||||||||
2311 | } | - | ||||||||||||||||||||||||
2312 | - | |||||||||||||||||||||||||
2313 | /*! | - | ||||||||||||||||||||||||
2314 | \since 4.8 | - | ||||||||||||||||||||||||
2315 | - | |||||||||||||||||||||||||
2316 | Returns the first day of the week according to the current locale. | - | ||||||||||||||||||||||||
2317 | */ | - | ||||||||||||||||||||||||
2318 | Qt::DayOfWeek QLocale::firstDayOfWeek() const | - | ||||||||||||||||||||||||
2319 | { | - | ||||||||||||||||||||||||
2320 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
2321 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
2322 | QVariant res = systemLocale()->query(QSystemLocale::FirstDayOfWeek, QVariant()); | - | ||||||||||||||||||||||||
2323 | if (!res.isNull()) | - | ||||||||||||||||||||||||
2324 | return static_cast<Qt::DayOfWeek>(res.toUInt()); | - | ||||||||||||||||||||||||
2325 | } | - | ||||||||||||||||||||||||
2326 | #endif | - | ||||||||||||||||||||||||
2327 | return static_cast<Qt::DayOfWeek>(d->m_data->m_first_day_of_week); | - | ||||||||||||||||||||||||
2328 | } | - | ||||||||||||||||||||||||
2329 | - | |||||||||||||||||||||||||
2330 | QLocale::MeasurementSystem QLocalePrivate::measurementSystem() const | - | ||||||||||||||||||||||||
2331 | { | - | ||||||||||||||||||||||||
2332 | for (int i = 0; i < ImperialMeasurementSystemsCount; ++i) { | - | ||||||||||||||||||||||||
2333 | if (ImperialMeasurementSystems[i].languageId == m_data->m_language_id | - | ||||||||||||||||||||||||
2334 | && ImperialMeasurementSystems[i].countryId == m_data->m_country_id) { | - | ||||||||||||||||||||||||
2335 | return ImperialMeasurementSystems[i].system; | - | ||||||||||||||||||||||||
2336 | } | - | ||||||||||||||||||||||||
2337 | } | - | ||||||||||||||||||||||||
2338 | return QLocale::MetricSystem; | - | ||||||||||||||||||||||||
2339 | } | - | ||||||||||||||||||||||||
2340 | - | |||||||||||||||||||||||||
2341 | /*! | - | ||||||||||||||||||||||||
2342 | \since 4.8 | - | ||||||||||||||||||||||||
2343 | - | |||||||||||||||||||||||||
2344 | Returns a list of days that are considered weekdays according to the current locale. | - | ||||||||||||||||||||||||
2345 | */ | - | ||||||||||||||||||||||||
2346 | QList<Qt::DayOfWeek> QLocale::weekdays() const | - | ||||||||||||||||||||||||
2347 | { | - | ||||||||||||||||||||||||
2348 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
2349 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
2350 | QVariant res = systemLocale()->query(QSystemLocale::Weekdays, QVariant()); | - | ||||||||||||||||||||||||
2351 | if (!res.isNull()) | - | ||||||||||||||||||||||||
2352 | return static_cast<QList<Qt::DayOfWeek> >(res.value<QList<Qt::DayOfWeek> >()); | - | ||||||||||||||||||||||||
2353 | } | - | ||||||||||||||||||||||||
2354 | #endif | - | ||||||||||||||||||||||||
2355 | QList<Qt::DayOfWeek> weekdays; | - | ||||||||||||||||||||||||
2356 | quint16 weekendStart = d->m_data->m_weekend_start; | - | ||||||||||||||||||||||||
2357 | quint16 weekendEnd = d->m_data->m_weekend_end; | - | ||||||||||||||||||||||||
2358 | for (int day = Qt::Monday; day <= Qt::Sunday; day++) { | - | ||||||||||||||||||||||||
2359 | if ((weekendEnd >= weekendStart && (day < weekendStart || day > weekendEnd)) || | - | ||||||||||||||||||||||||
2360 | (weekendEnd < weekendStart && (day > weekendEnd && day < weekendStart))) | - | ||||||||||||||||||||||||
2361 | weekdays << static_cast<Qt::DayOfWeek>(day); | - | ||||||||||||||||||||||||
2362 | } | - | ||||||||||||||||||||||||
2363 | return weekdays; | - | ||||||||||||||||||||||||
2364 | } | - | ||||||||||||||||||||||||
2365 | - | |||||||||||||||||||||||||
2366 | /*! | - | ||||||||||||||||||||||||
2367 | \since 4.4 | - | ||||||||||||||||||||||||
2368 | - | |||||||||||||||||||||||||
2369 | Returns the measurement system for the locale. | - | ||||||||||||||||||||||||
2370 | */ | - | ||||||||||||||||||||||||
2371 | QLocale::MeasurementSystem QLocale::measurementSystem() const | - | ||||||||||||||||||||||||
2372 | { | - | ||||||||||||||||||||||||
2373 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
2374 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
2375 | QVariant res = systemLocale()->query(QSystemLocale::MeasurementSystem, QVariant()); | - | ||||||||||||||||||||||||
2376 | if (!res.isNull()) | - | ||||||||||||||||||||||||
2377 | return MeasurementSystem(res.toInt()); | - | ||||||||||||||||||||||||
2378 | } | - | ||||||||||||||||||||||||
2379 | #endif | - | ||||||||||||||||||||||||
2380 | - | |||||||||||||||||||||||||
2381 | return d->measurementSystem(); | - | ||||||||||||||||||||||||
2382 | } | - | ||||||||||||||||||||||||
2383 | - | |||||||||||||||||||||||||
2384 | /*! | - | ||||||||||||||||||||||||
2385 | \since 4.7 | - | ||||||||||||||||||||||||
2386 | - | |||||||||||||||||||||||||
2387 | Returns the text direction of the language. | - | ||||||||||||||||||||||||
2388 | */ | - | ||||||||||||||||||||||||
2389 | Qt::LayoutDirection QLocale::textDirection() const | - | ||||||||||||||||||||||||
2390 | { | - | ||||||||||||||||||||||||
2391 | switch (script()) { | - | ||||||||||||||||||||||||
2392 | case QLocale::AdlamScript: never executed: case QLocale::AdlamScript: | 0 | ||||||||||||||||||||||||
2393 | case QLocale::ArabicScript: never executed: case QLocale::ArabicScript: | 0 | ||||||||||||||||||||||||
2394 | case QLocale::AvestanScript: never executed: case QLocale::AvestanScript: | 0 | ||||||||||||||||||||||||
2395 | case QLocale::CypriotScript: never executed: case QLocale::CypriotScript: | 0 | ||||||||||||||||||||||||
2396 | case QLocale::HatranScript never executed: :case QLocale::HatranScript: never executed: case QLocale::HatranScript: | 0 | ||||||||||||||||||||||||
2397 | case QLocale::HebrewScript: never executed: case QLocale::HebrewScript: | 0 | ||||||||||||||||||||||||
2398 | case QLocale::ImperialAramaicScript: never executed: case QLocale::ImperialAramaicScript: | 0 | ||||||||||||||||||||||||
2399 | case QLocale::InscriptionalPahlaviScript: never executed: case QLocale::InscriptionalPahlaviScript: | 0 | ||||||||||||||||||||||||
2400 | case QLocale::InscriptionalParthianScript: never executed: case QLocale::InscriptionalParthianScript: | 0 | ||||||||||||||||||||||||
2401 | case QLocale::KharoshthiScript: never executed: case QLocale::KharoshthiScript: | 0 | ||||||||||||||||||||||||
2402 | case QLocale::LydianScript: never executed: case QLocale::LydianScript: | 0 | ||||||||||||||||||||||||
2403 | case QLocale::MandaeanScript: never executed: case QLocale::MandaeanScript: | 0 | ||||||||||||||||||||||||
2404 | case QLocale::ManichaeanScript: never executed: case QLocale::ManichaeanScript: | 0 | ||||||||||||||||||||||||
2405 | case QLocale::MendeKikakuiScript: never executed: case QLocale::MendeKikakuiScript: | 0 | ||||||||||||||||||||||||
2406 | case QLocale::MeroiticCursiveScript: never executed: case QLocale::MeroiticCursiveScript: | 0 | ||||||||||||||||||||||||
2407 | case QLocale::MeroiticScript: never executed: case QLocale::MeroiticScript: | 0 | ||||||||||||||||||||||||
2408 | case QLocale::NabataeanScript: never executed: case QLocale::NabataeanScript: | 0 | ||||||||||||||||||||||||
2409 | case QLocale::NkoScript: never executed: case QLocale::NkoScript: | 0 | ||||||||||||||||||||||||
2410 | case QLocale::OldHungarianScript never executed: :case QLocale::OldHungarianScript: never executed: case QLocale::OldHungarianScript: | 0 | ||||||||||||||||||||||||
2411 | case QLocale::OldNorthArabianScript: never executed: case QLocale::OldNorthArabianScript: | 0 | ||||||||||||||||||||||||
2412 | case QLocale::OldSouthArabianScript: never executed: case QLocale::OldSouthArabianScript: | 0 | ||||||||||||||||||||||||
2413 | case QLocale::OrkhonScript: never executed: case QLocale::OrkhonScript: | 0 | ||||||||||||||||||||||||
2414 | case QLocale::PalmyreneScript: never executed: case QLocale::PalmyreneScript: | 0 | ||||||||||||||||||||||||
2415 | case QLocale::PhoenicianScript: never executed: case QLocale::PhoenicianScript: | 0 | ||||||||||||||||||||||||
2416 | case QLocale::PsalterPahlaviScript: never executed: case QLocale::PsalterPahlaviScript: | 0 | ||||||||||||||||||||||||
2417 | case QLocale::SamaritanScript: never executed: case QLocale::SamaritanScript: | 0 | ||||||||||||||||||||||||
2418 | case QLocale::SyriacScript: never executed: case QLocale::SyriacScript: | 0 | ||||||||||||||||||||||||
2419 | case QLocale::ThaanaScript: never executed: case QLocale::ThaanaScript: | 0 | ||||||||||||||||||||||||
2420 | return Qt::RightToLeft; never executed: return Qt::RightToLeft; | 0 | ||||||||||||||||||||||||
2421 | default: executed 34 times by 34 tests: default: Executed by:
| 34 | ||||||||||||||||||||||||
2422 | break; executed 34 times by 34 tests: break; Executed by:
| 34 | ||||||||||||||||||||||||
2423 | } | - | ||||||||||||||||||||||||
2424 | return Qt::LeftToRight; executed 34 times by 34 tests: return Qt::LeftToRight; Executed by:
| 34 | ||||||||||||||||||||||||
2425 | } | - | ||||||||||||||||||||||||
2426 | - | |||||||||||||||||||||||||
2427 | /*! | - | ||||||||||||||||||||||||
2428 | \since 4.8 | - | ||||||||||||||||||||||||
2429 | - | |||||||||||||||||||||||||
2430 | Returns an uppercase copy of \a str. | - | ||||||||||||||||||||||||
2431 | - | |||||||||||||||||||||||||
2432 | If Qt Core is using the ICU libraries, they will be used to perform | - | ||||||||||||||||||||||||
2433 | the transformation according to the rules of the current locale. | - | ||||||||||||||||||||||||
2434 | Otherwise the conversion may be done in a platform-dependent manner, | - | ||||||||||||||||||||||||
2435 | with QString::toUpper() as a generic fallback. | - | ||||||||||||||||||||||||
2436 | - | |||||||||||||||||||||||||
2437 | \sa QString::toUpper() | - | ||||||||||||||||||||||||
2438 | */ | - | ||||||||||||||||||||||||
2439 | QString QLocale::toUpper(const QString &str) const | - | ||||||||||||||||||||||||
2440 | { | - | ||||||||||||||||||||||||
2441 | #ifdef QT_USE_ICU | - | ||||||||||||||||||||||||
2442 | bool ok = true; | - | ||||||||||||||||||||||||
2443 | QString result = QIcu::toUpper(d->bcp47Name('_'), str, &ok); | - | ||||||||||||||||||||||||
2444 | if (ok) | - | ||||||||||||||||||||||||
2445 | return result; | - | ||||||||||||||||||||||||
2446 | // else fall through and use Qt's toUpper | - | ||||||||||||||||||||||||
2447 | #endif | - | ||||||||||||||||||||||||
2448 | return str.toUpper(); | - | ||||||||||||||||||||||||
2449 | } | - | ||||||||||||||||||||||||
2450 | - | |||||||||||||||||||||||||
2451 | /*! | - | ||||||||||||||||||||||||
2452 | \since 4.8 | - | ||||||||||||||||||||||||
2453 | - | |||||||||||||||||||||||||
2454 | Returns a lowercase copy of \a str. | - | ||||||||||||||||||||||||
2455 | - | |||||||||||||||||||||||||
2456 | If Qt Core is using the ICU libraries, they will be used to perform | - | ||||||||||||||||||||||||
2457 | the transformation according to the rules of the current locale. | - | ||||||||||||||||||||||||
2458 | Otherwise the conversion may be done in a platform-dependent manner, | - | ||||||||||||||||||||||||
2459 | with QString::toLower() as a generic fallback. | - | ||||||||||||||||||||||||
2460 | - | |||||||||||||||||||||||||
2461 | \sa QString::toLower() | - | ||||||||||||||||||||||||
2462 | */ | - | ||||||||||||||||||||||||
2463 | QString QLocale::toLower(const QString &str) const | - | ||||||||||||||||||||||||
2464 | { | - | ||||||||||||||||||||||||
2465 | #ifdef QT_USE_ICU | - | ||||||||||||||||||||||||
2466 | bool ok = true; | - | ||||||||||||||||||||||||
2467 | const QString result = QIcu::toLower(d->bcp47Name('_'), str, &ok); | - | ||||||||||||||||||||||||
2468 | if (ok) | - | ||||||||||||||||||||||||
2469 | return result; | - | ||||||||||||||||||||||||
2470 | // else fall through and use Qt's toUpper | - | ||||||||||||||||||||||||
2471 | #endif | - | ||||||||||||||||||||||||
2472 | return str.toLower(); | - | ||||||||||||||||||||||||
2473 | } | - | ||||||||||||||||||||||||
2474 | - | |||||||||||||||||||||||||
2475 | - | |||||||||||||||||||||||||
2476 | /*! | - | ||||||||||||||||||||||||
2477 | \since 4.5 | - | ||||||||||||||||||||||||
2478 | - | |||||||||||||||||||||||||
2479 | Returns the localized name of the "AM" suffix for times specified using | - | ||||||||||||||||||||||||
2480 | the conventions of the 12-hour clock. | - | ||||||||||||||||||||||||
2481 | - | |||||||||||||||||||||||||
2482 | \sa pmText() | - | ||||||||||||||||||||||||
2483 | */ | - | ||||||||||||||||||||||||
2484 | QString QLocale::amText() const | - | ||||||||||||||||||||||||
2485 | { | - | ||||||||||||||||||||||||
2486 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
2487 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
2488 | QVariant res = systemLocale()->query(QSystemLocale::AMText, QVariant()); | - | ||||||||||||||||||||||||
2489 | if (!res.isNull()) | - | ||||||||||||||||||||||||
2490 | return res.toString(); | - | ||||||||||||||||||||||||
2491 | } | - | ||||||||||||||||||||||||
2492 | #endif | - | ||||||||||||||||||||||||
2493 | return getLocaleData(am_data + d->m_data->m_am_idx, d->m_data->m_am_size); | - | ||||||||||||||||||||||||
2494 | } | - | ||||||||||||||||||||||||
2495 | - | |||||||||||||||||||||||||
2496 | /*! | - | ||||||||||||||||||||||||
2497 | \since 4.5 | - | ||||||||||||||||||||||||
2498 | - | |||||||||||||||||||||||||
2499 | Returns the localized name of the "PM" suffix for times specified using | - | ||||||||||||||||||||||||
2500 | the conventions of the 12-hour clock. | - | ||||||||||||||||||||||||
2501 | - | |||||||||||||||||||||||||
2502 | \sa amText() | - | ||||||||||||||||||||||||
2503 | */ | - | ||||||||||||||||||||||||
2504 | QString QLocale::pmText() const | - | ||||||||||||||||||||||||
2505 | { | - | ||||||||||||||||||||||||
2506 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
2507 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
2508 | QVariant res = systemLocale()->query(QSystemLocale::PMText, QVariant()); | - | ||||||||||||||||||||||||
2509 | if (!res.isNull()) | - | ||||||||||||||||||||||||
2510 | return res.toString(); | - | ||||||||||||||||||||||||
2511 | } | - | ||||||||||||||||||||||||
2512 | #endif | - | ||||||||||||||||||||||||
2513 | return getLocaleData(pm_data + d->m_data->m_pm_idx, d->m_data->m_pm_size); | - | ||||||||||||||||||||||||
2514 | } | - | ||||||||||||||||||||||||
2515 | - | |||||||||||||||||||||||||
2516 | - | |||||||||||||||||||||||||
2517 | QString QLocalePrivate::dateTimeToString(const QString &format, const QDateTime &datetime, | - | ||||||||||||||||||||||||
2518 | const QDate &dateOnly, const QTime &timeOnly, | - | ||||||||||||||||||||||||
2519 | const QLocale *q) const | - | ||||||||||||||||||||||||
2520 | { | - | ||||||||||||||||||||||||
2521 | QDate date; | - | ||||||||||||||||||||||||
2522 | QTime time; | - | ||||||||||||||||||||||||
2523 | bool formatDate = false; | - | ||||||||||||||||||||||||
2524 | bool formatTime = false; | - | ||||||||||||||||||||||||
2525 | if (datetime.isValid()) { | - | ||||||||||||||||||||||||
2526 | date = datetime.date(); | - | ||||||||||||||||||||||||
2527 | time = datetime.time(); | - | ||||||||||||||||||||||||
2528 | formatDate = true; | - | ||||||||||||||||||||||||
2529 | formatTime = true; | - | ||||||||||||||||||||||||
2530 | } else if (dateOnly.isValid()) { | - | ||||||||||||||||||||||||
2531 | date = dateOnly; | - | ||||||||||||||||||||||||
2532 | formatDate = true; | - | ||||||||||||||||||||||||
2533 | } else if (timeOnly.isValid()) { | - | ||||||||||||||||||||||||
2534 | time = timeOnly; | - | ||||||||||||||||||||||||
2535 | formatTime = true; | - | ||||||||||||||||||||||||
2536 | } else { | - | ||||||||||||||||||||||||
2537 | return QString(); | - | ||||||||||||||||||||||||
2538 | } | - | ||||||||||||||||||||||||
2539 | - | |||||||||||||||||||||||||
2540 | QString result; | - | ||||||||||||||||||||||||
2541 | - | |||||||||||||||||||||||||
2542 | int i = 0; | - | ||||||||||||||||||||||||
2543 | while (i < format.size()) { | - | ||||||||||||||||||||||||
2544 | if (format.at(i).unicode() == '\'') { | - | ||||||||||||||||||||||||
2545 | result.append(qt_readEscapedFormatString(format, &i)); | - | ||||||||||||||||||||||||
2546 | continue; | - | ||||||||||||||||||||||||
2547 | } | - | ||||||||||||||||||||||||
2548 | - | |||||||||||||||||||||||||
2549 | const QChar c = format.at(i); | - | ||||||||||||||||||||||||
2550 | int repeat = qt_repeatCount(format, i); | - | ||||||||||||||||||||||||
2551 | bool used = false; | - | ||||||||||||||||||||||||
2552 | if (formatDate) { | - | ||||||||||||||||||||||||
2553 | switch (c.unicode()) { | - | ||||||||||||||||||||||||
2554 | case 'y': | - | ||||||||||||||||||||||||
2555 | used = true; | - | ||||||||||||||||||||||||
2556 | if (repeat >= 4) | - | ||||||||||||||||||||||||
2557 | repeat = 4; | - | ||||||||||||||||||||||||
2558 | else if (repeat >= 2) | - | ||||||||||||||||||||||||
2559 | repeat = 2; | - | ||||||||||||||||||||||||
2560 | - | |||||||||||||||||||||||||
2561 | switch (repeat) { | - | ||||||||||||||||||||||||
2562 | case 4: { | - | ||||||||||||||||||||||||
2563 | const int yr = date.year(); | - | ||||||||||||||||||||||||
2564 | const int len = (yr < 0) ? 5 : 4; | - | ||||||||||||||||||||||||
2565 | result.append(m_data->longLongToString(yr, -1, 10, len, QLocaleData::ZeroPadded)); | - | ||||||||||||||||||||||||
2566 | break; | - | ||||||||||||||||||||||||
2567 | } | - | ||||||||||||||||||||||||
2568 | case 2: | - | ||||||||||||||||||||||||
2569 | result.append(m_data->longLongToString(date.year() % 100, -1, 10, 2, | - | ||||||||||||||||||||||||
2570 | QLocaleData::ZeroPadded)); | - | ||||||||||||||||||||||||
2571 | break; | - | ||||||||||||||||||||||||
2572 | default: | - | ||||||||||||||||||||||||
2573 | repeat = 1; | - | ||||||||||||||||||||||||
2574 | result.append(c); | - | ||||||||||||||||||||||||
2575 | break; | - | ||||||||||||||||||||||||
2576 | } | - | ||||||||||||||||||||||||
2577 | break; | - | ||||||||||||||||||||||||
2578 | - | |||||||||||||||||||||||||
2579 | case 'M': | - | ||||||||||||||||||||||||
2580 | used = true; | - | ||||||||||||||||||||||||
2581 | repeat = qMin(repeat, 4); | - | ||||||||||||||||||||||||
2582 | switch (repeat) { | - | ||||||||||||||||||||||||
2583 | case 1: | - | ||||||||||||||||||||||||
2584 | result.append(m_data->longLongToString(date.month())); | - | ||||||||||||||||||||||||
2585 | break; | - | ||||||||||||||||||||||||
2586 | case 2: | - | ||||||||||||||||||||||||
2587 | result.append(m_data->longLongToString(date.month(), -1, 10, 2, QLocaleData::ZeroPadded)); | - | ||||||||||||||||||||||||
2588 | break; | - | ||||||||||||||||||||||||
2589 | case 3: | - | ||||||||||||||||||||||||
2590 | result.append(q->monthName(date.month(), QLocale::ShortFormat)); | - | ||||||||||||||||||||||||
2591 | break; | - | ||||||||||||||||||||||||
2592 | case 4: | - | ||||||||||||||||||||||||
2593 | result.append(q->monthName(date.month(), QLocale::LongFormat)); | - | ||||||||||||||||||||||||
2594 | break; | - | ||||||||||||||||||||||||
2595 | } | - | ||||||||||||||||||||||||
2596 | break; | - | ||||||||||||||||||||||||
2597 | - | |||||||||||||||||||||||||
2598 | case 'd': | - | ||||||||||||||||||||||||
2599 | used = true; | - | ||||||||||||||||||||||||
2600 | repeat = qMin(repeat, 4); | - | ||||||||||||||||||||||||
2601 | switch (repeat) { | - | ||||||||||||||||||||||||
2602 | case 1: | - | ||||||||||||||||||||||||
2603 | result.append(m_data->longLongToString(date.day())); | - | ||||||||||||||||||||||||
2604 | break; | - | ||||||||||||||||||||||||
2605 | case 2: | - | ||||||||||||||||||||||||
2606 | result.append(m_data->longLongToString(date.day(), -1, 10, 2, QLocaleData::ZeroPadded)); | - | ||||||||||||||||||||||||
2607 | break; | - | ||||||||||||||||||||||||
2608 | case 3: | - | ||||||||||||||||||||||||
2609 | result.append(q->dayName(date.dayOfWeek(), QLocale::ShortFormat)); | - | ||||||||||||||||||||||||
2610 | break; | - | ||||||||||||||||||||||||
2611 | case 4: | - | ||||||||||||||||||||||||
2612 | result.append(q->dayName(date.dayOfWeek(), QLocale::LongFormat)); | - | ||||||||||||||||||||||||
2613 | break; | - | ||||||||||||||||||||||||
2614 | } | - | ||||||||||||||||||||||||
2615 | break; | - | ||||||||||||||||||||||||
2616 | - | |||||||||||||||||||||||||
2617 | default: | - | ||||||||||||||||||||||||
2618 | break; | - | ||||||||||||||||||||||||
2619 | } | - | ||||||||||||||||||||||||
2620 | } | - | ||||||||||||||||||||||||
2621 | if (!used && formatTime) { | - | ||||||||||||||||||||||||
2622 | switch (c.unicode()) { | - | ||||||||||||||||||||||||
2623 | case 'h': { | - | ||||||||||||||||||||||||
2624 | used = true; | - | ||||||||||||||||||||||||
2625 | repeat = qMin(repeat, 2); | - | ||||||||||||||||||||||||
2626 | int hour = time.hour(); | - | ||||||||||||||||||||||||
2627 | if (timeFormatContainsAP(format)) { | - | ||||||||||||||||||||||||
2628 | if (hour > 12) | - | ||||||||||||||||||||||||
2629 | hour -= 12; | - | ||||||||||||||||||||||||
2630 | else if (hour == 0) | - | ||||||||||||||||||||||||
2631 | hour = 12; | - | ||||||||||||||||||||||||
2632 | } | - | ||||||||||||||||||||||||
2633 | - | |||||||||||||||||||||||||
2634 | switch (repeat) { | - | ||||||||||||||||||||||||
2635 | case 1: | - | ||||||||||||||||||||||||
2636 | result.append(m_data->longLongToString(hour)); | - | ||||||||||||||||||||||||
2637 | break; | - | ||||||||||||||||||||||||
2638 | case 2: | - | ||||||||||||||||||||||||
2639 | result.append(m_data->longLongToString(hour, -1, 10, 2, QLocaleData::ZeroPadded)); | - | ||||||||||||||||||||||||
2640 | break; | - | ||||||||||||||||||||||||
2641 | } | - | ||||||||||||||||||||||||
2642 | break; | - | ||||||||||||||||||||||||
2643 | } | - | ||||||||||||||||||||||||
2644 | case 'H': | - | ||||||||||||||||||||||||
2645 | used = true; | - | ||||||||||||||||||||||||
2646 | repeat = qMin(repeat, 2); | - | ||||||||||||||||||||||||
2647 | switch (repeat) { | - | ||||||||||||||||||||||||
2648 | case 1: | - | ||||||||||||||||||||||||
2649 | result.append(m_data->longLongToString(time.hour())); | - | ||||||||||||||||||||||||
2650 | break; | - | ||||||||||||||||||||||||
2651 | case 2: | - | ||||||||||||||||||||||||
2652 | result.append(m_data->longLongToString(time.hour(), -1, 10, 2, QLocaleData::ZeroPadded)); | - | ||||||||||||||||||||||||
2653 | break; | - | ||||||||||||||||||||||||
2654 | } | - | ||||||||||||||||||||||||
2655 | break; | - | ||||||||||||||||||||||||
2656 | - | |||||||||||||||||||||||||
2657 | case 'm': | - | ||||||||||||||||||||||||
2658 | used = true; | - | ||||||||||||||||||||||||
2659 | repeat = qMin(repeat, 2); | - | ||||||||||||||||||||||||
2660 | switch (repeat) { | - | ||||||||||||||||||||||||
2661 | case 1: | - | ||||||||||||||||||||||||
2662 | result.append(m_data->longLongToString(time.minute())); | - | ||||||||||||||||||||||||
2663 | break; | - | ||||||||||||||||||||||||
2664 | case 2: | - | ||||||||||||||||||||||||
2665 | result.append(m_data->longLongToString(time.minute(), -1, 10, 2, QLocaleData::ZeroPadded)); | - | ||||||||||||||||||||||||
2666 | break; | - | ||||||||||||||||||||||||
2667 | } | - | ||||||||||||||||||||||||
2668 | break; | - | ||||||||||||||||||||||||
2669 | - | |||||||||||||||||||||||||
2670 | case 's': | - | ||||||||||||||||||||||||
2671 | used = true; | - | ||||||||||||||||||||||||
2672 | repeat = qMin(repeat, 2); | - | ||||||||||||||||||||||||
2673 | switch (repeat) { | - | ||||||||||||||||||||||||
2674 | case 1: | - | ||||||||||||||||||||||||
2675 | result.append(m_data->longLongToString(time.second())); | - | ||||||||||||||||||||||||
2676 | break; | - | ||||||||||||||||||||||||
2677 | case 2: | - | ||||||||||||||||||||||||
2678 | result.append(m_data->longLongToString(time.second(), -1, 10, 2, QLocaleData::ZeroPadded)); | - | ||||||||||||||||||||||||
2679 | break; | - | ||||||||||||||||||||||||
2680 | } | - | ||||||||||||||||||||||||
2681 | break; | - | ||||||||||||||||||||||||
2682 | - | |||||||||||||||||||||||||
2683 | case 'a': | - | ||||||||||||||||||||||||
2684 | used = true; | - | ||||||||||||||||||||||||
2685 | if (i + 1 < format.length() && format.at(i + 1).unicode() == 'p') { | - | ||||||||||||||||||||||||
2686 | repeat = 2; | - | ||||||||||||||||||||||||
2687 | } else { | - | ||||||||||||||||||||||||
2688 | repeat = 1; | - | ||||||||||||||||||||||||
2689 | } | - | ||||||||||||||||||||||||
2690 | result.append(time.hour() < 12 ? q->amText().toLower() : q->pmText().toLower()); | - | ||||||||||||||||||||||||
2691 | break; | - | ||||||||||||||||||||||||
2692 | - | |||||||||||||||||||||||||
2693 | case 'A': | - | ||||||||||||||||||||||||
2694 | used = true; | - | ||||||||||||||||||||||||
2695 | if (i + 1 < format.length() && format.at(i + 1).unicode() == 'P') { | - | ||||||||||||||||||||||||
2696 | repeat = 2; | - | ||||||||||||||||||||||||
2697 | } else { | - | ||||||||||||||||||||||||
2698 | repeat = 1; | - | ||||||||||||||||||||||||
2699 | } | - | ||||||||||||||||||||||||
2700 | result.append(time.hour() < 12 ? q->amText().toUpper() : q->pmText().toUpper()); | - | ||||||||||||||||||||||||
2701 | break; | - | ||||||||||||||||||||||||
2702 | - | |||||||||||||||||||||||||
2703 | case 'z': | - | ||||||||||||||||||||||||
2704 | used = true; | - | ||||||||||||||||||||||||
2705 | if (repeat >= 3) { | - | ||||||||||||||||||||||||
2706 | repeat = 3; | - | ||||||||||||||||||||||||
2707 | } else { | - | ||||||||||||||||||||||||
2708 | repeat = 1; | - | ||||||||||||||||||||||||
2709 | } | - | ||||||||||||||||||||||||
2710 | switch (repeat) { | - | ||||||||||||||||||||||||
2711 | case 1: | - | ||||||||||||||||||||||||
2712 | result.append(m_data->longLongToString(time.msec())); | - | ||||||||||||||||||||||||
2713 | break; | - | ||||||||||||||||||||||||
2714 | case 3: | - | ||||||||||||||||||||||||
2715 | result.append(m_data->longLongToString(time.msec(), -1, 10, 3, QLocaleData::ZeroPadded)); | - | ||||||||||||||||||||||||
2716 | break; | - | ||||||||||||||||||||||||
2717 | } | - | ||||||||||||||||||||||||
2718 | break; | - | ||||||||||||||||||||||||
2719 | - | |||||||||||||||||||||||||
2720 | case 't': | - | ||||||||||||||||||||||||
2721 | used = true; | - | ||||||||||||||||||||||||
2722 | repeat = 1; | - | ||||||||||||||||||||||||
2723 | // If we have a QDateTime use the time spec otherwise use the current system tzname | - | ||||||||||||||||||||||||
2724 | if (formatDate) { | - | ||||||||||||||||||||||||
2725 | result.append(datetime.timeZoneAbbreviation()); | - | ||||||||||||||||||||||||
2726 | } else { | - | ||||||||||||||||||||||||
2727 | result.append(QDateTime::currentDateTime().timeZoneAbbreviation()); | - | ||||||||||||||||||||||||
2728 | } | - | ||||||||||||||||||||||||
2729 | break; | - | ||||||||||||||||||||||||
2730 | - | |||||||||||||||||||||||||
2731 | default: | - | ||||||||||||||||||||||||
2732 | break; | - | ||||||||||||||||||||||||
2733 | } | - | ||||||||||||||||||||||||
2734 | } | - | ||||||||||||||||||||||||
2735 | if (!used) { | - | ||||||||||||||||||||||||
2736 | result.append(QString(repeat, c)); | - | ||||||||||||||||||||||||
2737 | } | - | ||||||||||||||||||||||||
2738 | i += repeat; | - | ||||||||||||||||||||||||
2739 | } | - | ||||||||||||||||||||||||
2740 | - | |||||||||||||||||||||||||
2741 | return result; | - | ||||||||||||||||||||||||
2742 | } | - | ||||||||||||||||||||||||
2743 | - | |||||||||||||||||||||||||
2744 | QString QLocaleData::doubleToString(double d, int precision, DoubleForm form, | - | ||||||||||||||||||||||||
2745 | int width, unsigned flags) const | - | ||||||||||||||||||||||||
2746 | { | - | ||||||||||||||||||||||||
2747 | return doubleToString(m_zero, m_plus, m_minus, m_exponential, m_group, m_decimal, | - | ||||||||||||||||||||||||
2748 | d, precision, form, width, flags); | - | ||||||||||||||||||||||||
2749 | } | - | ||||||||||||||||||||||||
2750 | - | |||||||||||||||||||||||||
2751 | QString QLocaleData::doubleToString(const QChar _zero, const QChar plus, const QChar minus, | - | ||||||||||||||||||||||||
2752 | const QChar exponential, const QChar group, const QChar decimal, | - | ||||||||||||||||||||||||
2753 | double d, int precision, DoubleForm form, int width, unsigned flags) | - | ||||||||||||||||||||||||
2754 | { | - | ||||||||||||||||||||||||
2755 | if (precision != QLocale::FloatingPointShortest && precision < 0)
| 168-110478 | ||||||||||||||||||||||||
2756 | precision = 6; executed 97694 times by 9 tests: precision = 6; Executed by:
| 97694 | ||||||||||||||||||||||||
2757 | if (width < 0)
| 7345-103301 | ||||||||||||||||||||||||
2758 | width = 0; executed 7345 times by 49 tests: width = 0; Executed by:
| 7345 | ||||||||||||||||||||||||
2759 | - | |||||||||||||||||||||||||
2760 | bool negative = false; | - | ||||||||||||||||||||||||
bool special_number= false; | ||||||||||||||||||||||||||
2761 | QString num_str; | - | ||||||||||||||||||||||||
2762 | - | |||||||||||||||||||||||||
2763 | if (qt_is_inf(d)) { | - | ||||||||||||||||||||||||
num_str = QString::fromLatin1("inf"); | ||||||||||||||||||||||||||
special_number = trueint decpt; | ||||||||||||||||||||||||||
2764 | negativeint bufSize = d < 01; | - | ||||||||||||||||||||||||
2765 | } elseif (qt_is_nan(d)) {
| 168-110478 | ||||||||||||||||||||||||
num_str = QString
| ||||||||||||||||||||||||||
special_number = true;
| ||||||||||||||||||||||||||
}
| ||||||||||||||||||||||||||
if (!special_number
| ||||||||||||||||||||||||||
2766 | { executed 168 times by 13 tests: bufSize += DoubleMaxSignificant; Executed by:
| 168 | ||||||||||||||||||||||||
int decpt, sign; executed 168 times by 13 tests: bufSize += DoubleMaxSignificant; Executed by:
| ||||||||||||||||||||||||||
QString digits; executed 168 times by 13 tests: bufSize += DoubleMaxSignificant; Executed by:
| ||||||||||||||||||||||||||
int mode executed 168 times by 13 tests: bufSize += DoubleMaxSignificant;bufSize += DoubleMaxSignificant; Executed by:
executed 168 times by 13 tests: bufSize += DoubleMaxSignificant; Executed by:
| ||||||||||||||||||||||||||
2767 | else if (form == DFDecimal) mode = 3// optimize for numbers between -512k and 512k
| 2237-108241 | ||||||||||||||||||||||||
2768 | executed 2237 times by 20 tests: bufSize += ((d > (1 << 19) || d < -(1 << 19)) ? DoubleMaxDigitsBeforeDecimal : 6) + precision; Executed by:
executed 2237 times by 20 tests: bufSize += ((d > (1 << 19) || d < -(1 << 19)) ? DoubleMaxDigitsBeforeDecimal : 6) + precision; Executed by:
| 35-2237 | ||||||||||||||||||||||||
2769 | precision executed 2237 times by 20 tests: ;bufSize += ((d > (1 << 19) || d < -(1 << 19)) ? DoubleMaxDigitsBeforeDecimal : 6) + precision; Executed by:
executed 2237 times by 20 tests: bufSize += ((d > (1 << 19) || d < -(1 << 19)) ? DoubleMaxDigitsBeforeDecimal : 6) + precision; Executed by:
| 2237 | ||||||||||||||||||||||||
2770 | else mode =// Add extra digit due to different interpretations of precision. Also, "nan" has to fit. | - | ||||||||||||||||||||||||
2771 | executed 108241 times by 36 tests: bufSize += qMax(2;bufSize += qMax(2, precision) + 1; Executed by:
executed 108241 times by 36 tests: bufSize += qMax(2, precision) + 1; Executed by:
| 108241 | ||||||||||||||||||||||||
int pr = executed 108241 times by 36 tests: , precision;bufSize += qMax(2, precision) + 1; Executed by:
executed 108241 times by 36 tests: bufSize += qMax(2, precision) + 1; Executed by:
| ||||||||||||||||||||||||||
if (form == DFExponent executed 108241 times by 36 tests: ) ++pr;bufSize += qMax(2, precision) + 1; Executed by:
executed 108241 times by 36 tests: bufSize += qMax(2, precision) + 1; Executed by:
| ||||||||||||||||||||||||||
char *rve = 0 executed 108241 times by 36 tests: + 1;bufSize += qMax(2, precision) + 1; Executed by:
executed 108241 times by 36 tests: bufSize += qMax(2, precision) + 1; Executed by:
| ||||||||||||||||||||||||||
2772 | - | |||||||||||||||||||||||||
2773 | QVarLengthArray<char*buff = 0; | - | ||||||||||||||||||||||||
QT_TRY { | ||||||||||||||||||||||||||
digits = QLatin1String> buf(qdtoabufSize); | ||||||||||||||||||||||||||
2774 | int length; | - | ||||||||||||||||||||||||
2775 | - | |||||||||||||||||||||||||
2776 | doubleToAscii(d, modeform, prprecision, &decptbuf.data(), bufSize, &signnegative, &rvelength, &buff)); | - | ||||||||||||||||||||||||
} QT_CATCH(...) {decpt); | ||||||||||||||||||||||||||
2777 | - | |||||||||||||||||||||||||
2778 | if (buff !=qstrncmp(buf.data(), "inf", 3) == 0 || qstrncmp(buf.data(), "nan", 3) free== 0) {
| 262-110096 | ||||||||||||||||||||||||
2779 | num_str = QString::fromLatin1(buffbuf.data(), length); | - | ||||||||||||||||||||||||
2780 | QT_RETHROW;} if (buff != 0) executed 812 times by 4 tests: end of block Executed by:
| 812 | ||||||||||||||||||||||||
free executed 812 times by 4 tests: else { // Handle normal numbersend of block Executed by:
executed 812 times by 4 tests: end of block Executed by:
| ||||||||||||||||||||||||||
2781 | QString digits = QString::fromLatin1(buffbuf.data(), length); | - | ||||||||||||||||||||||||
2782 | - | |||||||||||||||||||||||||
2783 | if (_zero.unicode() != '0') {
| 1-109833 | ||||||||||||||||||||||||
2784 | ushort z = _zero.unicode() - '0'; | - | ||||||||||||||||||||||||
2785 | for (int i = 0; i < digits.length(); ++i)
| 1-7 | ||||||||||||||||||||||||
2786 | reinterpret_cast<ushort *>(digits.data())[i] += z; executed 7 times by 1 test: reinterpret_cast<ushort *>(digits.data())[i] += z; Executed by:
| 7 | ||||||||||||||||||||||||
2787 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||
2788 | - | |||||||||||||||||||||||||
2789 | bool always_show_decpt = (flags & Alternate || flags & ForcePoint);
| 0-105220 | ||||||||||||||||||||||||
2790 | switch (form) { | - | ||||||||||||||||||||||||
2791 | case DFExponent: { executed 17 times by 3 tests: case DFExponent: Executed by:
| 17 | ||||||||||||||||||||||||
2792 | num_str = exponentForm(_zero, decimal, exponential, group, plus, minus, | - | ||||||||||||||||||||||||
2793 | digits, decpt, precision, PMDecimalDigits, | - | ||||||||||||||||||||||||
2794 | always_show_decpt, flags & ZeroPadExponent); | - | ||||||||||||||||||||||||
2795 | break; executed 17 times by 3 tests: break; Executed by:
| 17 | ||||||||||||||||||||||||
2796 | } | - | ||||||||||||||||||||||||
2797 | case DFDecimal: { executed 2237 times by 20 tests: case DFDecimal: Executed by:
| 2237 | ||||||||||||||||||||||||
2798 | num_str = decimalForm(_zero, decimal, group, | - | ||||||||||||||||||||||||
2799 | digits, decpt, precision, PMDecimalDigits, | - | ||||||||||||||||||||||||
2800 | always_show_decpt, flags & ThousandsGroup); | - | ||||||||||||||||||||||||
2801 | break; executed 2237 times by 20 tests: break; Executed by:
| 2237 | ||||||||||||||||||||||||
2802 | } | - | ||||||||||||||||||||||||
2803 | case DFSignificantDigits: { executed 107580 times by 42 tests: case DFSignificantDigits: Executed by:
| 107580 | ||||||||||||||||||||||||
2804 | PrecisionMode mode = (flags & Alternate) ?
| 4610-102970 | ||||||||||||||||||||||||
2805 | PMSignificantDigits : PMChopTrailingZeros; | - | ||||||||||||||||||||||||
2806 | - | |||||||||||||||||||||||||
2807 | int cutoff = precision < 0 ? 6 : precision;
| 144-107436 | ||||||||||||||||||||||||
2808 | // Find out which representation is shorter | - | ||||||||||||||||||||||||
2809 |
| 1-107436 | ||||||||||||||||||||||||
2810 | cutoff = digits.length() + 4; // 'e', '+'/'-', one digit exponent | - | ||||||||||||||||||||||||
2811 |
| 0-143 | ||||||||||||||||||||||||
2812 | ++cutoff; | - | ||||||||||||||||||||||||
2813 | } else { executed 143 times by 12 tests: end of block Executed by:
| 143 | ||||||||||||||||||||||||
2814 | cutoff += decpt > 100 ? 2 : 1;
| 0 | ||||||||||||||||||||||||
2815 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2816 | if (!always_show_decpt && digits.length() > decpt)
| 0-143 | ||||||||||||||||||||||||
2817 | ++cutoff executed 56 times by 6 tests: ; // decpt shown in exponent form, but not in decimal form++cutoff; Executed by:
executed 56 times by 6 tests: ++cutoff; Executed by:
| 56 | ||||||||||||||||||||||||
2818 | executed 143 times by 12 tests: }end of block Executed by:
executed 143 times by 12 tests: end of block Executed by:
| 143 | ||||||||||||||||||||||||
2819 | - | |||||||||||||||||||||||||
2820 | if (decpt != digits.length() && (decpt <= -4 || decpt > precisioncutoff))
| 1897-54011 | ||||||||||||||||||||||||
2821 | num_str = exponentForm(_zero, decimal, exponential, group, plus, minus, executed 6335 times by 5 tests: num_str = exponentForm(_zero, decimal, exponential, group, plus, minus, digits, decpt, precision, mode, always_show_decpt, flags & ZeroPadExponent); Executed by:
| 6335 | ||||||||||||||||||||||||
2822 | digits, decpt, precision, mode, executed 6335 times by 5 tests: num_str = exponentForm(_zero, decimal, exponential, group, plus, minus, digits, decpt, precision, mode, always_show_decpt, flags & ZeroPadExponent); Executed by:
| 6335 | ||||||||||||||||||||||||
2823 | always_show_decpt, flags & ZeroPadExponent); executed 6335 times by 5 tests: num_str = exponentForm(_zero, decimal, exponential, group, plus, minus, digits, decpt, precision, mode, always_show_decpt, flags & ZeroPadExponent); Executed by:
| 6335 | ||||||||||||||||||||||||
2824 | else | - | ||||||||||||||||||||||||
2825 | num_str = decimalForm(_zero, decimal, group, executed 101245 times by 42 tests: num_str = decimalForm(_zero, decimal, group, digits, decpt, precision, mode, always_show_decpt, flags & ThousandsGroup); Executed by:
| 101245 | ||||||||||||||||||||||||
2826 | digits, decpt, precision, mode, executed 101245 times by 42 tests: num_str = decimalForm(_zero, decimal, group, digits, decpt, precision, mode, always_show_decpt, flags & ThousandsGroup); Executed by:
| 101245 | ||||||||||||||||||||||||
2827 | always_show_decpt, flags & ThousandsGroup); executed 101245 times by 42 tests: num_str = decimalForm(_zero, decimal, group, digits, decpt, precision, mode, always_show_decpt, flags & ThousandsGroup); Executed by:
| 101245 | ||||||||||||||||||||||||
2828 | break; executed 107580 times by 42 tests: break; Executed by:
| 107580 | ||||||||||||||||||||||||
2829 | } | - | ||||||||||||||||||||||||
2830 | } | - | ||||||||||||||||||||||||
2831 | - | |||||||||||||||||||||||||
2832 | negative = sign != 0 && !if (isZero(d);
| 38415-71419 | ||||||||||||||||||||||||
}
| ||||||||||||||||||||||||||
2833 | negative = false; executed 38415 times by 24 tests: negative = false; Executed by:
| 38415 | ||||||||||||||||||||||||
2834 | - | |||||||||||||||||||||||||
2835 | // pad with zeros. LeftAdjusted overrides this flag). Also, we don't | - | ||||||||||||||||||||||||
2836 | // pad special numbers | - | ||||||||||||||||||||||||
2837 | if (flags & QLocaleData::ZeroPadded && !(flags & QLocaleData::LeftAdjusted)
| 2304-105221 | ||||||||||||||||||||||||
&& !special_number)
| ||||||||||||||||||||||||||
2838 | int num_pad_chars = width - num_str.length(); | - | ||||||||||||||||||||||||
2839 | // leave space for the sign | - | ||||||||||||||||||||||||
2840 | if (negative
| 66-2243 | ||||||||||||||||||||||||
2841 | || flags & QLocaleData::AlwaysShowSign
| 1120-1123 | ||||||||||||||||||||||||
2842 | || flags & QLocaleData::BlankBeforePositive)
| 560-563 | ||||||||||||||||||||||||
2843 | --num_pad_chars; executed 1746 times by 1 test: --num_pad_chars; Executed by:
| 1746 | ||||||||||||||||||||||||
2844 | - | |||||||||||||||||||||||||
2845 | for (int i = 0; i < num_pad_chars; ++i)
| 2309-23653 | ||||||||||||||||||||||||
2846 | num_str.prepend(_zero); executed 23653 times by 1 test: num_str.prepend(_zero); Executed by:
| 23653 | ||||||||||||||||||||||||
2847 | } executed 2309 times by 1 test: end of block Executed by:
| 2309 | ||||||||||||||||||||||||
2848 | } executed 109834 times by 55 tests: end of block Executed by:
| 109834 | ||||||||||||||||||||||||
2849 | - | |||||||||||||||||||||||||
2850 | // add sign | - | ||||||||||||||||||||||||
2851 | if (negative)
| 22427-88219 | ||||||||||||||||||||||||
2852 | num_str.prepend(minus); executed 22427 times by 15 tests: num_str.prepend(minus); Executed by:
| 22427 | ||||||||||||||||||||||||
2853 | else if (flags & QLocaleData::AlwaysShowSign)
| 4738-83481 | ||||||||||||||||||||||||
2854 | num_str.prepend(plus); executed 4738 times by 2 tests: num_str.prepend(plus); Executed by:
| 4738 | ||||||||||||||||||||||||
2855 | else if (flags & QLocaleData::BlankBeforePositive)
| 2368-81113 | ||||||||||||||||||||||||
2856 | num_str.prepend(QLatin1Char(' ')); executed 2368 times by 1 test: num_str.prepend(QLatin1Char(' ')); Executed by:
| 2368 | ||||||||||||||||||||||||
2857 | - | |||||||||||||||||||||||||
2858 | if (flags & QLocaleData::CapitalEorX)
| 4999-105647 | ||||||||||||||||||||||||
2859 | num_str = num_str.toUpper(); executed 4999 times by 2 tests: num_str = num_str.toUpper(); Executed by:
| 4999 | ||||||||||||||||||||||||
2860 | - | |||||||||||||||||||||||||
2861 | return num_str; executed 110646 times by 55 tests: return num_str; Executed by:
| 110646 | ||||||||||||||||||||||||
2862 | } | - | ||||||||||||||||||||||||
2863 | - | |||||||||||||||||||||||||
2864 | QString QLocaleData::longLongToString(qlonglong l, int precision, | - | ||||||||||||||||||||||||
2865 | int base, int width, | - | ||||||||||||||||||||||||
2866 | unsigned flags) const | - | ||||||||||||||||||||||||
2867 | { | - | ||||||||||||||||||||||||
2868 | return longLongToString(m_zero, m_group, m_plus, m_minus, | - | ||||||||||||||||||||||||
2869 | l, precision, base, width, flags); | - | ||||||||||||||||||||||||
2870 | } | - | ||||||||||||||||||||||||
2871 | - | |||||||||||||||||||||||||
2872 | QString QLocaleData::longLongToString(const QChar zero, const QChar group, | - | ||||||||||||||||||||||||
2873 | const QChar plus, const QChar minus, | - | ||||||||||||||||||||||||
2874 | qlonglong l, int precision, | - | ||||||||||||||||||||||||
2875 | int base, int width, | - | ||||||||||||||||||||||||
2876 | unsigned flags) | - | ||||||||||||||||||||||||
2877 | { | - | ||||||||||||||||||||||||
2878 | bool precision_not_specified = false; | - | ||||||||||||||||||||||||
2879 | if (precision == -1) { | - | ||||||||||||||||||||||||
2880 | precision_not_specified = true; | - | ||||||||||||||||||||||||
2881 | precision = 1; | - | ||||||||||||||||||||||||
2882 | } | - | ||||||||||||||||||||||||
2883 | - | |||||||||||||||||||||||||
2884 | bool negative = l < 0; | - | ||||||||||||||||||||||||
2885 | if (base != 10) { | - | ||||||||||||||||||||||||
2886 | // these are not supported by sprintf for octal and hex | - | ||||||||||||||||||||||||
2887 | flags &= ~AlwaysShowSign; | - | ||||||||||||||||||||||||
2888 | flags &= ~BlankBeforePositive; | - | ||||||||||||||||||||||||
2889 | negative = false; // neither are negative numbers | - | ||||||||||||||||||||||||
2890 | } | - | ||||||||||||||||||||||||
2891 | - | |||||||||||||||||||||||||
2892 | QString num_str; | - | ||||||||||||||||||||||||
2893 | if (base == 10) | - | ||||||||||||||||||||||||
2894 | num_str = qlltoa(l, base, zero); | - | ||||||||||||||||||||||||
2895 | else | - | ||||||||||||||||||||||||
2896 | num_str = qulltoa(l, base, zero); | - | ||||||||||||||||||||||||
2897 | - | |||||||||||||||||||||||||
2898 | uint cnt_thousand_sep = 0; | - | ||||||||||||||||||||||||
2899 | if (flags & ThousandsGroup && base == 10) { | - | ||||||||||||||||||||||||
2900 | for (int i = num_str.length() - 3; i > 0; i -= 3) { | - | ||||||||||||||||||||||||
2901 | num_str.insert(i, group); | - | ||||||||||||||||||||||||
2902 | ++cnt_thousand_sep; | - | ||||||||||||||||||||||||
2903 | } | - | ||||||||||||||||||||||||
2904 | } | - | ||||||||||||||||||||||||
2905 | - | |||||||||||||||||||||||||
2906 | for (int i = num_str.length()/* - cnt_thousand_sep*/; i < precision; ++i) | - | ||||||||||||||||||||||||
2907 | num_str.prepend(base == 10 ? zero : QChar::fromLatin1('0')); | - | ||||||||||||||||||||||||
2908 | - | |||||||||||||||||||||||||
2909 | if ((flags & Alternate || flags & ShowBase) | - | ||||||||||||||||||||||||
2910 | && base == 8 | - | ||||||||||||||||||||||||
2911 | && (num_str.isEmpty() || num_str[0].unicode() != QLatin1Char('0'))) | - | ||||||||||||||||||||||||
2912 | num_str.prepend(QLatin1Char('0')); | - | ||||||||||||||||||||||||
2913 | - | |||||||||||||||||||||||||
2914 | // LeftAdjusted overrides this flag ZeroPadded. sprintf only padds | - | ||||||||||||||||||||||||
2915 | // when precision is not specified in the format string | - | ||||||||||||||||||||||||
2916 | bool zero_padded = flags & ZeroPadded | - | ||||||||||||||||||||||||
2917 | && !(flags & LeftAdjusted) | - | ||||||||||||||||||||||||
2918 | && precision_not_specified; | - | ||||||||||||||||||||||||
2919 | - | |||||||||||||||||||||||||
2920 | if (zero_padded) { | - | ||||||||||||||||||||||||
2921 | int num_pad_chars = width - num_str.length(); | - | ||||||||||||||||||||||||
2922 | - | |||||||||||||||||||||||||
2923 | // leave space for the sign | - | ||||||||||||||||||||||||
2924 | if (negative | - | ||||||||||||||||||||||||
2925 | || flags & AlwaysShowSign | - | ||||||||||||||||||||||||
2926 | || flags & BlankBeforePositive) | - | ||||||||||||||||||||||||
2927 | --num_pad_chars; | - | ||||||||||||||||||||||||
2928 | - | |||||||||||||||||||||||||
2929 | // leave space for optional '0x' in hex form | - | ||||||||||||||||||||||||
2930 | if (base == 16 && (flags & Alternate || flags & ShowBase)) | - | ||||||||||||||||||||||||
2931 | num_pad_chars -= 2; | - | ||||||||||||||||||||||||
2932 | // leave space for optional '0b' in binary form | - | ||||||||||||||||||||||||
2933 | else if (base == 2 && (flags & Alternate || flags & ShowBase)) | - | ||||||||||||||||||||||||
2934 | num_pad_chars -= 2; | - | ||||||||||||||||||||||||
2935 | - | |||||||||||||||||||||||||
2936 | for (int i = 0; i < num_pad_chars; ++i) | - | ||||||||||||||||||||||||
2937 | num_str.prepend(base == 10 ? zero : QChar::fromLatin1('0')); | - | ||||||||||||||||||||||||
2938 | } | - | ||||||||||||||||||||||||
2939 | - | |||||||||||||||||||||||||
2940 | if (flags & CapitalEorX) | - | ||||||||||||||||||||||||
2941 | num_str = num_str.toUpper(); | - | ||||||||||||||||||||||||
2942 | - | |||||||||||||||||||||||||
2943 | if (base == 16 && (flags & Alternate || flags & ShowBase)) | - | ||||||||||||||||||||||||
2944 | num_str.prepend(QLatin1String(flags & UppercaseBase ? "0X" : "0x")); | - | ||||||||||||||||||||||||
2945 | if (base == 2 && (flags & Alternate || flags & ShowBase)) | - | ||||||||||||||||||||||||
2946 | num_str.prepend(QLatin1String(flags & UppercaseBase ? "0B" : "0b")); | - | ||||||||||||||||||||||||
2947 | - | |||||||||||||||||||||||||
2948 | // add sign | - | ||||||||||||||||||||||||
2949 | if (negative) | - | ||||||||||||||||||||||||
2950 | num_str.prepend(minus); | - | ||||||||||||||||||||||||
2951 | else if (flags & AlwaysShowSign) | - | ||||||||||||||||||||||||
2952 | num_str.prepend(plus); | - | ||||||||||||||||||||||||
2953 | else if (flags & BlankBeforePositive) | - | ||||||||||||||||||||||||
2954 | num_str.prepend(QLatin1Char(' ')); | - | ||||||||||||||||||||||||
2955 | - | |||||||||||||||||||||||||
2956 | return num_str; | - | ||||||||||||||||||||||||
2957 | } | - | ||||||||||||||||||||||||
2958 | - | |||||||||||||||||||||||||
2959 | QString QLocaleData::unsLongLongToString(qulonglong l, int precision, | - | ||||||||||||||||||||||||
2960 | int base, int width, | - | ||||||||||||||||||||||||
2961 | unsigned flags) const | - | ||||||||||||||||||||||||
2962 | { | - | ||||||||||||||||||||||||
2963 | return unsLongLongToString(m_zero, m_group, m_plus, | - | ||||||||||||||||||||||||
2964 | l, precision, base, width, flags); | - | ||||||||||||||||||||||||
2965 | } | - | ||||||||||||||||||||||||
2966 | - | |||||||||||||||||||||||||
2967 | QString QLocaleData::unsLongLongToString(const QChar zero, const QChar group, | - | ||||||||||||||||||||||||
2968 | const QChar plus, | - | ||||||||||||||||||||||||
2969 | qulonglong l, int precision, | - | ||||||||||||||||||||||||
2970 | int base, int width, | - | ||||||||||||||||||||||||
2971 | unsigned flags) | - | ||||||||||||||||||||||||
2972 | { | - | ||||||||||||||||||||||||
2973 | bool precision_not_specified = false; | - | ||||||||||||||||||||||||
2974 | if (precision == -1) { | - | ||||||||||||||||||||||||
2975 | precision_not_specified = true; | - | ||||||||||||||||||||||||
2976 | precision = 1; | - | ||||||||||||||||||||||||
2977 | } | - | ||||||||||||||||||||||||
2978 | - | |||||||||||||||||||||||||
2979 | QString num_str = qulltoa(l, base, zero); | - | ||||||||||||||||||||||||
2980 | - | |||||||||||||||||||||||||
2981 | uint cnt_thousand_sep = 0; | - | ||||||||||||||||||||||||
2982 | if (flags & ThousandsGroup && base == 10) { | - | ||||||||||||||||||||||||
2983 | for (int i = num_str.length() - 3; i > 0; i -=3) { | - | ||||||||||||||||||||||||
2984 | num_str.insert(i, group); | - | ||||||||||||||||||||||||
2985 | ++cnt_thousand_sep; | - | ||||||||||||||||||||||||
2986 | } | - | ||||||||||||||||||||||||
2987 | } | - | ||||||||||||||||||||||||
2988 | - | |||||||||||||||||||||||||
2989 | for (int i = num_str.length()/* - cnt_thousand_sep*/; i < precision; ++i) | - | ||||||||||||||||||||||||
2990 | num_str.prepend(base == 10 ? zero : QChar::fromLatin1('0')); | - | ||||||||||||||||||||||||
2991 | - | |||||||||||||||||||||||||
2992 | if ((flags & Alternate || flags & ShowBase) | - | ||||||||||||||||||||||||
2993 | && base == 8 | - | ||||||||||||||||||||||||
2994 | && (num_str.isEmpty() || num_str[0].unicode() != QLatin1Char('0'))) | - | ||||||||||||||||||||||||
2995 | num_str.prepend(QLatin1Char('0')); | - | ||||||||||||||||||||||||
2996 | - | |||||||||||||||||||||||||
2997 | // LeftAdjusted overrides this flag ZeroPadded. sprintf only padds | - | ||||||||||||||||||||||||
2998 | // when precision is not specified in the format string | - | ||||||||||||||||||||||||
2999 | bool zero_padded = flags & ZeroPadded | - | ||||||||||||||||||||||||
3000 | && !(flags & LeftAdjusted) | - | ||||||||||||||||||||||||
3001 | && precision_not_specified; | - | ||||||||||||||||||||||||
3002 | - | |||||||||||||||||||||||||
3003 | if (zero_padded) { | - | ||||||||||||||||||||||||
3004 | int num_pad_chars = width - num_str.length(); | - | ||||||||||||||||||||||||
3005 | - | |||||||||||||||||||||||||
3006 | // leave space for optional '0x' in hex form | - | ||||||||||||||||||||||||
3007 | if (base == 16 && flags & Alternate) | - | ||||||||||||||||||||||||
3008 | num_pad_chars -= 2; | - | ||||||||||||||||||||||||
3009 | // leave space for optional '0b' in binary form | - | ||||||||||||||||||||||||
3010 | else if (base == 2 && flags & Alternate) | - | ||||||||||||||||||||||||
3011 | num_pad_chars -= 2; | - | ||||||||||||||||||||||||
3012 | - | |||||||||||||||||||||||||
3013 | for (int i = 0; i < num_pad_chars; ++i) | - | ||||||||||||||||||||||||
3014 | num_str.prepend(base == 10 ? zero : QChar::fromLatin1('0')); | - | ||||||||||||||||||||||||
3015 | } | - | ||||||||||||||||||||||||
3016 | - | |||||||||||||||||||||||||
3017 | if (flags & CapitalEorX) | - | ||||||||||||||||||||||||
3018 | num_str = num_str.toUpper(); | - | ||||||||||||||||||||||||
3019 | - | |||||||||||||||||||||||||
3020 | if (base == 16 && (flags & Alternate || flags & ShowBase)) | - | ||||||||||||||||||||||||
3021 | num_str.prepend(QLatin1String(flags & UppercaseBase ? "0X" : "0x")); | - | ||||||||||||||||||||||||
3022 | else if (base == 2 && (flags & Alternate || flags & ShowBase)) | - | ||||||||||||||||||||||||
3023 | num_str.prepend(QLatin1String(flags & UppercaseBase ? "0B" : "0b")); | - | ||||||||||||||||||||||||
3024 | - | |||||||||||||||||||||||||
3025 | // add sign | - | ||||||||||||||||||||||||
3026 | if (flags & AlwaysShowSign) | - | ||||||||||||||||||||||||
3027 | num_str.prepend(plus); | - | ||||||||||||||||||||||||
3028 | else if (flags & BlankBeforePositive) | - | ||||||||||||||||||||||||
3029 | num_str.prepend(QLatin1Char(' ')); | - | ||||||||||||||||||||||||
3030 | - | |||||||||||||||||||||||||
3031 | return num_str; | - | ||||||||||||||||||||||||
3032 | } | - | ||||||||||||||||||||||||
3033 | - | |||||||||||||||||||||||||
3034 | /* | - | ||||||||||||||||||||||||
3035 | Converts a number in locale to its representation in the C locale. | - | ||||||||||||||||||||||||
3036 | Only has to guarantee that a string that is a correct representation of | - | ||||||||||||||||||||||||
3037 | a number will be converted. If junk is passed in, junk will be passed | - | ||||||||||||||||||||||||
3038 | out and the error will be detected during the actual conversion to a | - | ||||||||||||||||||||||||
3039 | number. We can't detect junk here, since we don't even know the base | - | ||||||||||||||||||||||||
3040 | of the number. | - | ||||||||||||||||||||||||
3041 | */ | - | ||||||||||||||||||||||||
3042 | bool QLocaleData::numberToCLocale(const QChar *str, int len, GroupSeparatorMode group_sep_modeQLocale::NumberOptions number_options, | - | ||||||||||||||||||||||||
3043 | CharBuff *result) const | - | ||||||||||||||||||||||||
3044 | { | - | ||||||||||||||||||||||||
3045 | const QChar *uc = str; | - | ||||||||||||||||||||||||
3046 | int l = len; | - | ||||||||||||||||||||||||
3047 | int idx = 0; | - | ||||||||||||||||||||||||
3048 | - | |||||||||||||||||||||||||
3049 | // Skip whitespace | - | ||||||||||||||||||||||||
3050 | while (idx < l && uc[idx].isSpace())
| 268-177012 | ||||||||||||||||||||||||
3051 | ++idx; executed 268 times by 4 tests: ++idx; Executed by:
| 268 | ||||||||||||||||||||||||
3052 | if (idx == l)
| 4310-176744 | ||||||||||||||||||||||||
3053 | return false; executed 4310 times by 11 tests: return false; Executed by:
| 4310 | ||||||||||||||||||||||||
3054 | - | |||||||||||||||||||||||||
3055 | // Check trailing whitespace | - | ||||||||||||||||||||||||
3056 | for (; idx < l; --l) {
| 0-176919 | ||||||||||||||||||||||||
3057 | if (!uc[l - 1].isSpace())
| 175-176744 | ||||||||||||||||||||||||
3058 | break; executed 176744 times by 92 tests: break; Executed by:
| 176744 | ||||||||||||||||||||||||
3059 | } executed 175 times by 5 tests: end of block Executed by:
| 175 | ||||||||||||||||||||||||
3060 | - | |||||||||||||||||||||||||
3061 | int group_cnt = 0; // counts number of group chars | - | ||||||||||||||||||||||||
3062 | int decpt_idx = -1; | - | ||||||||||||||||||||||||
3063 | int last_separator_idx = -1; | - | ||||||||||||||||||||||||
3064 | int start_of_digits_idx = -1; | - | ||||||||||||||||||||||||
3065 | int exponent_idx = -1; | - | ||||||||||||||||||||||||
3066 | - | |||||||||||||||||||||||||
3067 | while (idx < l) {
| 175786-545999 | ||||||||||||||||||||||||
3068 | const QChar in = uc[idx]; | - | ||||||||||||||||||||||||
3069 | - | |||||||||||||||||||||||||
3070 | char out = digitToCLocale(in); | - | ||||||||||||||||||||||||
3071 | if (out == 0) {
| 209926-336073 | ||||||||||||||||||||||||
3072 | if (in == m_list)
| 0-209926 | ||||||||||||||||||||||||
3073 | out = ';'; never executed: out = ';'; | 0 | ||||||||||||||||||||||||
3074 | else if (in == m_percent)
| 4-209922 | ||||||||||||||||||||||||
3075 | out = '%'; executed 4 times by 2 tests: out = '%'; Executed by:
| 4 | ||||||||||||||||||||||||
3076 | // for handling base-x numbers | - | ||||||||||||||||||||||||
3077 | else if (in.unicode() >= 'A' && in.unicode() <= 'Z')
| 927-208995 | ||||||||||||||||||||||||
3078 | out = in.toLower().toLatin1(); executed 207440 times by 15 tests: out = in.toLower().toLatin1(); Executed by:
| 207440 | ||||||||||||||||||||||||
3079 | else if (in.unicode() >= 'a' && in.unicode() <= 'z')
| 5-1535 | ||||||||||||||||||||||||
3080 | out = in.toLatin1(); executed 1530 times by 27 tests: out = in.toLatin1(); Executed by:
| 1530 | ||||||||||||||||||||||||
3081 | else | - | ||||||||||||||||||||||||
3082 | break; executed 952 times by 16 tests: break; Executed by:
| 952 | ||||||||||||||||||||||||
3083 | } | - | ||||||||||||||||||||||||
3084 | - | |||||||||||||||||||||||||
3085 | if (group_sep_modenumber_options & QLocale::RejectLeadingZeroInExponent) {
| 0-545047 | ||||||||||||||||||||||||
3086 | if (out
| 0 | ||||||||||||||||||||||||
3087 | exponent_idx = idx; | - | ||||||||||||||||||||||||
3088 | } else if (exponent_idx != -1) { never executed: end of block
| 0 | ||||||||||||||||||||||||
3089 | if (out >= '1' && out <= '9')
| 0 | ||||||||||||||||||||||||
3090 | exponent_idx = -1; never executed: // leading digit is not 0, forget exponent_idxexponent_idx = -1; never executed: exponent_idx = -1; | 0 | ||||||||||||||||||||||||
3091 |
| 0 | ||||||||||||||||||||||||
3092 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
3093 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3094 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3095 | - | |||||||||||||||||||||||||
3096 | if (!(number_options & QLocale::RejectGroupSeparator))
| 43490-501557 | ||||||||||||||||||||||||
3097 | if (start_of_digits_idx == -1 && out >= '0' && out <= '9') {
| 231-25090 | ||||||||||||||||||||||||
3098 | start_of_digits_idx = idx; | - | ||||||||||||||||||||||||
3099 | } else if (out == ',') { executed 17820 times by 25 tests: end of block Executed by:
| 54-25616 | ||||||||||||||||||||||||
3100 | // Don't allow group chars after the decimal point | - | ||||||||||||||||||||||||
3101 | if (decpt_idx != -1)
| 0-54 | ||||||||||||||||||||||||
3102 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
3103 | - | |||||||||||||||||||||||||
3104 | // check distance from the last separator or from the beginning of the digits | - | ||||||||||||||||||||||||
3105 | // ### FIXME: Some locales allow other groupings! See https://en.wikipedia.org/wiki/Thousands_separator | - | ||||||||||||||||||||||||
3106 | if (last_separator_idx != -1 && idx - last_separator_idx != 4)
| 3-44 | ||||||||||||||||||||||||
3107 | return false; executed 3 times by 3 tests: return false; Executed by:
| 3 | ||||||||||||||||||||||||
3108 | if (last_separator_idx == -1 && (start_of_digits_idx == -1 || idx - start_of_digits_idx > 3))
| 0-44 | ||||||||||||||||||||||||
3109 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
3110 | - | |||||||||||||||||||||||||
3111 | last_separator_idx = idx; | - | ||||||||||||||||||||||||
3112 | ++group_cnt; | - | ||||||||||||||||||||||||
3113 | - | |||||||||||||||||||||||||
3114 | // don't add the group separator | - | ||||||||||||||||||||||||
3115 | ++idx; | - | ||||||||||||||||||||||||
3116 | continue; executed 51 times by 4 tests: continue; Executed by:
| 51 | ||||||||||||||||||||||||
3117 | } else if (out == '.' || out == 'e' || out == 'E') {
| 0-24766 | ||||||||||||||||||||||||
3118 | // Fail if more than one decimal point | - | ||||||||||||||||||||||||
3119 | if (out == '.' && decpt_idx != -1)
| 0-850 | ||||||||||||||||||||||||
3120 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
3121 | if (decpt_idx == -1)
| 0-858 | ||||||||||||||||||||||||
3122 | decpt_idx = idx; executed 858 times by 8 tests: decpt_idx = idx; Executed by:
| 858 | ||||||||||||||||||||||||
3123 | - | |||||||||||||||||||||||||
3124 | // check distance from the last separator | - | ||||||||||||||||||||||||
3125 | // ### FIXME: Some locales allow other groupings! See https://en.wikipedia.org/wiki/Thousands_separator | - | ||||||||||||||||||||||||
3126 | if (last_separator_idx != -1 && idx - last_separator_idx != 4)
| 3-840 | ||||||||||||||||||||||||
3127 | return false; executed 3 times by 2 tests: return false; Executed by:
| 3 | ||||||||||||||||||||||||
3128 | - | |||||||||||||||||||||||||
3129 | // stop processing separators | - | ||||||||||||||||||||||||
3130 | last_separator_idx = -1; | - | ||||||||||||||||||||||||
3131 | } executed 855 times by 8 tests: end of block Executed by:
| 855 | ||||||||||||||||||||||||
3132 | } executed 43433 times by 25 tests: end of block Executed by:
| 43433 | ||||||||||||||||||||||||
3133 | - | |||||||||||||||||||||||||
3134 | result->append(out); | - | ||||||||||||||||||||||||
3135 | - | |||||||||||||||||||||||||
3136 | ++idx; | - | ||||||||||||||||||||||||
3137 | } executed 544990 times by 92 tests: end of block Executed by:
| 544990 | ||||||||||||||||||||||||
3138 | - | |||||||||||||||||||||||||
3139 | if (group_sep_mode == ParseGroupSeparators)(!(number_options & QLocale::RejectGroupSeparator)) {
| 18106-158632 | ||||||||||||||||||||||||
3140 | // group separator post-processing | - | ||||||||||||||||||||||||
3141 | // did we end in a separator? | - | ||||||||||||||||||||||||
3142 | if (last_separator_idx + 1 == idx)
| 67-18039 | ||||||||||||||||||||||||
3143 | return false; executed 67 times by 3 tests: return false; Executed by:
| 67 | ||||||||||||||||||||||||
3144 | // were there enough digits since the last separator? | - | ||||||||||||||||||||||||
3145 | if (last_separator_idx != -1 && idx - last_separator_idx != 4)
| 3-18019 | ||||||||||||||||||||||||
3146 | return false; executed 3 times by 1 test: return false; Executed by:
| 3 | ||||||||||||||||||||||||
3147 | } executed 18036 times by 25 tests: end of block Executed by:
| 18036 | ||||||||||||||||||||||||
3148 | - | |||||||||||||||||||||||||
3149 | result->append('\0'); | - | ||||||||||||||||||||||||
3150 | return idx == l; executed 176668 times by 92 tests: return idx == l; Executed by:
| 176668 | ||||||||||||||||||||||||
3151 | } | - | ||||||||||||||||||||||||
3152 | - | |||||||||||||||||||||||||
3153 | bool QLocaleData::validateChars(const QString &str, NumberMode numMode, QByteArray *buff, | - | ||||||||||||||||||||||||
3154 | int decDigits, bool rejectGroupSeparatorsQLocale::NumberOptions number_options) const | - | ||||||||||||||||||||||||
3155 | { | - | ||||||||||||||||||||||||
3156 | buff->clear(); | - | ||||||||||||||||||||||||
3157 | buff->reserve(str.length()); | - | ||||||||||||||||||||||||
3158 | - | |||||||||||||||||||||||||
3159 | const bool scientific = numMode == DoubleScientificMode; | - | ||||||||||||||||||||||||
3160 | bool lastWasE = false; | - | ||||||||||||||||||||||||
3161 | bool lastWasDigit = false; | - | ||||||||||||||||||||||||
3162 | int eCnt = 0; | - | ||||||||||||||||||||||||
3163 | int decPointCnt = 0; | - | ||||||||||||||||||||||||
3164 | bool dec = false; | - | ||||||||||||||||||||||||
3165 | int decDigitCnt = 0; | - | ||||||||||||||||||||||||
3166 | - | |||||||||||||||||||||||||
3167 | for (int i = 0; i < str.length(); ++i) {
| 416-1769 | ||||||||||||||||||||||||
3168 | char c = digitToCLocale(str.at(i)); | - | ||||||||||||||||||||||||
3169 | - | |||||||||||||||||||||||||
3170 | if (c >= '0' && c <= '9') {
| 124-1453 | ||||||||||||||||||||||||
3171 | if (numMode != IntegerMode) {
| 529-800 | ||||||||||||||||||||||||
3172 | // If a double has too many digits after decpt, it shall be Invalid. | - | ||||||||||||||||||||||||
3173 | if (dec && decDigits != -1 && decDigits < ++decDigitCnt)
| 0-694 | ||||||||||||||||||||||||
3174 | return false; executed 12 times by 1 test: return false; Executed by:
| 12 | ||||||||||||||||||||||||
3175 | } executed 788 times by 2 tests: end of block Executed by:
| 788 | ||||||||||||||||||||||||
3176 | - | |||||||||||||||||||||||||
3177 | // The only non-digit character after the 'e' can be '+' or '-'. | - | ||||||||||||||||||||||||
3178 | // If a zero is directly after that, then the exponent is zero-padded. | - | ||||||||||||||||||||||||
3179 |
| 0-34 | ||||||||||||||||||||||||
3180 | !lastWasDigit)
| 0-5 | ||||||||||||||||||||||||
3181 | return false; executed 5 times by 1 test: return false; Executed by:
| 5 | ||||||||||||||||||||||||
3182 | - | |||||||||||||||||||||||||
3183 | lastWasDigit = true; | - | ||||||||||||||||||||||||
3184 | } else { executed 1312 times by 5 tests: end of block Executed by:
| 1312 | ||||||||||||||||||||||||
3185 | switch (c) { | - | ||||||||||||||||||||||||
3186 | case '.': executed 74 times by 4 tests: case '.': Executed by:
| 74 | ||||||||||||||||||||||||
3187 | if (numMode == IntegerMode) {
| 6-68 | ||||||||||||||||||||||||
3188 | // If an integer has a decimal point, it shall be Invalid. | - | ||||||||||||||||||||||||
3189 | return false; executed 6 times by 2 tests: return false; Executed by:
| 6 | ||||||||||||||||||||||||
3190 | } else { | - | ||||||||||||||||||||||||
3191 | // If a double has more than one decimal point, it shall be Invalid. | - | ||||||||||||||||||||||||
3192 | if (++decPointCnt > 1)
| 0-68 | ||||||||||||||||||||||||
3193 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
3194 | #if 0 | - | ||||||||||||||||||||||||
3195 | // If a double with no decimal digits has a decimal point, it shall be | - | ||||||||||||||||||||||||
3196 | // Invalid. | - | ||||||||||||||||||||||||
3197 | if (decDigits == 0) | - | ||||||||||||||||||||||||
3198 | return false; | - | ||||||||||||||||||||||||
3199 | #endif // On second thoughts, it shall be Valid. | - | ||||||||||||||||||||||||
3200 | - | |||||||||||||||||||||||||
3201 | dec = true; | - | ||||||||||||||||||||||||
3202 | } executed 68 times by 2 tests: end of block Executed by:
| 68 | ||||||||||||||||||||||||
3203 | break; executed 68 times by 2 tests: break; Executed by:
| 68 | ||||||||||||||||||||||||
3204 | - | |||||||||||||||||||||||||
3205 | case '+': executed 45 times by 2 tests: case '+': Executed by:
| 45 | ||||||||||||||||||||||||
3206 | case '-': executed 135 times by 3 tests: case '-': Executed by:
| 135 | ||||||||||||||||||||||||
3207 | if (scientific) {
| 72-108 | ||||||||||||||||||||||||
3208 | // If a scientific has a sign that's not at the beginning or after | - | ||||||||||||||||||||||||
3209 | // an 'e', it shall be Invalid. | - | ||||||||||||||||||||||||
3210 | if (i != 0 && !lastWasE)
| 0-58 | ||||||||||||||||||||||||
3211 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
3212 | } else { executed 72 times by 1 test: end of block Executed by:
| 72 | ||||||||||||||||||||||||
3213 | // If a non-scientific has a sign that's not at the beginning, | - | ||||||||||||||||||||||||
3214 | // it shall be Invalid. | - | ||||||||||||||||||||||||
3215 | if (i != 0)
| 4-104 | ||||||||||||||||||||||||
3216 | return false; executed 4 times by 2 tests: return false; Executed by:
| 4 | ||||||||||||||||||||||||
3217 | } executed 104 times by 3 tests: end of block Executed by:
| 104 | ||||||||||||||||||||||||
3218 | break; executed 176 times by 3 tests: break; Executed by:
| 176 | ||||||||||||||||||||||||
3219 | - | |||||||||||||||||||||||||
3220 | case ',': executed 19 times by 2 tests: case ',': Executed by:
| 19 | ||||||||||||||||||||||||
3221 | //it can only be placed after a digit which is before the decimal point | - | ||||||||||||||||||||||||
3222 | if (rejectGroupSeparators((number_options & QLocale::RejectGroupSeparator) || !lastWasDigit ||
| 2-15 | ||||||||||||||||||||||||
3223 | decPointCnt > 0)
| 0-15 | ||||||||||||||||||||||||
3224 | return false; executed 4 times by 1 test: return false; Executed by:
| 4 | ||||||||||||||||||||||||
3225 | break; executed 15 times by 2 tests: break; Executed by:
| 15 | ||||||||||||||||||||||||
3226 | - | |||||||||||||||||||||||||
3227 | case 'e': executed 124 times by 1 test: case 'e': Executed by:
| 124 | ||||||||||||||||||||||||
3228 | if (scientific) {
| 52-72 | ||||||||||||||||||||||||
3229 | // If a scientific has more than one 'e', it shall be Invalid. | - | ||||||||||||||||||||||||
3230 | if (++eCnt > 1)
| 0-72 | ||||||||||||||||||||||||
3231 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
3232 | dec = false; | - | ||||||||||||||||||||||||
3233 | } else { executed 72 times by 1 test: end of block Executed by:
| 72 | ||||||||||||||||||||||||
3234 | // If a non-scientific has an 'e', it shall be Invalid. | - | ||||||||||||||||||||||||
3235 | return false; executed 52 times by 1 test: return false; Executed by:
| 52 | ||||||||||||||||||||||||
3236 | } | - | ||||||||||||||||||||||||
3237 | break; executed 72 times by 1 test: break; Executed by:
| 72 | ||||||||||||||||||||||||
3238 | - | |||||||||||||||||||||||||
3239 | default: executed 43 times by 4 tests: default: Executed by:
| 43 | ||||||||||||||||||||||||
3240 | // If it's not a valid digit, it shall be Invalid. | - | ||||||||||||||||||||||||
3241 | return false; executed 43 times by 4 tests: return false; Executed by:
| 43 | ||||||||||||||||||||||||
3242 | } | - | ||||||||||||||||||||||||
3243 | lastWasDigit = false; | - | ||||||||||||||||||||||||
3244 | } executed 331 times by 4 tests: end of block Executed by:
| 331 | ||||||||||||||||||||||||
3245 | - | |||||||||||||||||||||||||
3246 | lastWasE = c == 'e'; | - | ||||||||||||||||||||||||
3247 | if (c != ',')
| 15-1628 | ||||||||||||||||||||||||
3248 | buff->append(c); executed 1628 times by 5 tests: buff->append(c); Executed by:
| 1628 | ||||||||||||||||||||||||
3249 | } executed 1643 times by 5 tests: end of block Executed by:
| 1643 | ||||||||||||||||||||||||
3250 | - | |||||||||||||||||||||||||
3251 | return true; executed 416 times by 5 tests: return true; Executed by:
| 416 | ||||||||||||||||||||||||
3252 | } | - | ||||||||||||||||||||||||
3253 | - | |||||||||||||||||||||||||
3254 | double QLocaleData::stringToDouble(const QChar *begin, int len, bool *ok, | - | ||||||||||||||||||||||||
3255 | GroupSeparatorMode group_sep_modeQLocale::NumberOptions number_options) const | - | ||||||||||||||||||||||||
3256 | { | - | ||||||||||||||||||||||||
3257 | CharBuff buff; | - | ||||||||||||||||||||||||
3258 | if (!numberToCLocale(begin, len, group_sep_modenumber_options, &buff)) {
| 49-4014 | ||||||||||||||||||||||||
3259 | if (ok != 0)
| 0-49 | ||||||||||||||||||||||||
3260 | *ok = false; executed 49 times by 5 tests: *ok = false; Executed by:
| 49 | ||||||||||||||||||||||||
3261 | return 0.0; executed 49 times by 5 tests: return 0.0; Executed by:
| 49 | ||||||||||||||||||||||||
3262 | } | - | ||||||||||||||||||||||||
3263 | return bytearrayToDoubleint processed = 0; | - | ||||||||||||||||||||||||
3264 | bool nonNullOk = false; | - | ||||||||||||||||||||||||
3265 | double d = asciiToDouble(buff.constData(), okbuff.length() - 1, nonNullOk, processed); | - | ||||||||||||||||||||||||
3266 | if (ok)
| 1159-2855 | ||||||||||||||||||||||||
3267 | *ok = nonNullOk; executed 2855 times by 21 tests: *ok = nonNullOk; Executed by:
| 2855 | ||||||||||||||||||||||||
3268 | return d; executed 4014 times by 27 tests: return d; Executed by:
| 4014 | ||||||||||||||||||||||||
3269 | } | - | ||||||||||||||||||||||||
3270 | - | |||||||||||||||||||||||||
3271 | qlonglong QLocaleData::stringToLongLong(const QChar *begin, int len, int base, bool *ok, | - | ||||||||||||||||||||||||
3272 | GroupSeparatorMode group_sep_modeQLocale::NumberOptions number_options) const | - | ||||||||||||||||||||||||
3273 | { | - | ||||||||||||||||||||||||
3274 | CharBuff buff; | - | ||||||||||||||||||||||||
3275 | if (!numberToCLocale(begin, len, group_sep_modenumber_options, &buff)) {
| 4267-153149 | ||||||||||||||||||||||||
3276 | if (ok != 0)
| 74-4193 | ||||||||||||||||||||||||
3277 | *ok = false; executed 74 times by 8 tests: *ok = false; Executed by:
| 74 | ||||||||||||||||||||||||
3278 | return 0; executed 4267 times by 13 tests: return 0; Executed by:
| 4267 | ||||||||||||||||||||||||
3279 | } | - | ||||||||||||||||||||||||
3280 | - | |||||||||||||||||||||||||
3281 | return bytearrayToLongLong(buff.constData(), base, ok); executed 153149 times by 71 tests: return bytearrayToLongLong(buff.constData(), base, ok); Executed by:
| 153149 | ||||||||||||||||||||||||
3282 | } | - | ||||||||||||||||||||||||
3283 | - | |||||||||||||||||||||||||
3284 | qulonglong QLocaleData::stringToUnsLongLong(const QChar *begin, int len, int base, bool *ok, | - | ||||||||||||||||||||||||
3285 | GroupSeparatorMode group_sep_modeQLocale::NumberOptions number_options) const | - | ||||||||||||||||||||||||
3286 | { | - | ||||||||||||||||||||||||
3287 | CharBuff buff; | - | ||||||||||||||||||||||||
3288 | if (!numberToCLocale(begin, len, group_sep_modenumber_options, &buff)) {
| 958-18617 | ||||||||||||||||||||||||
3289 | if (ok != 0)
| 8-950 | ||||||||||||||||||||||||
3290 | *ok = false; executed 950 times by 11 tests: *ok = false; Executed by:
| 950 | ||||||||||||||||||||||||
3291 | return 0; executed 958 times by 11 tests: return 0; Executed by:
| 958 | ||||||||||||||||||||||||
3292 | } | - | ||||||||||||||||||||||||
3293 | - | |||||||||||||||||||||||||
3294 | return bytearrayToUnsLongLong(buff.constData(), base, ok); executed 18617 times by 29 tests: return bytearrayToUnsLongLong(buff.constData(), base, ok); Executed by:
| 18617 | ||||||||||||||||||||||||
3295 | } | - | ||||||||||||||||||||||||
3296 | - | |||||||||||||||||||||||||
3297 | double QLocaleData::bytearrayToDouble(const char *num, bool *ok, bool *overflow) | - | ||||||||||||||||||||||||
3298 | { | - | ||||||||||||||||||||||||
3299 | if (ok != 0) | - | ||||||||||||||||||||||||
*ok = true; | ||||||||||||||||||||||||||
if (overflow != 0) | ||||||||||||||||||||||||||
*overflowbool nonNullOk = false; | ||||||||||||||||||||||||||
3300 | if (*num == '\0') { | - | ||||||||||||||||||||||||
if (ok != 0) | ||||||||||||||||||||||||||
*okint len = false; | ||||||||||||||||||||||||||
return 0.0; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
if (qstrcmp(num, "nan") == 0) | ||||||||||||||||||||||||||
return qt_snan(); | ||||||||||||||||||||||||||
if (qstrcmpstatic_cast<int>(strlen(num, "+inf") == 0 || qstrcmp)); | ||||||||||||||||||||||||||
3301 | Q_ASSERT(num, "inf") ==len >= 0) | - | ||||||||||||||||||||||||
return qt_inf(); | ||||||||||||||||||||||||||
if (qstrcmp(num, "-inf") ==); | ||||||||||||||||||||||||||
3302 | int processed = 0) | - | ||||||||||||||||||||||||
return -qt_inf(); | ||||||||||||||||||||||||||
bool _ok; | ||||||||||||||||||||||||||
const char *endptr; | ||||||||||||||||||||||||||
3303 | double d = qstrtodasciiToDouble(num, &endptrlen, &_oknonNullOk, processed); | - | ||||||||||||||||||||||||
3304 | if (!_ok) {
| 0 | ||||||||||||||||||||||||
if (ok != 0)
| ||||||||||||||||||||||||||
*ok = false;
| ||||||||||||||||||||||||||
if (overflow != 0)
| ||||||||||||||||||||||||||
*overflow = *endptr != '\0';
| ||||||||||||||||||||||||||
return 0.0;
| ||||||||||||||||||||||||||
}
| ||||||||||||||||||||||||||
if (*endptr != '\0') {
| ||||||||||||||||||||||||||
if (ok != 0)
| ||||||||||||||||||||||||||
*ok = false;
| ||||||||||||||||||||||||||
if (overflow != 0)
| ||||||||||||||||||||||||||
*overflow = false;
| ||||||||||||||||||||||||||
return 0.0;
| ||||||||||||||||||||||||||
}
| ||||||||||||||||||||||||||
3305 | *ok = truenonNullOk; never executed: *ok = nonNullOk; | 0 | ||||||||||||||||||||||||
3306 | if (overflow!= 0)
| 0 | ||||||||||||||||||||||||
3307 | *overflow = falseprocessed < len; never executed: *overflow = processed < len; | 0 | ||||||||||||||||||||||||
3308 | return d; never executed: return d; | 0 | ||||||||||||||||||||||||
3309 | } | - | ||||||||||||||||||||||||
3310 | - | |||||||||||||||||||||||||
3311 | qlonglong QLocaleData::bytearrayToLongLong(const char *num, int base, bool *ok, bool *overflow) | - | ||||||||||||||||||||||||
3312 | { | - | ||||||||||||||||||||||||
3313 | bool _ok; | - | ||||||||||||||||||||||||
3314 | const char *endptr; | - | ||||||||||||||||||||||||
3315 | - | |||||||||||||||||||||||||
3316 | if (*num == '\0') { | - | ||||||||||||||||||||||||
3317 | if (ok != 0) | - | ||||||||||||||||||||||||
3318 | *ok = false; | - | ||||||||||||||||||||||||
3319 | if (overflow != 0) | - | ||||||||||||||||||||||||
3320 | *overflow = false; | - | ||||||||||||||||||||||||
3321 | return 0; | - | ||||||||||||||||||||||||
3322 | } | - | ||||||||||||||||||||||||
3323 | - | |||||||||||||||||||||||||
3324 | qlonglong l = qstrtoll(num, &endptr, base, &_ok); | - | ||||||||||||||||||||||||
3325 | - | |||||||||||||||||||||||||
3326 | if (!_ok) { | - | ||||||||||||||||||||||||
3327 | if (ok != 0) | - | ||||||||||||||||||||||||
3328 | *ok = false; | - | ||||||||||||||||||||||||
3329 | if (overflow != 0) { | - | ||||||||||||||||||||||||
3330 | // the only way qstrtoll can fail with *endptr != '\0' on a non-empty | - | ||||||||||||||||||||||||
3331 | // input string is overflow | - | ||||||||||||||||||||||||
3332 | *overflow = *endptr != '\0'; | - | ||||||||||||||||||||||||
3333 | } | - | ||||||||||||||||||||||||
3334 | return 0; | - | ||||||||||||||||||||||||
3335 | } | - | ||||||||||||||||||||||||
3336 | - | |||||||||||||||||||||||||
3337 | if (*endptr != '\0') { | - | ||||||||||||||||||||||||
3338 | // we stopped at a non-digit character after converting some digits | - | ||||||||||||||||||||||||
3339 | if (ok != 0) | - | ||||||||||||||||||||||||
3340 | *ok = false; | - | ||||||||||||||||||||||||
3341 | if (overflow != 0) | - | ||||||||||||||||||||||||
3342 | *overflow = false; | - | ||||||||||||||||||||||||
3343 | return 0; | - | ||||||||||||||||||||||||
3344 | } | - | ||||||||||||||||||||||||
3345 | - | |||||||||||||||||||||||||
3346 | if (ok != 0) | - | ||||||||||||||||||||||||
3347 | *ok = true; | - | ||||||||||||||||||||||||
3348 | if (overflow != 0) | - | ||||||||||||||||||||||||
3349 | *overflow = false; | - | ||||||||||||||||||||||||
3350 | return l; | - | ||||||||||||||||||||||||
3351 | } | - | ||||||||||||||||||||||||
3352 | - | |||||||||||||||||||||||||
3353 | qulonglong QLocaleData::bytearrayToUnsLongLong(const char *num, int base, bool *ok) | - | ||||||||||||||||||||||||
3354 | { | - | ||||||||||||||||||||||||
3355 | bool _ok; | - | ||||||||||||||||||||||||
3356 | const char *endptr; | - | ||||||||||||||||||||||||
3357 | qulonglong l = qstrtoull(num, &endptr, base, &_ok); | - | ||||||||||||||||||||||||
3358 | - | |||||||||||||||||||||||||
3359 | if (!_ok || *endptr != '\0') { | - | ||||||||||||||||||||||||
3360 | if (ok != 0) | - | ||||||||||||||||||||||||
3361 | *ok = false; | - | ||||||||||||||||||||||||
3362 | return 0; | - | ||||||||||||||||||||||||
3363 | } | - | ||||||||||||||||||||||||
3364 | - | |||||||||||||||||||||||||
3365 | if (ok != 0) | - | ||||||||||||||||||||||||
3366 | *ok = true; | - | ||||||||||||||||||||||||
3367 | return l; | - | ||||||||||||||||||||||||
3368 | } | - | ||||||||||||||||||||||||
3369 | - | |||||||||||||||||||||||||
3370 | /*! | - | ||||||||||||||||||||||||
3371 | \since 4.8 | - | ||||||||||||||||||||||||
3372 | - | |||||||||||||||||||||||||
3373 | \enum QLocale::CurrencySymbolFormat | - | ||||||||||||||||||||||||
3374 | - | |||||||||||||||||||||||||
3375 | Specifies the format of the currency symbol. | - | ||||||||||||||||||||||||
3376 | - | |||||||||||||||||||||||||
3377 | \value CurrencyIsoCode a ISO-4217 code of the currency. | - | ||||||||||||||||||||||||
3378 | \value CurrencySymbol a currency symbol. | - | ||||||||||||||||||||||||
3379 | \value CurrencyDisplayName a user readable name of the currency. | - | ||||||||||||||||||||||||
3380 | */ | - | ||||||||||||||||||||||||
3381 | - | |||||||||||||||||||||||||
3382 | /*! | - | ||||||||||||||||||||||||
3383 | \since 4.8 | - | ||||||||||||||||||||||||
3384 | Returns a currency symbol according to the \a format. | - | ||||||||||||||||||||||||
3385 | */ | - | ||||||||||||||||||||||||
3386 | QString QLocale::currencySymbol(QLocale::CurrencySymbolFormat format) const | - | ||||||||||||||||||||||||
3387 | { | - | ||||||||||||||||||||||||
3388 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
3389 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
3390 | QVariant res = systemLocale()->query(QSystemLocale::CurrencySymbol, format); | - | ||||||||||||||||||||||||
3391 | if (!res.isNull()) | - | ||||||||||||||||||||||||
3392 | return res.toString(); | - | ||||||||||||||||||||||||
3393 | } | - | ||||||||||||||||||||||||
3394 | #endif | - | ||||||||||||||||||||||||
3395 | quint32 idx, size; | - | ||||||||||||||||||||||||
3396 | switch (format) { | - | ||||||||||||||||||||||||
3397 | case CurrencySymbol: | - | ||||||||||||||||||||||||
3398 | idx = d->m_data->m_currency_symbol_idx; | - | ||||||||||||||||||||||||
3399 | size = d->m_data->m_currency_symbol_size; | - | ||||||||||||||||||||||||
3400 | return getLocaleData(currency_symbol_data + idx, size); | - | ||||||||||||||||||||||||
3401 | case CurrencyDisplayName: | - | ||||||||||||||||||||||||
3402 | idx = d->m_data->m_currency_display_name_idx; | - | ||||||||||||||||||||||||
3403 | size = d->m_data->m_currency_display_name_size; | - | ||||||||||||||||||||||||
3404 | return getLocaleListData(currency_display_name_data + idx, size, 0); | - | ||||||||||||||||||||||||
3405 | case CurrencyIsoCode: { | - | ||||||||||||||||||||||||
3406 | int len = 0; | - | ||||||||||||||||||||||||
3407 | const QLocaleData *data = this->d->m_data; | - | ||||||||||||||||||||||||
3408 | for (; len < 3; ++len) | - | ||||||||||||||||||||||||
3409 | if (!data->m_currency_iso_code[len]) | - | ||||||||||||||||||||||||
3410 | break; | - | ||||||||||||||||||||||||
3411 | return len ? QString::fromLatin1(data->m_currency_iso_code, len) : QString(); | - | ||||||||||||||||||||||||
3412 | } | - | ||||||||||||||||||||||||
3413 | } | - | ||||||||||||||||||||||||
3414 | return QString(); | - | ||||||||||||||||||||||||
3415 | } | - | ||||||||||||||||||||||||
3416 | - | |||||||||||||||||||||||||
3417 | /*! | - | ||||||||||||||||||||||||
3418 | \since 4.8 | - | ||||||||||||||||||||||||
3419 | - | |||||||||||||||||||||||||
3420 | Returns a localized string representation of \a value as a currency. | - | ||||||||||||||||||||||||
3421 | If the \a symbol is provided it is used instead of the default currency symbol. | - | ||||||||||||||||||||||||
3422 | - | |||||||||||||||||||||||||
3423 | \sa currencySymbol() | - | ||||||||||||||||||||||||
3424 | */ | - | ||||||||||||||||||||||||
3425 | QString QLocale::toCurrencyString(qlonglong value, const QString &symbol) const | - | ||||||||||||||||||||||||
3426 | { | - | ||||||||||||||||||||||||
3427 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
3428 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
3429 | QSystemLocale::CurrencyToStringArgument arg(value, symbol); | - | ||||||||||||||||||||||||
3430 | QVariant res = systemLocale()->query(QSystemLocale::CurrencyToString, QVariant::fromValue(arg)); | - | ||||||||||||||||||||||||
3431 | if (!res.isNull()) | - | ||||||||||||||||||||||||
3432 | return res.toString(); | - | ||||||||||||||||||||||||
3433 | } | - | ||||||||||||||||||||||||
3434 | #endif | - | ||||||||||||||||||||||||
3435 | const QLocalePrivate *d = this->d; | - | ||||||||||||||||||||||||
3436 | quint8 idx = d->m_data->m_currency_format_idx; | - | ||||||||||||||||||||||||
3437 | quint8 size = d->m_data->m_currency_format_size; | - | ||||||||||||||||||||||||
3438 | if (d->m_data->m_currency_negative_format_size && value < 0) { | - | ||||||||||||||||||||||||
3439 | idx = d->m_data->m_currency_negative_format_idx; | - | ||||||||||||||||||||||||
3440 | size = d->m_data->m_currency_negative_format_size; | - | ||||||||||||||||||||||||
3441 | value = -value; | - | ||||||||||||||||||||||||
3442 | } | - | ||||||||||||||||||||||||
3443 | QString str = toString(value); | - | ||||||||||||||||||||||||
3444 | QString sym = symbol.isNull() ? currencySymbol() : symbol; | - | ||||||||||||||||||||||||
3445 | if (sym.isEmpty()) | - | ||||||||||||||||||||||||
3446 | sym = currencySymbol(QLocale::CurrencyIsoCode); | - | ||||||||||||||||||||||||
3447 | QString format = getLocaleData(currency_format_data + idx, size); | - | ||||||||||||||||||||||||
3448 | return format.arg(str, sym); | - | ||||||||||||||||||||||||
3449 | } | - | ||||||||||||||||||||||||
3450 | - | |||||||||||||||||||||||||
3451 | /*! | - | ||||||||||||||||||||||||
3452 | \since 4.8 | - | ||||||||||||||||||||||||
3453 | \overload | - | ||||||||||||||||||||||||
3454 | */ | - | ||||||||||||||||||||||||
3455 | QString QLocale::toCurrencyString(qulonglong value, const QString &symbol) const | - | ||||||||||||||||||||||||
3456 | { | - | ||||||||||||||||||||||||
3457 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
3458 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
3459 | QSystemLocale::CurrencyToStringArgument arg(value, symbol); | - | ||||||||||||||||||||||||
3460 | QVariant res = systemLocale()->query(QSystemLocale::CurrencyToString, QVariant::fromValue(arg)); | - | ||||||||||||||||||||||||
3461 | if (!res.isNull()) | - | ||||||||||||||||||||||||
3462 | return res.toString(); | - | ||||||||||||||||||||||||
3463 | } | - | ||||||||||||||||||||||||
3464 | #endif | - | ||||||||||||||||||||||||
3465 | const QLocaleData *data = this->d->m_data; | - | ||||||||||||||||||||||||
3466 | quint8 idx = data->m_currency_format_idx; | - | ||||||||||||||||||||||||
3467 | quint8 size = data->m_currency_format_size; | - | ||||||||||||||||||||||||
3468 | QString str = toString(value); | - | ||||||||||||||||||||||||
3469 | QString sym = symbol.isNull() ? currencySymbol() : symbol; | - | ||||||||||||||||||||||||
3470 | if (sym.isEmpty()) | - | ||||||||||||||||||||||||
3471 | sym = currencySymbol(QLocale::CurrencyIsoCode); | - | ||||||||||||||||||||||||
3472 | QString format = getLocaleData(currency_format_data + idx, size); | - | ||||||||||||||||||||||||
3473 | return format.arg(str, sym); | - | ||||||||||||||||||||||||
3474 | } | - | ||||||||||||||||||||||||
3475 | - | |||||||||||||||||||||||||
3476 | #if QT_VERSION < QT_VERSION_CHECK(6,0,0) | - | ||||||||||||||||||||||||
3477 | /*! | - | ||||||||||||||||||||||||
3478 | \since 4.8 | - | ||||||||||||||||||||||||
3479 | \overload | - | ||||||||||||||||||||||||
3480 | */ | - | ||||||||||||||||||||||||
3481 | QString QLocale::toCurrencyString(double value, const QString &symbol) const | - | ||||||||||||||||||||||||
3482 | { | - | ||||||||||||||||||||||||
3483 | return toCurrencyString(value, symbol, d->m_data->m_currency_digits); never executed: return toCurrencyString(value, symbol, d->m_data->m_currency_digits); | 0 | ||||||||||||||||||||||||
3484 | } | - | ||||||||||||||||||||||||
3485 | #endif | - | ||||||||||||||||||||||||
3486 | - | |||||||||||||||||||||||||
3487 | /*! | - | ||||||||||||||||||||||||
3488 | \since 5.7 | - | ||||||||||||||||||||||||
3489 | \overload toCurrencyString() | - | ||||||||||||||||||||||||
3490 | - | |||||||||||||||||||||||||
3491 | Returns a localized string representation of \a value as a currency. | - | ||||||||||||||||||||||||
3492 | If the \a symbol is provided it is used instead of the default currency symbol. | - | ||||||||||||||||||||||||
3493 | If the \a precision is provided it is used to set the precision of the currency value. | - | ||||||||||||||||||||||||
3494 | - | |||||||||||||||||||||||||
3495 | \sa currencySymbol() | - | ||||||||||||||||||||||||
3496 | */ | - | ||||||||||||||||||||||||
3497 | QString QLocale::toCurrencyString(double value, const QString &symbol, int precision) const | - | ||||||||||||||||||||||||
3498 | { | - | ||||||||||||||||||||||||
3499 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
3500 | if (d->m_data == systemData()) {
| 0 | ||||||||||||||||||||||||
3501 | QSystemLocale::CurrencyToStringArgument arg(value, symbol); | - | ||||||||||||||||||||||||
3502 | QVariant res = systemLocale()->query(QSystemLocale::CurrencyToString, QVariant::fromValue(arg)); | - | ||||||||||||||||||||||||
3503 | if (!res.isNull())
| 0 | ||||||||||||||||||||||||
3504 | return res.toString(); never executed: return res.toString(); | 0 | ||||||||||||||||||||||||
3505 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3506 | #endif | - | ||||||||||||||||||||||||
3507 | const QLocaleData *data = this->d->m_data; | - | ||||||||||||||||||||||||
3508 | quint8 idx = data->m_currency_format_idx; | - | ||||||||||||||||||||||||
3509 | quint8 size = data->m_currency_format_size; | - | ||||||||||||||||||||||||
3510 | if (data->m_currency_negative_format_size && value < 0) {
| 0 | ||||||||||||||||||||||||
3511 | idx = data->m_currency_negative_format_idx; | - | ||||||||||||||||||||||||
3512 | size = data->m_currency_negative_format_size; | - | ||||||||||||||||||||||||
3513 | value = -value; | - | ||||||||||||||||||||||||
3514 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3515 | QString str = toString(value, 'f', precision == -1 ? d->m_data->m_currency_digits : precision); | - | ||||||||||||||||||||||||
3516 | QString sym = symbol.isNull() ? currencySymbol() : symbol;
| 0 | ||||||||||||||||||||||||
3517 | if (sym.isEmpty())
| 0 | ||||||||||||||||||||||||
3518 | sym = currencySymbol(QLocale::CurrencyIsoCode); never executed: sym = currencySymbol(QLocale::CurrencyIsoCode); | 0 | ||||||||||||||||||||||||
3519 | QString format = getLocaleData(currency_format_data + idx, size); | - | ||||||||||||||||||||||||
3520 | return format.arg(str, sym); never executed: return format.arg(str, sym); | 0 | ||||||||||||||||||||||||
3521 | } | - | ||||||||||||||||||||||||
3522 | - | |||||||||||||||||||||||||
3523 | /*! | - | ||||||||||||||||||||||||
3524 | \since 4.8 | - | ||||||||||||||||||||||||
3525 | - | |||||||||||||||||||||||||
3526 | Returns an ordered list of locale names for translation purposes in | - | ||||||||||||||||||||||||
3527 | preference order (like "en-Latn-US", "en-US", "en"). | - | ||||||||||||||||||||||||
3528 | - | |||||||||||||||||||||||||
3529 | The return value represents locale names that the user expects to see the | - | ||||||||||||||||||||||||
3530 | UI translation in. | - | ||||||||||||||||||||||||
3531 | - | |||||||||||||||||||||||||
3532 | Most like you do not need to use this function directly, but just pass the | - | ||||||||||||||||||||||||
3533 | QLocale object to the QTranslator::load() function. | - | ||||||||||||||||||||||||
3534 | - | |||||||||||||||||||||||||
3535 | The first item in the list is the most preferred one. | - | ||||||||||||||||||||||||
3536 | - | |||||||||||||||||||||||||
3537 | \sa QTranslator, bcp47Name() | - | ||||||||||||||||||||||||
3538 | */ | - | ||||||||||||||||||||||||
3539 | QStringList QLocale::uiLanguages() const | - | ||||||||||||||||||||||||
3540 | { | - | ||||||||||||||||||||||||
3541 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
3542 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
3543 | QVariant res = systemLocale()->query(QSystemLocale::UILanguages, QVariant()); | - | ||||||||||||||||||||||||
3544 | if (!res.isNull()) { | - | ||||||||||||||||||||||||
3545 | QStringList result = res.toStringList(); | - | ||||||||||||||||||||||||
3546 | if (!result.isEmpty()) | - | ||||||||||||||||||||||||
3547 | return result; | - | ||||||||||||||||||||||||
3548 | } | - | ||||||||||||||||||||||||
3549 | } | - | ||||||||||||||||||||||||
3550 | #endif | - | ||||||||||||||||||||||||
3551 | QLocaleId id = QLocaleId::fromIds(d->m_data->m_language_id, d->m_data->m_script_id, d->m_data->m_country_id); | - | ||||||||||||||||||||||||
3552 | const QLocaleId max = id.withLikelySubtagsAdded(); | - | ||||||||||||||||||||||||
3553 | const QLocaleId min = max.withLikelySubtagsRemoved(); | - | ||||||||||||||||||||||||
3554 | - | |||||||||||||||||||||||||
3555 | QStringList uiLanguages; | - | ||||||||||||||||||||||||
3556 | uiLanguages.append(QString::fromLatin1(min.name())); | - | ||||||||||||||||||||||||
3557 | if (id.script_id) { | - | ||||||||||||||||||||||||
3558 | id.script_id = 0; | - | ||||||||||||||||||||||||
3559 | if (id != min && id.withLikelySubtagsAdded() == max) | - | ||||||||||||||||||||||||
3560 | uiLanguages.append(QString::fromLatin1(id.name())); | - | ||||||||||||||||||||||||
3561 | } | - | ||||||||||||||||||||||||
3562 | if (max != min && max != id) | - | ||||||||||||||||||||||||
3563 | uiLanguages.append(QString::fromLatin1(max.name())); | - | ||||||||||||||||||||||||
3564 | return uiLanguages; | - | ||||||||||||||||||||||||
3565 | } | - | ||||||||||||||||||||||||
3566 | - | |||||||||||||||||||||||||
3567 | /*! | - | ||||||||||||||||||||||||
3568 | \since 4.8 | - | ||||||||||||||||||||||||
3569 | - | |||||||||||||||||||||||||
3570 | Returns a native name of the language for the locale. For example | - | ||||||||||||||||||||||||
3571 | "Schwiizertüütsch" for Swiss-German locale. | - | ||||||||||||||||||||||||
3572 | - | |||||||||||||||||||||||||
3573 | \sa nativeCountryName(), languageToString() | - | ||||||||||||||||||||||||
3574 | */ | - | ||||||||||||||||||||||||
3575 | QString QLocale::nativeLanguageName() const | - | ||||||||||||||||||||||||
3576 | { | - | ||||||||||||||||||||||||
3577 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
3578 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
3579 | QVariant res = systemLocale()->query(QSystemLocale::NativeLanguageName, QVariant()); | - | ||||||||||||||||||||||||
3580 | if (!res.isNull()) | - | ||||||||||||||||||||||||
3581 | return res.toString(); | - | ||||||||||||||||||||||||
3582 | } | - | ||||||||||||||||||||||||
3583 | #endif | - | ||||||||||||||||||||||||
3584 | return getLocaleData(endonyms_data + d->m_data->m_language_endonym_idx, d->m_data->m_language_endonym_size); | - | ||||||||||||||||||||||||
3585 | } | - | ||||||||||||||||||||||||
3586 | - | |||||||||||||||||||||||||
3587 | /*! | - | ||||||||||||||||||||||||
3588 | \since 4.8 | - | ||||||||||||||||||||||||
3589 | - | |||||||||||||||||||||||||
3590 | Returns a native name of the country for the locale. For example | - | ||||||||||||||||||||||||
3591 | "España" for Spanish/Spain locale. | - | ||||||||||||||||||||||||
3592 | - | |||||||||||||||||||||||||
3593 | \sa nativeLanguageName(), countryToString() | - | ||||||||||||||||||||||||
3594 | */ | - | ||||||||||||||||||||||||
3595 | QString QLocale::nativeCountryName() const | - | ||||||||||||||||||||||||
3596 | { | - | ||||||||||||||||||||||||
3597 | #ifndef QT_NO_SYSTEMLOCALE | - | ||||||||||||||||||||||||
3598 | if (d->m_data == systemData()) { | - | ||||||||||||||||||||||||
3599 | QVariant res = systemLocale()->query(QSystemLocale::NativeCountryName, QVariant()); | - | ||||||||||||||||||||||||
3600 | if (!res.isNull()) | - | ||||||||||||||||||||||||
3601 | return res.toString(); | - | ||||||||||||||||||||||||
3602 | } | - | ||||||||||||||||||||||||
3603 | #endif | - | ||||||||||||||||||||||||
3604 | return getLocaleData(endonyms_data + d->m_data->m_country_endonym_idx, d->m_data->m_country_endonym_size); | - | ||||||||||||||||||||||||
3605 | } | - | ||||||||||||||||||||||||
3606 | - | |||||||||||||||||||||||||
3607 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||||||||
3608 | QDebug operator<<(QDebug dbg, const QLocale &l) | - | ||||||||||||||||||||||||
3609 | { | - | ||||||||||||||||||||||||
3610 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||||||||
3611 | dbg.nospace().noquote() | - | ||||||||||||||||||||||||
3612 | << "QLocale(" << QLocale::languageToString(l.language()) | - | ||||||||||||||||||||||||
3613 | << ", " << QLocale::scriptToString(l.script()) | - | ||||||||||||||||||||||||
3614 | << ", " << QLocale::countryToString(l.country()) << ')'; | - | ||||||||||||||||||||||||
3615 | return dbg; | - | ||||||||||||||||||||||||
3616 | } | - | ||||||||||||||||||||||||
3617 | #endif | - | ||||||||||||||||||||||||
3618 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |