Qt 4.8
qlocale.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qglobal.h"
43 
44 #ifndef QT_NO_SYSTEMLOCALE
46 class QSystemLocale;
49 #endif
50 
51 #if !defined(QWS) && defined(Q_OS_MAC)
52 # include "private/qcore_mac_p.h"
53 # include <CoreFoundation/CoreFoundation.h>
54 #endif
55 
56 #include "qplatformdefs.h"
57 
58 #include "qdatastream.h"
59 #include "qstring.h"
60 #include "qlocale.h"
61 #include "qlocale_p.h"
62 #include "qlocale_tools_p.h"
63 #include "qdatetime_p.h"
64 #include "qnamespace.h"
65 #include "qdatetime.h"
66 #include "qstringlist.h"
67 #include "qvariant.h"
68 #include "qstringbuilder.h"
69 #if defined(Q_WS_WIN)
70 # include "qt_windows.h"
71 # include <time.h>
72 #endif
73 #include "private/qnumeric_p.h"
74 #include "private/qsystemlibrary_p.h"
75 
77 
78 #if defined(Q_OS_SYMBIAN)
79 void qt_symbianUpdateSystemPrivate();
80 #endif
81 
82 #ifndef QT_NO_SYSTEMLOCALE
86 Q_GLOBAL_STATIC(QLocalePrivate, globalLocalePrivate)
87 #endif
88 
89 #ifdef QT_USE_ICU
90 extern bool qt_initIcu(const QString &localeName);
91 extern bool qt_u_strToUpper(const QString &str, QString *out, const QLocale &locale);
92 extern bool qt_u_strToLower(const QString &str, QString *out, const QLocale &locale);
93 #endif
94 
95 /******************************************************************************
96 ** Helpers for accessing Qt locale database
97 */
98 
100 #include "qlocale_data_p.h"
102 
104 {
105  int len = code.length();
106  if (len != 2 && len != 3)
107  return QLocale::C;
108  ushort uc1 = len-- > 0 ? code[0].toLower().unicode() : 0;
109  ushort uc2 = len-- > 0 ? code[1].toLower().unicode() : 0;
110  ushort uc3 = len-- > 0 ? code[2].toLower().unicode() : 0;
111 
112  if (uc1 == 'n' && uc2 == 'o' && uc3 == 0)
113  uc2 = 'b';
114 
115  const unsigned char *c = language_code_list;
116  for (; *c != 0; c += 3) {
117  if (uc1 == c[0] && uc2 == c[1] && uc3 == c[2])
118  return QLocale::Language((c - language_code_list)/3);
119  }
120 
121  return QLocale::C;
122 }
123 
125 {
126  int len = code.length();
127  if (len != 4)
128  return QLocale::AnyScript;
129 
130  // script is titlecased in our data
131  unsigned char c0 = code.at(0).toUpper().toLatin1();
132  unsigned char c1 = code.at(1).toLower().toLatin1();
133  unsigned char c2 = code.at(2).toLower().toLatin1();
134  unsigned char c3 = code.at(3).toLower().toLatin1();
135 
136  const unsigned char *c = script_code_list;
137  for (int i = 0; i < QLocale::LastScript; ++i, c += 4) {
138  if (c0 == c[0] && c1 == c[1] && c2 == c[2] && c3 == c[3])
139  return QLocale::Script(i);
140  }
141  return QLocale::AnyScript;
142 }
143 
145 {
146  int len = code.length();
147  if (len != 2 && len != 3)
148  return QLocale::AnyCountry;
149  ushort uc1 = len-- > 0 ? code[0].toUpper().unicode() : 0;
150  ushort uc2 = len-- > 0 ? code[1].toUpper().unicode() : 0;
151  ushort uc3 = len-- > 0 ? code[2].toUpper().unicode() : 0;
152 
153  const unsigned char *c = country_code_list;
154  for (; *c != 0; c += 3) {
155  if (uc1 == c[0] && uc2 == c[1] && uc3 == c[2])
156  return QLocale::Country((c - country_code_list)/3);
157  }
158 
159  return QLocale::AnyCountry;
160 }
161 
163 {
165  return QString();
166  if (m_language_id == QLocale::C)
167  return QLatin1String("C");
168 
169  const unsigned char *c = language_code_list + 3*(uint(m_language_id));
170 
171  QString code(c[2] == 0 ? 2 : 3, Qt::Uninitialized);
172 
173  code[0] = ushort(c[0]);
174  code[1] = ushort(c[1]);
175  if (c[2] != 0)
176  code[2] = ushort(c[2]);
177 
178  return code;
179 }
180 
182 {
184  return QString();
185  const unsigned char *c = script_code_list + 4*(uint(m_script_id));
186  return QString::fromLatin1((const char *)c, 4);
187 }
188 
190 {
192  return QString();
193 
194  const unsigned char *c = country_code_list + 3*(uint(m_country_id));
195 
196  QString code(c[2] == 0 ? 2 : 3, Qt::Uninitialized);
197 
198  code[0] = ushort(c[0]);
199  code[1] = ushort(c[1]);
200  if (c[2] != 0)
201  code[2] = ushort(c[2]);
202 
203  return code;
204 }
205 
207 {
209  return QString();
210  if (m_language_id == QLocale::C)
211  return QLatin1String("C");
212  const unsigned char *lang = language_code_list + 3*(uint(m_language_id));
213  const unsigned char *script =
215  const unsigned char *country =
217  char len = (lang[2] != 0 ? 3 : 2) + (script ? 4+1 : 0) + (country ? (country[2] != 0 ? 3 : 2)+1 : 0);
219  QChar *uc = name.data();
220  *uc++ = ushort(lang[0]);
221  *uc++ = ushort(lang[1]);
222  if (lang[2] != 0)
223  *uc++ = ushort(lang[2]);
224  if (script) {
225  *uc++ = QLatin1Char('-');
226  *uc++ = ushort(script[0]);
227  *uc++ = ushort(script[1]);
228  *uc++ = ushort(script[2]);
229  *uc++ = ushort(script[3]);
230  }
231  if (country) {
232  *uc++ = QLatin1Char('-');
233  *uc++ = ushort(country[0]);
234  *uc++ = ushort(country[1]);
235  if (country[2] != 0)
236  *uc++ = ushort(country[2]);
237  }
238  return name;
239 }
240 
242 {
243  const unsigned language_id = language;
244  const unsigned script_id = script;
245  const unsigned country_id = country;
246 
247  uint idx = locale_index[language_id];
248 
249  const QLocalePrivate *d = locale_data + idx;
250 
251  if (idx == 0) // default language has no associated country
252  return d;
253 
254  if (script == QLocale::AnyScript && country == QLocale::AnyCountry)
255  return d;
256 
257  Q_ASSERT(d->languageId() == language_id);
258 
259  if (country == QLocale::AnyCountry) {
260  while (d->m_language_id == language_id && d->m_script_id != script_id)
261  ++d;
262  if (d->m_language_id == language_id && d->m_script_id == script_id)
263  return d;
264  } else if (script == QLocale::AnyScript) {
265  while (d->m_language_id == language_id) {
266  if (d->m_script_id == script_id && d->m_country_id == country_id)
267  return d;
268  ++d;
269  }
270  } else {
271  // both script and country are explicitly specified
272  while (d->m_language_id == language_id) {
273  if (d->m_script_id == script_id && d->m_country_id == country_id)
274  return d;
275  ++d;
276  }
277  }
278 
279  return locale_data + idx;
280 }
281 
282 static bool parse_locale_tag(const QString &input, int &i, QString *result, const QString &separators)
283 {
284  *result = QString(8, Qt::Uninitialized); // worst case according to BCP47
285  QChar *pch = result->data();
286  const QChar *uc = input.data() + i;
287  const int l = input.length();
288  int size = 0;
289  for (; i < l && size < 8; ++i, ++size) {
290  if (separators.contains(*uc))
291  break;
292  if (! ((uc->unicode() >= 'a' && uc->unicode() <= 'z') ||
293  (uc->unicode() >= 'A' && uc->unicode() <= 'Z') ||
294  (uc->unicode() >= '0' && uc->unicode() <= '9')) ) // latin only
295  return false;
296  *pch++ = *uc++;
297  }
298  result->truncate(size);
299  return true;
300 }
301 
303 {
304  const int length = name.length();
305 
306  lang = script = cntry = QString();
307 
308  const QString separators = QLatin1String("_-.@");
309  enum ParserState { NoState, LangState, ScriptState, CountryState };
310  ParserState state = LangState;
311  for (int i = 0; i < length && state != NoState; ) {
312  QString value;
313  if (!parse_locale_tag(name, i, &value, separators) ||value.isEmpty())
314  break;
315  QChar sep = i < length ? name.at(i) : QChar();
316  switch (state) {
317  case LangState:
318  if (!sep.isNull() && !separators.contains(sep)) {
319  state = NoState;
320  break;
321  }
322  lang = value;
323  if (i == length) {
324  // just language was specified
325  state = NoState;
326  break;
327  }
328  state = ScriptState;
329  break;
330  case ScriptState: {
331  QString scripts = QString::fromLatin1((const char *)script_code_list, sizeof(script_code_list));
332  if (value.length() == 4 && scripts.indexOf(value) % 4 == 0) {
333  // script name is always 4 characters
334  script = value;
335  state = CountryState;
336  } else {
337  // it wasn't a script, maybe it is a country then?
338  cntry = value;
339  state = NoState;
340  }
341  break;
342  }
343  case CountryState:
344  cntry = value;
345  state = NoState;
346  break;
347  case NoState:
348  // shouldn't happen
349  qWarning("QLocale: This should never happen");
350  break;
351  }
352  ++i;
353  }
354  return lang.length() == 2 || lang.length() == 3;
355 }
356 
359 {
360  lang = QLocale::C;
361  script = QLocale::AnyScript;
362  cntry = QLocale::AnyCountry;
363 
364  QString lang_code;
365  QString script_code;
366  QString cntry_code;
367  if (!qt_splitLocaleName(name, lang_code, script_code, cntry_code))
368  return;
369 
370  lang = QLocalePrivate::codeToLanguage(lang_code);
371  if (lang == QLocale::C)
372  return;
373  script = QLocalePrivate::codeToScript(script_code);
374  cntry = QLocalePrivate::codeToCountry(cntry_code);
375 }
376 
377 static const QLocalePrivate *findLocale(const QString &name)
378 {
379  QLocale::Language lang;
381  QLocale::Country cntry;
382  QLocalePrivate::getLangAndCountry(name, lang, script, cntry);
383 
384  return QLocalePrivate::findLocale(lang, script, cntry);
385 }
386 
388 {
389  int &i = *idx;
390 
391  Q_ASSERT(format.at(i) == QLatin1Char('\''));
392  ++i;
393  if (i == format.size())
394  return QString();
395  if (format.at(i).unicode() == '\'') { // "''" outside of a quoted stirng
396  ++i;
397  return QLatin1String("'");
398  }
399 
400  QString result;
401 
402  while (i < format.size()) {
403  if (format.at(i).unicode() == '\'') {
404  if (i + 1 < format.size() && format.at(i + 1).unicode() == '\'') {
405  // "''" inside of a quoted string
406  result.append(QLatin1Char('\''));
407  i += 2;
408  } else {
409  break;
410  }
411  } else {
412  result.append(format.at(i++));
413  }
414  }
415  if (i < format.size())
416  ++i;
417 
418  return result;
419 }
420 
421 int qt_repeatCount(const QString &s, int i)
422 {
423  QChar c = s.at(i);
424  int j = i + 1;
425  while (j < s.size() && s.at(j) == c)
426  ++j;
427  return j - i;
428 }
429 
430 static const QLocalePrivate *default_lp = 0;
432 
433 #ifndef QT_NO_SYSTEMLOCALE
434 
435 
436 /******************************************************************************
437 ** Default system locale behavior
438 */
439 
446 {
447  delete _systemLocale;
448  _systemLocale = this;
449 
450  if (system_lp)
451  system_lp->m_language_id = 0;
452 }
453 
456 { }
457 
462 {
463  if (_systemLocale == this) {
464  _systemLocale = 0;
465 
466  if (system_lp)
467  system_lp->m_language_id = 0;
468  }
469 }
470 
472 {
473  if (_systemLocale)
474  return _systemLocale;
476 }
477 
479 {
480  const QSystemLocale *sys_locale = systemLocale();
481  if (!system_lp)
482  system_lp = globalLocalePrivate();
483 
484  // tell the object that the system locale has changed.
486 
487  *system_lp = *sys_locale->fallbackLocale().d();
488 
489 #if defined(Q_OS_SYMBIAN)
490  qt_symbianUpdateSystemPrivate();
491 #endif
492 
493  QVariant res = sys_locale->query(QSystemLocale::LanguageId, QVariant());
494  if (!res.isNull()) {
495  system_lp->m_language_id = res.toInt();
496  system_lp->m_script_id = QLocale::AnyScript; // default for compatibility
497  }
498  res = sys_locale->query(QSystemLocale::CountryId, QVariant());
499  if (!res.isNull()) {
500  system_lp->m_country_id = res.toInt();
501  system_lp->m_script_id = QLocale::AnyScript; // default for compatibility
502  }
503  res = sys_locale->query(QSystemLocale::ScriptId, QVariant());
504  if (!res.isNull())
505  system_lp->m_script_id = res.toInt();
506 
507  res = sys_locale->query(QSystemLocale::DecimalPoint, QVariant());
508  if (!res.isNull())
509  system_lp->m_decimal = res.toString().at(0).unicode();
510 
511  res = sys_locale->query(QSystemLocale::GroupSeparator, QVariant());
512  if (!res.isNull())
513  system_lp->m_group = res.toString().at(0).unicode();
514 
515  res = sys_locale->query(QSystemLocale::ZeroDigit, QVariant());
516  if (!res.isNull())
517  system_lp->m_zero = res.toString().at(0).unicode();
518 
519  res = sys_locale->query(QSystemLocale::NegativeSign, QVariant());
520  if (!res.isNull())
521  system_lp->m_minus = res.toString().at(0).unicode();
522 
523  res = sys_locale->query(QSystemLocale::PositiveSign, QVariant());
524  if (!res.isNull())
525  system_lp->m_plus = res.toString().at(0).unicode();
526 
527 #ifdef QT_USE_ICU
528  if (!default_lp)
529  qt_initIcu(system_lp->bcp47Name());
530 #endif
531 
532 }
533 #endif
534 
535 static const QLocalePrivate *systemPrivate()
536 {
537 #ifndef QT_NO_SYSTEMLOCALE
538  // copy over the information from the fallback locale and modify
539  if (!system_lp || system_lp->m_language_id == 0)
541 
542  return system_lp;
543 #else
544  return locale_data;
545 #endif
546 }
547 
548 static const QLocalePrivate *defaultPrivate()
549 {
550  if (!default_lp)
551  default_lp = systemPrivate();
552  return default_lp;
553 }
554 
555 static QString getLocaleListData(const ushort *data, int size, int index)
556 {
557  static const ushort separator = ';';
558  while (index && size > 0) {
559  while (*data != separator)
560  ++data, --size;
561  --index;
562  ++data;
563  --size;
564  }
565  const ushort *end = data;
566  while (size > 0 && *end != separator)
567  ++end, --size;
568  if (end-data == 0)
569  return QString();
570  return QString::fromRawData(reinterpret_cast<const QChar*>(data), end-data);
571 }
572 
573 static inline QString getLocaleData(const ushort *data, int size)
574 {
575  return size ? QString::fromRawData(reinterpret_cast<const QChar*>(data), size) : QString();
576 }
577 
578 
579 #ifndef QT_NO_DATASTREAM
581 {
582  ds << l.name();
583  return ds;
584 }
585 
587 {
588  QString s;
589  ds >> s;
590  l = QLocale(s);
591  return ds;
592 }
593 #endif // QT_NO_DATASTREAM
594 
595 
596 static const int locale_data_size = sizeof(locale_data)/sizeof(QLocalePrivate) - 1;
597 
598 static const QLocalePrivate *dataPointerHelper(quint16 index)
599 {
600 #ifndef QT_NO_SYSTEMLOCALE
601  Q_ASSERT(index <= locale_data_size);
602  if (index == locale_data_size)
603  return system_lp;
604 #else
605  Q_ASSERT(index < locale_data_size);
606 #endif
607 
608  return &locale_data[index];
609 }
610 
611 static quint16 localePrivateIndex(const QLocalePrivate *p)
612 {
613 #ifndef QT_NO_SYSTEMLOCALE
614  Q_ASSERT((p >= locale_data && p - locale_data < locale_data_size)
615  || (p != 0 && p == system_lp));
616  quint16 index = p == system_lp ? locale_data_size : p - locale_data;
617 #else
618  Q_ASSERT(p >= locale_data && p - locale_data < locale_data_size);
619  quint16 index = p - locale_data;
620 #endif
621 
622  return index;
623 }
624 
655  : v(0)
656 {
657  p.numberOptions = 0;
659 }
660 
670  : v(0)
671 {
674 }
675 
696  : v(0)
697 {
698  const QLocalePrivate *d = QLocalePrivate::findLocale(language, QLocale::AnyScript, country);
699 
700  // If not found, should default to system
701  if (d->languageId() == QLocale::C && language != QLocale::C) {
704  } else {
705  p.numberOptions = 0;
707  }
708 }
709 \
738  : v(0)
739 {
740  const QLocalePrivate *d = QLocalePrivate::findLocale(language, script, country);
741 
742  // If not found, should default to system
743  if (d->languageId() == QLocale::C && language != QLocale::C) {
746  } else {
747  p.numberOptions = 0;
749  }
750 }
751 
757 {
758  v = other.v;
759 }
760 
761 const QLocalePrivate *QLocale::d() const
762 {
763  return dataPointerHelper(p.index);
764 }
765 
772 {
773  v = other.v;
774  return *this;
775 }
776 
786 void QLocale::setNumberOptions(NumberOptions options)
787 {
788  p.numberOptions = options;
789 }
790 
802 QLocale::NumberOptions QLocale::numberOptions() const
803 {
804  return static_cast<NumberOption>(p.numberOptions);
805 }
806 
817 {
818  return quoteString(&str, style);
819 }
820 
827 {
828 #ifndef QT_NO_SYSTEMLOCALE
829  if (d() == systemPrivate()) {
830  QVariant res;
831  if (style == QLocale::AlternateQuotation)
833  if (res.isNull() || style == QLocale::StandardQuotation)
835  if (!res.isNull())
836  return res.toString();
837  }
838 #endif
839 
840  if (style == QLocale::StandardQuotation)
841  return QChar(d()->m_quotation_start) % str % QChar(d()->m_quotation_end);
842  else
843  return QChar(d()->m_alternate_quotation_start) % str % QChar(d()->m_alternate_quotation_end);
844 }
845 
856 {
857 #ifndef QT_NO_SYSTEMLOCALE
858  if (d() == systemPrivate()) {
859  QVariant res;
861 
862  if (!res.isNull())
863  return res.toString();
864  }
865 #endif
866 
867  const int size = list.size();
868  if (size == 1) {
869  return list.at(0);
870  } else if (size == 2) {
871  QString format = getLocaleData(list_pattern_part_data + d()->m_list_pattern_part_two_idx, d()->m_list_pattern_part_two_size);
872  return format.arg(list.at(0), list.at(1));
873  } else if (size > 2) {
874  QString formatStart = getLocaleData(list_pattern_part_data + d()->m_list_pattern_part_start_idx, d()->m_list_pattern_part_start_size);
875  QString formatMid = getLocaleData(list_pattern_part_data + d()->m_list_pattern_part_mid_idx, d()->m_list_pattern_part_mid_size);
876  QString formatEnd = getLocaleData(list_pattern_part_data + d()->m_list_pattern_part_end_idx, d()->m_list_pattern_part_end_size);
877  QString result = formatStart.arg(list.at(0), list.at(1));
878  for (int i = 2; i < size - 1; ++i)
879  result = formatMid.arg(result, list.at(i));
880  result = formatEnd.arg(result, list.at(size - 1));
881  return result;
882  }
883 
884  return QString();
885 }
886 
905 void QLocale::setDefault(const QLocale &locale)
906 {
907  default_lp = locale.d();
908  default_number_options = locale.numberOptions();
909 
910 #ifdef QT_USE_ICU
911  qt_initIcu(locale.bcp47Name());
912 #endif
913 }
914 
921 {
922  return Language(d()->languageId());
923 }
924 
936 {
937  return Script(d()->m_script_id);
938 }
939 
946 {
947  return Country(d()->countryId());
948 }
949 
964 {
965  const QLocalePrivate *dd = d();
966 
968  return QString();
969  if (dd->m_language_id == QLocale::C)
970  return QLatin1String("C");
971 
972  const unsigned char *c = language_code_list + 3*(uint(dd->m_language_id));
973 
974  QString result(7, Qt::Uninitialized);
975  ushort *data = (ushort *)result.unicode();
976  const ushort *begin = data;
977 
978  *data++ = ushort(c[0]);
979  *data++ = ushort(c[1]);
980  if (c[2] != 0)
981  *data++ = ushort(c[2]);
982  if (dd->m_country_id != AnyCountry) {
983  *data++ = '_';
984  const unsigned char *c = country_code_list + 3*(uint(dd->m_country_id));
985  *data++ = ushort(c[0]);
986  *data++ = ushort(c[1]);
987  if (c[2] != 0)
988  *data++ = ushort(c[2]);
989  }
990  result.resize(data - begin);
991 
992  return result;
993 }
994 
1013 {
1014  return d()->bcp47Name();
1015 }
1016 
1024 {
1025  if (uint(language) > uint(QLocale::LastLanguage))
1026  return QLatin1String("Unknown");
1028 }
1029 
1037 {
1038  if (uint(country) > uint(QLocale::LastCountry))
1039  return QLatin1String("Unknown");
1041 }
1042 
1054 {
1055  if (uint(script) > uint(QLocale::LastScript))
1056  return QLatin1String("Unknown");
1058 }
1059 
1077 short QLocale::toShort(const QString &s, bool *ok, int base) const
1078 {
1079  qlonglong i = toLongLong(s, ok, base);
1080  if (i < SHRT_MIN || i > SHRT_MAX) {
1081  if (ok != 0)
1082  *ok = false;
1083  return 0;
1084  }
1085  return short(i);
1086 }
1087 
1105 ushort QLocale::toUShort(const QString &s, bool *ok, int base) const
1106 {
1107  qulonglong i = toULongLong(s, ok, base);
1108  if (i > USHRT_MAX) {
1109  if (ok != 0)
1110  *ok = false;
1111  return 0;
1112  }
1113  return ushort(i);
1114 }
1115 
1133 int QLocale::toInt(const QString &s, bool *ok, int base) const
1134 {
1135  qlonglong i = toLongLong(s, ok, base);
1136  if (i < INT_MIN || i > INT_MAX) {
1137  if (ok != 0)
1138  *ok = false;
1139  return 0;
1140  }
1141  return int(i);
1142 }
1143 
1161 uint QLocale::toUInt(const QString &s, bool *ok, int base) const
1162 {
1163  qulonglong i = toULongLong(s, ok, base);
1164  if (i > UINT_MAX) {
1165  if (ok != 0)
1166  *ok = false;
1167  return 0;
1168  }
1169  return uint(i);
1170 }
1171 
1190 qlonglong QLocale::toLongLong(const QString &s, bool *ok, int base) const
1191 {
1196 
1197  return d()->stringToLongLong(s, base, ok, mode);
1198 }
1199 
1200 // ### Qt5: make the return type for toULongLong() qulonglong.
1201 
1220 qlonglong QLocale::toULongLong(const QString &s, bool *ok, int base) const
1221 {
1226 
1227  return d()->stringToUnsLongLong(s, base, ok, mode);
1228 }
1229 
1242 #define QT_MAX_FLOAT 3.4028234663852886e+38
1243 
1244 float QLocale::toFloat(const QString &s, bool *ok) const
1245 {
1246  bool myOk;
1247  double d = toDouble(s, &myOk);
1248  if (!myOk || d > QT_MAX_FLOAT || d < -QT_MAX_FLOAT) {
1249  if (ok != 0)
1250  *ok = false;
1251  return 0.0;
1252  }
1253  if (ok != 0)
1254  *ok = true;
1255  return float(d);
1256 }
1257 
1279 double QLocale::toDouble(const QString &s, bool *ok) const
1280 {
1285 
1286  return d()->stringToDouble(s, ok, mode);
1287 }
1288 
1296 {
1297  int flags = p.numberOptions & OmitGroupSeparator
1298  ? 0
1300 
1301  return d()->longLongToString(i, -1, 10, -1, flags);
1302 }
1303 
1311 {
1312  int flags = p.numberOptions & OmitGroupSeparator
1313  ? 0
1315 
1316  return d()->unsLongLongToString(i, -1, 10, -1, flags);
1317 }
1318 
1325 QString QLocale::toString(const QDate &date, const QString &format) const
1326 {
1327  return d()->dateTimeToString(format, &date, 0, this);
1328 }
1329 
1336 {
1337  if (!date.isValid())
1338  return QString();
1339 
1340 #ifndef QT_NO_SYSTEMLOCALE
1341  if (d() == systemPrivate()) {
1342  QVariant res = systemLocale()->query(format == LongFormat
1344  date);
1345  if (!res.isNull())
1346  return res.toString();
1347  }
1348 #endif
1349 
1350  QString format_str = dateFormat(format);
1351  return toString(date, format_str);
1352 }
1353 
1355 {
1356  int i = 0;
1357  while (i < format.size()) {
1358  if (format.at(i).unicode() == '\'') {
1359  qt_readEscapedFormatString(format, &i);
1360  continue;
1361  }
1362 
1363  if (format.at(i).toLower().unicode() == 'a')
1364  return true;
1365 
1366  ++i;
1367  }
1368  return false;
1369 }
1370 
1372 {
1373 #if defined(Q_OS_WINCE)
1374  TIME_ZONE_INFORMATION info;
1375  DWORD res = GetTimeZoneInformation(&info);
1376  if (res == TIME_ZONE_ID_UNKNOWN)
1377  return QString();
1378  return QString::fromWCharArray(info.StandardName);
1379 #elif defined(Q_OS_WIN)
1380  _tzset();
1381 # if defined(_MSC_VER) && _MSC_VER >= 1400
1382  size_t returnSize = 0;
1383  char timeZoneName[512];
1384  if (_get_tzname(&returnSize, timeZoneName, 512, 1))
1385  return QString();
1386  return QString::fromLocal8Bit(timeZoneName);
1387 # else
1388  return QString::fromLocal8Bit(_tzname[1]);
1389 # endif
1390 #elif defined(Q_OS_VXWORKS)
1391  return QString();
1392 #else
1393  tzset();
1394  return QString::fromLocal8Bit(tzname[1]);
1395 #endif
1396 }
1397 
1403 QString QLocale::toString(const QTime &time, const QString &format) const
1404 {
1405  return d()->dateTimeToString(format, 0, &time, this);
1406 }
1407 
1419 QString QLocale::toString(const QDateTime &dateTime, const QString &format) const
1420 {
1421  const QDate dt = dateTime.date();
1422  const QTime tm = dateTime.time();
1423  return d()->dateTimeToString(format, &dt, &tm, this);
1424 }
1425 
1437 {
1438  if (!dateTime.isValid())
1439  return QString();
1440 
1441 #ifndef QT_NO_SYSTEMLOCALE
1442  if (d() == systemPrivate()) {
1443  QVariant res = systemLocale()->query(format == LongFormat
1446  dateTime);
1447  if (!res.isNull())
1448  return res.toString();
1449  }
1450 #endif
1451 
1452  const QString format_str = dateTimeFormat(format);
1453  return toString(dateTime, format_str);
1454 }
1455 
1456 
1463 {
1464  if (!time.isValid())
1465  return QString();
1466 
1467 #ifndef QT_NO_SYSTEMLOCALE
1468  if (d() == systemPrivate()) {
1469  QVariant res = systemLocale()->query(format == LongFormat
1471  time);
1472  if (!res.isNull())
1473  return res.toString();
1474  }
1475 #endif
1476 
1477  QString format_str = timeFormat(format);
1478  return toString(time, format_str);
1479 }
1480 
1496 {
1497 #ifndef QT_NO_SYSTEMLOCALE
1498  if (d() == systemPrivate()) {
1499  QVariant res = systemLocale()->query(format == LongFormat
1501  QVariant());
1502  if (!res.isNull())
1503  return res.toString();
1504  }
1505 #endif
1506 
1507  quint32 idx, size;
1508  switch (format) {
1509  case LongFormat:
1510  idx = d()->m_long_date_format_idx;
1511  size = d()->m_long_date_format_size;
1512  break;
1513  default:
1514  idx = d()->m_short_date_format_idx;
1515  size = d()->m_short_date_format_size;
1516  break;
1517  }
1518  return getLocaleData(date_format_data + idx, size);
1519 }
1520 
1536 {
1537 #ifndef QT_NO_SYSTEMLOCALE
1538  if (d() == systemPrivate()) {
1539  QVariant res = systemLocale()->query(format == LongFormat
1541  QVariant());
1542  if (!res.isNull())
1543  return res.toString();
1544  }
1545 #endif
1546 
1547  quint32 idx, size;
1548  switch (format) {
1549  case LongFormat:
1550  idx = d()->m_long_time_format_idx;
1551  size = d()->m_long_time_format_size;
1552  break;
1553  default:
1554  idx = d()->m_short_time_format_idx;
1555  size = d()->m_short_time_format_size;
1556  break;
1557  }
1558  return getLocaleData(time_format_data + idx, size);
1559 }
1560 
1576 {
1577 #ifndef QT_NO_SYSTEMLOCALE
1578  if (d() == systemPrivate()) {
1579  QVariant res = systemLocale()->query(format == LongFormat
1582  QVariant());
1583  if (!res.isNull()) {
1584  return res.toString();
1585  }
1586  }
1587 #endif
1588  return dateFormat(format) + QLatin1Char(' ') + timeFormat(format);
1589 }
1590 
1605 #ifndef QT_NO_DATESTRING
1607 {
1608  return toTime(string, timeFormat(format));
1609 }
1610 #endif
1611 
1626 #ifndef QT_NO_DATESTRING
1628 {
1629  return toDate(string, dateFormat(format));
1630 }
1631 #endif
1632 
1648 #ifndef QT_NO_DATESTRING
1650 {
1651  return toDateTime(string, dateTimeFormat(format));
1652 }
1653 #endif
1654 
1669 #ifndef QT_NO_DATESTRING
1670 QTime QLocale::toTime(const QString &string, const QString &format) const
1671 {
1672  QTime time;
1673 #ifndef QT_BOOTSTRAPPED
1675  dt.defaultLocale = *this;
1676  if (dt.parseFormat(format))
1677  dt.fromString(string, 0, &time);
1678 #else
1679  Q_UNUSED(string);
1680  Q_UNUSED(format);
1681 #endif
1682  return time;
1683 }
1684 #endif
1685 
1703 #ifndef QT_NO_DATESTRING
1704 QDate QLocale::toDate(const QString &string, const QString &format) const
1705 {
1706  QDate date;
1707 #ifndef QT_BOOTSTRAPPED
1709  dt.defaultLocale = *this;
1710  if (dt.parseFormat(format))
1711  dt.fromString(string, &date, 0);
1712 #else
1713  Q_UNUSED(string);
1714  Q_UNUSED(format);
1715 #endif
1716  return date;
1717 }
1718 #endif
1719 
1737 #ifndef QT_NO_DATESTRING
1739 {
1740 #ifndef QT_BOOTSTRAPPED
1741  QTime time;
1742  QDate date;
1743 
1745  dt.defaultLocale = *this;
1746  if (dt.parseFormat(format) && dt.fromString(string, &date, &time))
1747  return QDateTime(date, time);
1748 #else
1749  Q_UNUSED(string);
1750  Q_UNUSED(format);
1751 #endif
1752  return QDateTime(QDate(), QTime(-1, -1, -1));
1753 }
1754 #endif
1755 
1756 
1766 {
1767  return d()->decimal();
1768 }
1769 
1779 {
1780  return d()->group();
1781 }
1782 
1792 {
1793  return d()->percent();
1794 }
1795 
1805 {
1806  return d()->zero();
1807 }
1808 
1818 {
1819  return d()->minus();
1820 }
1821 
1831 {
1832  return d()->plus();
1833 }
1834 
1844 {
1845  return d()->exponential();
1846 }
1847 
1848 static bool qIsUpper(char c)
1849 {
1850  return c >= 'A' && c <= 'Z';
1851 }
1852 
1853 static char qToLower(char c)
1854 {
1855  if (c >= 'A' && c <= 'Z')
1856  return c - 'A' + 'a';
1857  else
1858  return c;
1859 }
1860 
1869 QString QLocale::toString(double i, char f, int prec) const
1870 {
1872  uint flags = 0;
1873 
1874  if (qIsUpper(f))
1876  f = qToLower(f);
1877 
1878  switch (f) {
1879  case 'f':
1881  break;
1882  case 'e':
1884  break;
1885  case 'g':
1887  break;
1888  default:
1889  break;
1890  }
1891 
1894  return d()->doubleToString(i, prec, form, -1, flags);
1895 }
1896 
1918 {
1919  QLocale result(C);
1921  return result;
1922 }
1923 
1924 
1940 {
1941  if (uint(language) > QLocale::LastLanguage || uint(script) > QLocale::LastScript ||
1942  uint(country) > QLocale::LastCountry)
1943  return QList<QLocale>();
1944 
1945  QList<QLocale> result;
1946  const QLocalePrivate *d = locale_data;
1947  if (language == QLocale::AnyLanguage && script == QLocale::AnyScript && country == QLocale::AnyCountry)
1948  result.reserve(locale_data_size);
1949  if (language != QLocale::C)
1950  d += locale_index[language];
1951  while ( (d != locale_data + locale_data_size)
1952  && (language == QLocale::AnyLanguage || d->m_language_id == uint(language))) {
1953  QLocale locale(QLocale::C);
1954  locale.p.index = localePrivateIndex(d);
1955  result.append(locale);
1956  ++d;
1957  }
1958  return result;
1959 }
1960 
1975 {
1976  QList<Country> result;
1977 
1978  unsigned language_id = language;
1979  uint idx = locale_index[language_id];
1980 
1981  if (language == C) {
1982  result << AnyCountry;
1983  return result;
1984  }
1985 
1986  const QLocalePrivate *d = locale_data + idx;
1987 
1988  while (d->languageId() == language_id) {
1989  result << static_cast<Country>(d->countryId());
1990  ++d;
1991  }
1992 
1993  return result;
1994 }
1995 
2008 {
2009  if (month < 1 || month > 12)
2010  return QString();
2011 
2012 #ifndef QT_NO_SYSTEMLOCALE
2013  if (d() == systemPrivate()) {
2014  QVariant res = systemLocale()->query(type == LongFormat
2016  month);
2017  if (!res.isNull())
2018  return res.toString();
2019  }
2020 #endif
2021 
2022  quint32 idx, size;
2023  switch (type) {
2024  case QLocale::LongFormat:
2025  idx = d()->m_long_month_names_idx;
2026  size = d()->m_long_month_names_size;
2027  break;
2028  case QLocale::ShortFormat:
2029  idx = d()->m_short_month_names_idx;
2030  size = d()->m_short_month_names_size;
2031  break;
2032  case QLocale::NarrowFormat:
2033  idx = d()->m_narrow_month_names_idx;
2034  size = d()->m_narrow_month_names_size;
2035  break;
2036  default:
2037  return QString();
2038  }
2039  return getLocaleListData(months_data + idx, size, month - 1);
2040 }
2041 
2057 {
2058  if (month < 1 || month > 12)
2059  return QString();
2060 
2061 #ifndef QT_NO_SYSTEMLOCALE
2062  if (d() == systemPrivate()) {
2063  QVariant res = systemLocale()->query(type == LongFormat
2065  month);
2066  if (!res.isNull())
2067  return res.toString();
2068  }
2069 #endif
2070 
2071  quint32 idx, size;
2072  switch (type) {
2073  case QLocale::LongFormat:
2076  break;
2077  case QLocale::ShortFormat:
2080  break;
2081  case QLocale::NarrowFormat:
2084  break;
2085  default:
2086  return QString();
2087  }
2088  QString name = getLocaleListData(standalone_months_data + idx, size, month - 1);
2089  if (name.isEmpty())
2090  return monthName(month, type);
2091  return name;
2092 }
2093 
2107 {
2108  if (day < 1 || day > 7)
2109  return QString();
2110 
2111 #ifndef QT_NO_SYSTEMLOCALE
2112  if (d() == systemPrivate()) {
2113  QVariant res = systemLocale()->query(type == LongFormat
2115  day);
2116  if (!res.isNull())
2117  return res.toString();
2118  }
2119 #endif
2120  if (day == 7)
2121  day = 0;
2122 
2123  quint32 idx, size;
2124  switch (type) {
2125  case QLocale::LongFormat:
2126  idx = d()->m_long_day_names_idx;
2127  size = d()->m_long_day_names_size;
2128  break;
2129  case QLocale::ShortFormat:
2130  idx = d()->m_short_day_names_idx;
2131  size = d()->m_short_day_names_size;
2132  break;
2133  case QLocale::NarrowFormat:
2134  idx = d()->m_narrow_day_names_idx;
2135  size = d()->m_narrow_day_names_size;
2136  break;
2137  default:
2138  return QString();
2139  }
2140  return getLocaleListData(days_data + idx, size, day);
2141 }
2142 
2159 {
2160  if (day < 1 || day > 7)
2161  return QString();
2162 
2163 #ifndef QT_NO_SYSTEMLOCALE
2164  if (d() == systemPrivate()) {
2165  QVariant res = systemLocale()->query(type == LongFormat
2167  day);
2168  if (!res.isNull())
2169  return res.toString();
2170  }
2171 #endif
2172  if (day == 7)
2173  day = 0;
2174 
2175  quint32 idx, size;
2176  switch (type) {
2177  case QLocale::LongFormat:
2180  break;
2181  case QLocale::ShortFormat:
2184  break;
2185  case QLocale::NarrowFormat:
2188  break;
2189  default:
2190  return QString();
2191  }
2192  QString name = getLocaleListData(days_data + idx, size, day);
2193  if (name.isEmpty())
2194  return dayName(day == 0 ? 7 : day, type);
2195  return name;
2196 }
2197 
2207 {
2208 #ifndef QT_NO_SYSTEMLOCALE
2209  if (d() == systemPrivate()) {
2211  if (!res.isNull())
2212  return static_cast<Qt::DayOfWeek>(res.toUInt());
2213  }
2214 #endif
2215  return static_cast<Qt::DayOfWeek>(d()->m_first_day_of_week);
2216 }
2217 
2219 {
2220  for (int i = 0; i < ImperialMeasurementSystemsCount; ++i) {
2221  if (ImperialMeasurementSystems[i].languageId == m_language_id
2222  && ImperialMeasurementSystems[i].countryId == m_country_id) {
2223  return QLocale::ImperialSystem;
2224  }
2225  }
2226  return QLocale::MetricSystem;
2227 }
2228 
2238 {
2239 #ifndef QT_NO_SYSTEMLOCALE
2240  if (d() == systemPrivate()) {
2242  if (!res.isNull())
2243  return static_cast<QList<Qt::DayOfWeek> >(res.value<QList<Qt::DayOfWeek> >());
2244  }
2245 #endif
2247  quint16 weekendStart = d()->m_weekend_start;
2248  quint16 weekendEnd = d()->m_weekend_end;
2249  for (int day = Qt::Monday; day <= Qt::Sunday; day++) {
2250  if ((weekendEnd >= weekendStart && (day < weekendStart || day > weekendEnd)) ||
2251  (weekendEnd < weekendStart && (day > weekendEnd && day < weekendStart)))
2252  weekdays << static_cast<Qt::DayOfWeek>(day);
2253  }
2254  return weekdays;
2255 }
2256 
2266 {
2267 #ifndef QT_NO_SYSTEMLOCALE
2268  if (d() == systemPrivate()) {
2270  if (!res.isNull())
2271  return MeasurementSystem(res.toInt());
2272  }
2273 #endif
2274 
2275  return d()->measurementSystem();
2276 }
2277 
2287 {
2288  Language lang = language();
2289  if (lang == QLocale::Arabic ||
2290  lang == QLocale::Hebrew ||
2291  lang == QLocale::Persian ||
2292  lang == QLocale::Urdu ||
2293  lang == QLocale::Syriac)
2294  return Qt::RightToLeft;
2295 
2296  return Qt::LeftToRight;
2297 }
2298 
2308 {
2309 #ifdef QT_USE_ICU
2310  {
2311  QString result;
2312  if (qt_u_strToUpper(str, &result, *this))
2313  return result;
2314  // else fall through and use Qt's toUpper
2315  }
2316 #endif
2317  return str.toUpper();
2318 }
2319 
2329 {
2330 #ifdef QT_USE_ICU
2331  {
2332  QString result;
2333  if (qt_u_strToLower(str, &result, *this))
2334  return result;
2335  // else fall through and use Qt's toUpper
2336  }
2337 #endif
2338  return str.toLower();
2339 }
2340 
2341 
2354 {
2355 #ifndef QT_NO_SYSTEMLOCALE
2356  if (d() == systemPrivate()) {
2358  if (!res.isNull())
2359  return res.toString();
2360  }
2361 #endif
2362  return getLocaleData(am_data + d()->m_am_idx, d()->m_am_size);
2363 }
2364 
2377 {
2378 #ifndef QT_NO_SYSTEMLOCALE
2379  if (d() == systemPrivate()) {
2381  if (!res.isNull())
2382  return res.toString();
2383  }
2384 #endif
2385  return getLocaleData(pm_data + d()->m_pm_idx, d()->m_pm_size);
2386 }
2387 
2388 
2390  const QLocale *q) const
2391 {
2392  Q_ASSERT(date || time);
2393  if ((date && !date->isValid()) || (time && !time->isValid()))
2394  return QString();
2395  const bool format_am_pm = time && timeFormatContainsAP(format);
2396 
2397  enum { AM, PM } am_pm = AM;
2398  int hour12 = time ? time->hour() : -1;
2399  if (time) {
2400  if (hour12 == 0) {
2401  am_pm = AM;
2402  hour12 = 12;
2403  } else if (hour12 < 12) {
2404  am_pm = AM;
2405  } else if (hour12 == 12) {
2406  am_pm = PM;
2407  } else {
2408  am_pm = PM;
2409  hour12 -= 12;
2410  }
2411  }
2412 
2413  QString result;
2414 
2415  int i = 0;
2416  while (i < format.size()) {
2417  if (format.at(i).unicode() == '\'') {
2418  result.append(qt_readEscapedFormatString(format, &i));
2419  continue;
2420  }
2421 
2422  const QChar c = format.at(i);
2423  int repeat = qt_repeatCount(format, i);
2424  bool used = false;
2425  if (date) {
2426  switch (c.unicode()) {
2427  case 'y':
2428  used = true;
2429  if (repeat >= 4)
2430  repeat = 4;
2431  else if (repeat >= 2)
2432  repeat = 2;
2433 
2434  switch (repeat) {
2435  case 4:
2436  result.append(longLongToString(date->year()));
2437  break;
2438  case 2:
2439  result.append(longLongToString(date->year() % 100, -1, 10, 2,
2441  break;
2442  default:
2443  repeat = 1;
2444  result.append(c);
2445  break;
2446  }
2447  break;
2448 
2449  case 'M':
2450  used = true;
2451  repeat = qMin(repeat, 4);
2452  switch (repeat) {
2453  case 1:
2454  result.append(longLongToString(date->month()));
2455  break;
2456  case 2:
2457  result.append(longLongToString(date->month(), -1, 10, 2, QLocalePrivate::ZeroPadded));
2458  break;
2459  case 3:
2460  result.append(q->monthName(date->month(), QLocale::ShortFormat));
2461  break;
2462  case 4:
2463  result.append(q->monthName(date->month(), QLocale::LongFormat));
2464  break;
2465  }
2466  break;
2467 
2468  case 'd':
2469  used = true;
2470  repeat = qMin(repeat, 4);
2471  switch (repeat) {
2472  case 1:
2473  result.append(longLongToString(date->day()));
2474  break;
2475  case 2:
2476  result.append(longLongToString(date->day(), -1, 10, 2, QLocalePrivate::ZeroPadded));
2477  break;
2478  case 3:
2479  result.append(q->dayName(date->dayOfWeek(), QLocale::ShortFormat));
2480  break;
2481  case 4:
2482  result.append(q->dayName(date->dayOfWeek(), QLocale::LongFormat));
2483  break;
2484  }
2485  break;
2486 
2487  default:
2488  break;
2489  }
2490  }
2491  if (!used && time) {
2492  switch (c.unicode()) {
2493  case 'h': {
2494  used = true;
2495  repeat = qMin(repeat, 2);
2496  const int hour = format_am_pm ? hour12 : time->hour();
2497 
2498  switch (repeat) {
2499  case 1:
2500  result.append(longLongToString(hour));
2501  break;
2502  case 2:
2503  result.append(longLongToString(hour, -1, 10, 2, QLocalePrivate::ZeroPadded));
2504  break;
2505  }
2506  break;
2507  }
2508  case 'H':
2509  used = true;
2510  repeat = qMin(repeat, 2);
2511  switch (repeat) {
2512  case 1:
2513  result.append(longLongToString(time->hour()));
2514  break;
2515  case 2:
2516  result.append(longLongToString(time->hour(), -1, 10, 2, QLocalePrivate::ZeroPadded));
2517  break;
2518  }
2519  break;
2520 
2521  case 'm':
2522  used = true;
2523  repeat = qMin(repeat, 2);
2524  switch (repeat) {
2525  case 1:
2526  result.append(longLongToString(time->minute()));
2527  break;
2528  case 2:
2529  result.append(longLongToString(time->minute(), -1, 10, 2, QLocalePrivate::ZeroPadded));
2530  break;
2531  }
2532  break;
2533 
2534  case 's':
2535  used = true;
2536  repeat = qMin(repeat, 2);
2537  switch (repeat) {
2538  case 1:
2539  result.append(longLongToString(time->second()));
2540  break;
2541  case 2:
2542  result.append(longLongToString(time->second(), -1, 10, 2, QLocalePrivate::ZeroPadded));
2543  break;
2544  }
2545  break;
2546 
2547  case 'a':
2548  used = true;
2549  if (i + 1 < format.length() && format.at(i + 1).unicode() == 'p') {
2550  repeat = 2;
2551  } else {
2552  repeat = 1;
2553  }
2554  result.append(am_pm == AM ? q->amText().toLower() : q->pmText().toLower());
2555  break;
2556 
2557  case 'A':
2558  used = true;
2559  if (i + 1 < format.length() && format.at(i + 1).unicode() == 'P') {
2560  repeat = 2;
2561  } else {
2562  repeat = 1;
2563  }
2564  result.append(am_pm == AM ? q->amText().toUpper() : q->pmText().toUpper());
2565  break;
2566 
2567  case 'z':
2568  used = true;
2569  if (repeat >= 3) {
2570  repeat = 3;
2571  } else {
2572  repeat = 1;
2573  }
2574  switch (repeat) {
2575  case 1:
2576  result.append(longLongToString(time->msec()));
2577  break;
2578  case 3:
2579  result.append(longLongToString(time->msec(), -1, 10, 3, QLocalePrivate::ZeroPadded));
2580  break;
2581  }
2582  break;
2583 
2584  case 't':
2585  used = true;
2586  repeat = 1;
2587  result.append(timeZone());
2588  break;
2589  default:
2590  break;
2591  }
2592  }
2593  if (!used) {
2594  result.append(QString(repeat, c));
2595  }
2596  i += repeat;
2597  }
2598 
2599  return result;
2600 }
2601 
2603  int precision,
2604  DoubleForm form,
2605  int width,
2606  unsigned flags) const
2607 {
2608  return QLocalePrivate::doubleToString(zero(), plus(), minus(), exponential(),
2609  group(), decimal(),
2610  d, precision, form, width, flags);
2611 }
2612 
2613 QString QLocalePrivate::doubleToString(const QChar _zero, const QChar plus, const QChar minus,
2614  const QChar exponential, const QChar group, const QChar decimal,
2615  double d,
2616  int precision,
2617  DoubleForm form,
2618  int width,
2619  unsigned flags)
2620 {
2621  if (precision == -1)
2622  precision = 6;
2623  if (width == -1)
2624  width = 0;
2625 
2626  bool negative = false;
2627  bool special_number = false; // nan, +/-inf
2628  QString num_str;
2629 
2630  // Detect special numbers (nan, +/-inf)
2631  if (qt_is_inf(d)) {
2632  num_str = QString::fromLatin1("inf");
2633  special_number = true;
2634  negative = d < 0;
2635  } else if (qt_is_nan(d)) {
2636  num_str = QString::fromLatin1("nan");
2637  special_number = true;
2638  }
2639 
2640  // Handle normal numbers
2641  if (!special_number) {
2642  int decpt, sign;
2643  QString digits;
2644 
2645 #ifdef QT_QLOCALE_USES_FCVT
2646  // NOT thread safe!
2647  if (form == DFDecimal) {
2648  digits = QLatin1String(fcvt(d, precision, &decpt, &sign));
2649  } else {
2650  int pr = precision;
2651  if (form == DFExponent)
2652  ++pr;
2653  else if (form == DFSignificantDigits && pr == 0)
2654  pr = 1;
2655  digits = QLatin1String(ecvt(d, pr, &decpt, &sign));
2656 
2657  // Chop trailing zeros
2658  if (digits.length() > 0) {
2659  int last_nonzero_idx = digits.length() - 1;
2660  while (last_nonzero_idx > 0
2661  && digits.unicode()[last_nonzero_idx] == QLatin1Char('0'))
2662  --last_nonzero_idx;
2663  digits.truncate(last_nonzero_idx + 1);
2664  }
2665 
2666  }
2667 
2668 #else
2669  int mode;
2670  if (form == DFDecimal)
2671  mode = 3;
2672  else
2673  mode = 2;
2674 
2675  /* This next bit is a bit quirky. In DFExponent form, the precision
2676  is the number of digits after decpt. So that would suggest using
2677  mode=3 for qdtoa. But qdtoa behaves strangely when mode=3 and
2678  precision=0. So we get around this by using mode=2 and reasoning
2679  that we want precision+1 significant digits, since the decimal
2680  point in this mode is always after the first digit. */
2681  int pr = precision;
2682  if (form == DFExponent)
2683  ++pr;
2684 
2685  char *rve = 0;
2686  char *buff = 0;
2687  QT_TRY {
2688  digits = QLatin1String(qdtoa(d, mode, pr, &decpt, &sign, &rve, &buff));
2689  } QT_CATCH(...) {
2690  if (buff != 0)
2691  free(buff);
2692  QT_RETHROW;
2693  }
2694  if (buff != 0)
2695  free(buff);
2696 #endif // QT_QLOCALE_USES_FCVT
2697 
2698  if (_zero.unicode() != '0') {
2699  ushort z = _zero.unicode() - '0';
2700  for (int i = 0; i < digits.length(); ++i)
2701  reinterpret_cast<ushort *>(digits.data())[i] += z;
2702  }
2703 
2704  bool always_show_decpt = (flags & Alternate || flags & ForcePoint);
2705  switch (form) {
2706  case DFExponent: {
2707  num_str = exponentForm(_zero, decimal, exponential, group, plus, minus,
2708  digits, decpt, precision, PMDecimalDigits,
2709  always_show_decpt);
2710  break;
2711  }
2712  case DFDecimal: {
2713  num_str = decimalForm(_zero, decimal, group,
2714  digits, decpt, precision, PMDecimalDigits,
2715  always_show_decpt, flags & ThousandsGroup);
2716  break;
2717  }
2718  case DFSignificantDigits: {
2719  PrecisionMode mode = (flags & Alternate) ?
2721 
2722  if (decpt != digits.length() && (decpt <= -4 || decpt > precision))
2723  num_str = exponentForm(_zero, decimal, exponential, group, plus, minus,
2724  digits, decpt, precision, mode,
2725  always_show_decpt);
2726  else
2727  num_str = decimalForm(_zero, decimal, group,
2728  digits, decpt, precision, mode,
2729  always_show_decpt, flags & ThousandsGroup);
2730  break;
2731  }
2732  }
2733 
2734  negative = sign != 0 && !isZero(d);
2735  }
2736 
2737  // pad with zeros. LeftAdjusted overrides this flag). Also, we don't
2738  // pad special numbers
2739  if (flags & QLocalePrivate::ZeroPadded
2740  && !(flags & QLocalePrivate::LeftAdjusted)
2741  && !special_number) {
2742  int num_pad_chars = width - num_str.length();
2743  // leave space for the sign
2744  if (negative
2747  --num_pad_chars;
2748 
2749  for (int i = 0; i < num_pad_chars; ++i)
2750  num_str.prepend(_zero);
2751  }
2752 
2753  // add sign
2754  if (negative)
2755  num_str.prepend(minus);
2756  else if (flags & QLocalePrivate::AlwaysShowSign)
2757  num_str.prepend(plus);
2758  else if (flags & QLocalePrivate::BlankBeforePositive)
2759  num_str.prepend(QLatin1Char(' '));
2760 
2761  if (flags & QLocalePrivate::CapitalEorX)
2762  num_str = num_str.toUpper();
2763 
2764  return num_str;
2765 }
2766 
2768  int base, int width,
2769  unsigned flags) const
2770 {
2771  return QLocalePrivate::longLongToString(zero(), group(), plus(), minus(),
2772  l, precision, base, width, flags);
2773 }
2774 
2776  const QChar plus, const QChar minus,
2777  qlonglong l, int precision,
2778  int base, int width,
2779  unsigned flags)
2780 {
2781  bool precision_not_specified = false;
2782  if (precision == -1) {
2783  precision_not_specified = true;
2784  precision = 1;
2785  }
2786 
2787  bool negative = l < 0;
2788  if (base != 10) {
2789  // these are not supported by sprintf for octal and hex
2790  flags &= ~AlwaysShowSign;
2791  flags &= ~BlankBeforePositive;
2792  negative = false; // neither are negative numbers
2793  }
2794 
2795  QString num_str;
2796  if (base == 10)
2797  num_str = qlltoa(l, base, zero);
2798  else
2799  num_str = qulltoa(l, base, zero);
2800 
2801  uint cnt_thousand_sep = 0;
2802  if (flags & ThousandsGroup && base == 10) {
2803  for (int i = num_str.length() - 3; i > 0; i -= 3) {
2804  num_str.insert(i, group);
2805  ++cnt_thousand_sep;
2806  }
2807  }
2808 
2809  for (int i = num_str.length()/* - cnt_thousand_sep*/; i < precision; ++i)
2810  num_str.prepend(base == 10 ? zero : QChar::fromLatin1('0'));
2811 
2812  if ((flags & Alternate || flags & ShowBase)
2813  && base == 8
2814  && (num_str.isEmpty() || num_str[0].unicode() != QLatin1Char('0')))
2815  num_str.prepend(QLatin1Char('0'));
2816 
2817  // LeftAdjusted overrides this flag ZeroPadded. sprintf only padds
2818  // when precision is not specified in the format string
2819  bool zero_padded = flags & ZeroPadded
2820  && !(flags & LeftAdjusted)
2821  && precision_not_specified;
2822 
2823  if (zero_padded) {
2824  int num_pad_chars = width - num_str.length();
2825 
2826  // leave space for the sign
2827  if (negative
2828  || flags & AlwaysShowSign
2829  || flags & BlankBeforePositive)
2830  --num_pad_chars;
2831 
2832  // leave space for optional '0x' in hex form
2833  if (base == 16 && (flags & Alternate || flags & ShowBase))
2834  num_pad_chars -= 2;
2835  // leave space for optional '0b' in binary form
2836  else if (base == 2 && (flags & Alternate || flags & ShowBase))
2837  num_pad_chars -= 2;
2838 
2839  for (int i = 0; i < num_pad_chars; ++i)
2840  num_str.prepend(base == 10 ? zero : QChar::fromLatin1('0'));
2841  }
2842 
2843  if (flags & CapitalEorX)
2844  num_str = num_str.toUpper();
2845 
2846  if (base == 16 && (flags & Alternate || flags & ShowBase))
2847  num_str.prepend(QLatin1String(flags & UppercaseBase ? "0X" : "0x"));
2848  if (base == 2 && (flags & Alternate || flags & ShowBase))
2849  num_str.prepend(QLatin1String(flags & UppercaseBase ? "0B" : "0b"));
2850 
2851  // add sign
2852  if (negative)
2853  num_str.prepend(minus);
2854  else if (flags & AlwaysShowSign)
2855  num_str.prepend(plus);
2856  else if (flags & BlankBeforePositive)
2857  num_str.prepend(QLatin1Char(' '));
2858 
2859  return num_str;
2860 }
2861 
2863  int base, int width,
2864  unsigned flags) const
2865 {
2866  return QLocalePrivate::unsLongLongToString(zero(), group(), plus(),
2867  l, precision, base, width, flags);
2868 }
2869 
2871  const QChar plus,
2872  qulonglong l, int precision,
2873  int base, int width,
2874  unsigned flags)
2875 {
2876  bool precision_not_specified = false;
2877  if (precision == -1) {
2878  precision_not_specified = true;
2879  precision = 1;
2880  }
2881 
2882  QString num_str = qulltoa(l, base, zero);
2883 
2884  uint cnt_thousand_sep = 0;
2885  if (flags & ThousandsGroup && base == 10) {
2886  for (int i = num_str.length() - 3; i > 0; i -=3) {
2887  num_str.insert(i, group);
2888  ++cnt_thousand_sep;
2889  }
2890  }
2891 
2892  for (int i = num_str.length()/* - cnt_thousand_sep*/; i < precision; ++i)
2893  num_str.prepend(base == 10 ? zero : QChar::fromLatin1('0'));
2894 
2895  if ((flags & Alternate || flags & ShowBase)
2896  && base == 8
2897  && (num_str.isEmpty() || num_str[0].unicode() != QLatin1Char('0')))
2898  num_str.prepend(QLatin1Char('0'));
2899 
2900  // LeftAdjusted overrides this flag ZeroPadded. sprintf only padds
2901  // when precision is not specified in the format string
2902  bool zero_padded = flags & ZeroPadded
2903  && !(flags & LeftAdjusted)
2904  && precision_not_specified;
2905 
2906  if (zero_padded) {
2907  int num_pad_chars = width - num_str.length();
2908 
2909  // leave space for optional '0x' in hex form
2910  if (base == 16 && flags & Alternate)
2911  num_pad_chars -= 2;
2912  // leave space for optional '0b' in binary form
2913  else if (base == 2 && flags & Alternate)
2914  num_pad_chars -= 2;
2915 
2916  for (int i = 0; i < num_pad_chars; ++i)
2917  num_str.prepend(base == 10 ? zero : QChar::fromLatin1('0'));
2918  }
2919 
2920  if (flags & CapitalEorX)
2921  num_str = num_str.toUpper();
2922 
2923  if (base == 16 && (flags & Alternate || flags & ShowBase))
2924  num_str.prepend(QLatin1String(flags & UppercaseBase ? "0X" : "0x"));
2925  else if (base == 2 && (flags & Alternate || flags & ShowBase))
2926  num_str.prepend(QLatin1String(flags & UppercaseBase ? "0B" : "0b"));
2927 
2928  // add sign
2929  if (flags & AlwaysShowSign)
2930  num_str.prepend(plus);
2931  else if (flags & BlankBeforePositive)
2932  num_str.prepend(QLatin1Char(' '));
2933 
2934  return num_str;
2935 }
2936 
2937 /*
2938  Converts a number in locale to its representation in the C locale.
2939  Only has to guarantee that a string that is a correct representation of
2940  a number will be converted. If junk is passed in, junk will be passed
2941  out and the error will be detected during the actual conversion to a
2942  number. We can't detect junk here, since we don't even know the base
2943  of the number.
2944 */
2946  GroupSeparatorMode group_sep_mode,
2947  CharBuff *result) const
2948 {
2949  const QChar *uc = num.unicode();
2950  int l = num.length();
2951  int idx = 0;
2952 
2953  // Skip whitespace
2954  while (idx < l && uc[idx].isSpace())
2955  ++idx;
2956  if (idx == l)
2957  return false;
2958 
2959  while (idx < l) {
2960  const QChar &in = uc[idx];
2961 
2962  char out = digitToCLocale(in);
2963  if (out == 0) {
2964  if (in == list())
2965  out = ';';
2966  else if (in == percent())
2967  out = '%';
2968  // for handling base-x numbers
2969  else if (in.unicode() >= 'A' && in.unicode() <= 'Z')
2970  out = in.toLower().toLatin1();
2971  else if (in.unicode() >= 'a' && in.unicode() <= 'z')
2972  out = in.toLatin1();
2973  else
2974  break;
2975  }
2976 
2977  result->append(out);
2978 
2979  ++idx;
2980  }
2981 
2982  // Check trailing whitespace
2983  for (; idx < l; ++idx) {
2984  if (!uc[idx].isSpace())
2985  return false;
2986  }
2987 
2988  result->append('\0');
2989 
2990  // Check separators
2991  if (group_sep_mode == ParseGroupSeparators
2992  && !removeGroupSeparators(result))
2993  return false;
2994 
2995 
2996  return true;
2997 }
2998 
3000  int decDigits) const
3001 {
3002  buff->clear();
3003  buff->reserve(str.length());
3004 
3005  const bool scientific = numMode == DoubleScientificMode;
3006  bool lastWasE = false;
3007  bool lastWasDigit = false;
3008  int eCnt = 0;
3009  int decPointCnt = 0;
3010  bool dec = false;
3011  int decDigitCnt = 0;
3012 
3013  for (int i = 0; i < str.length(); ++i) {
3014  char c = digitToCLocale(str.at(i));
3015 
3016  if (c >= '0' && c <= '9') {
3017  if (numMode != IntegerMode) {
3018  // If a double has too many digits after decpt, it shall be Invalid.
3019  if (dec && decDigits != -1 && decDigits < ++decDigitCnt)
3020  return false;
3021  }
3022  lastWasDigit = true;
3023  } else {
3024  switch (c) {
3025  case '.':
3026  if (numMode == IntegerMode) {
3027  // If an integer has a decimal point, it shall be Invalid.
3028  return false;
3029  } else {
3030  // If a double has more than one decimal point, it shall be Invalid.
3031  if (++decPointCnt > 1)
3032  return false;
3033 #if 0
3034  // If a double with no decimal digits has a decimal point, it shall be
3035  // Invalid.
3036  if (decDigits == 0)
3037  return false;
3038 #endif // On second thoughts, it shall be Valid.
3039 
3040  dec = true;
3041  }
3042  break;
3043 
3044  case '+':
3045  case '-':
3046  if (scientific) {
3047  // If a scientific has a sign that's not at the beginning or after
3048  // an 'e', it shall be Invalid.
3049  if (i != 0 && !lastWasE)
3050  return false;
3051  } else {
3052  // If a non-scientific has a sign that's not at the beginning,
3053  // it shall be Invalid.
3054  if (i != 0)
3055  return false;
3056  }
3057  break;
3058 
3059  case ',':
3060  //it can only be placed after a digit which is before the decimal point
3061  if (!lastWasDigit || decPointCnt > 0)
3062  return false;
3063  break;
3064 
3065  case 'e':
3066  if (scientific) {
3067  // If a scientific has more than one 'e', it shall be Invalid.
3068  if (++eCnt > 1)
3069  return false;
3070  dec = false;
3071  } else {
3072  // If a non-scientific has an 'e', it shall be Invalid.
3073  return false;
3074  }
3075  break;
3076 
3077  default:
3078  // If it's not a valid digit, it shall be Invalid.
3079  return false;
3080  }
3081  lastWasDigit = false;
3082  }
3083 
3084  lastWasE = c == 'e';
3085  if (c != ',')
3086  buff->append(c);
3087  }
3088 
3089  return true;
3090 }
3091 
3092 double QLocalePrivate::stringToDouble(const QString &number, bool *ok,
3093  GroupSeparatorMode group_sep_mode) const
3094 {
3095  CharBuff buff;
3096  if (!numberToCLocale(group().unicode() == 0xa0 ? number.trimmed() : number,
3097  group_sep_mode, &buff)) {
3098  if (ok != 0)
3099  *ok = false;
3100  return 0.0;
3101  }
3102  return bytearrayToDouble(buff.constData(), ok);
3103 }
3104 
3106  bool *ok, GroupSeparatorMode group_sep_mode) const
3107 {
3108  CharBuff buff;
3109  if (!numberToCLocale(group().unicode() == 0xa0 ? number.trimmed() : number,
3110  group_sep_mode, &buff)) {
3111  if (ok != 0)
3112  *ok = false;
3113  return 0;
3114  }
3115 
3116  return bytearrayToLongLong(buff.constData(), base, ok);
3117 }
3118 
3120  bool *ok, GroupSeparatorMode group_sep_mode) const
3121 {
3122  CharBuff buff;
3123  if (!numberToCLocale(group().unicode() == 0xa0 ? number.trimmed() : number,
3124  group_sep_mode, &buff)) {
3125  if (ok != 0)
3126  *ok = false;
3127  return 0;
3128  }
3129 
3130  return bytearrayToUnsLongLong(buff.constData(), base, ok);
3131 }
3132 
3133 
3134 double QLocalePrivate::bytearrayToDouble(const char *num, bool *ok, bool *overflow)
3135 {
3136  if (ok != 0)
3137  *ok = true;
3138  if (overflow != 0)
3139  *overflow = false;
3140 
3141  if (*num == '\0') {
3142  if (ok != 0)
3143  *ok = false;
3144  return 0.0;
3145  }
3146 
3147  if (qstrcmp(num, "nan") == 0)
3148  return qt_snan();
3149 
3150  if (qstrcmp(num, "+inf") == 0 || qstrcmp(num, "inf") == 0)
3151  return qt_inf();
3152 
3153  if (qstrcmp(num, "-inf") == 0)
3154  return -qt_inf();
3155 
3156  bool _ok;
3157  const char *endptr;
3158  double d = qstrtod(num, &endptr, &_ok);
3159 
3160  if (!_ok) {
3161  // the only way strtod can fail with *endptr != '\0' on a non-empty
3162  // input string is overflow
3163  if (ok != 0)
3164  *ok = false;
3165  if (overflow != 0)
3166  *overflow = *endptr != '\0';
3167  return 0.0;
3168  }
3169 
3170  if (*endptr != '\0') {
3171  // we stopped at a non-digit character after converting some digits
3172  if (ok != 0)
3173  *ok = false;
3174  if (overflow != 0)
3175  *overflow = false;
3176  return 0.0;
3177  }
3178 
3179  if (ok != 0)
3180  *ok = true;
3181  if (overflow != 0)
3182  *overflow = false;
3183  return d;
3184 }
3185 
3186 qlonglong QLocalePrivate::bytearrayToLongLong(const char *num, int base, bool *ok, bool *overflow)
3187 {
3188  bool _ok;
3189  const char *endptr;
3190 
3191  if (*num == '\0') {
3192  if (ok != 0)
3193  *ok = false;
3194  if (overflow != 0)
3195  *overflow = false;
3196  return 0;
3197  }
3198 
3199  qlonglong l = qstrtoll(num, &endptr, base, &_ok);
3200 
3201  if (!_ok) {
3202  if (ok != 0)
3203  *ok = false;
3204  if (overflow != 0) {
3205  // the only way qstrtoll can fail with *endptr != '\0' on a non-empty
3206  // input string is overflow
3207  *overflow = *endptr != '\0';
3208  }
3209  return 0;
3210  }
3211 
3212  if (*endptr != '\0') {
3213  // we stopped at a non-digit character after converting some digits
3214  if (ok != 0)
3215  *ok = false;
3216  if (overflow != 0)
3217  *overflow = false;
3218  return 0;
3219  }
3220 
3221  if (ok != 0)
3222  *ok = true;
3223  if (overflow != 0)
3224  *overflow = false;
3225  return l;
3226 }
3227 
3229 {
3230  bool _ok;
3231  const char *endptr;
3232  qulonglong l = qstrtoull(num, &endptr, base, &_ok);
3233 
3234  if (!_ok || *endptr != '\0') {
3235  if (ok != 0)
3236  *ok = false;
3237  return 0;
3238  }
3239 
3240  if (ok != 0)
3241  *ok = true;
3242  return l;
3243 }
3244 
3268 {
3269 #ifndef QT_NO_SYSTEMLOCALE
3270  if (d() == systemPrivate()) {
3272  if (!res.isNull())
3273  return res.toString();
3274  }
3275 #endif
3276  quint32 idx, size;
3277  switch (format) {
3278  case CurrencySymbol:
3279  idx = d()->m_currency_symbol_idx;
3280  size = d()->m_currency_symbol_size;
3281  return getLocaleData(currency_symbol_data + idx, size);
3282  case CurrencyDisplayName:
3283  idx = d()->m_currency_display_name_idx;
3284  size = d()->m_currency_display_name_size;
3285  return getLocaleListData(currency_display_name_data + idx, size, 0);
3286  case CurrencyIsoCode: {
3287  int len = 0;
3288  const QLocalePrivate *d = this->d();
3289  for (; len < 3; ++len)
3290  if (!d->m_currency_iso_code[len])
3291  break;
3292  return len ? QString::fromLatin1(d->m_currency_iso_code, len) : QString();
3293  }
3294  }
3295  return QString();
3296 }
3297 
3310 {
3311 #ifndef QT_NO_SYSTEMLOCALE
3312  if (d() == systemPrivate()) {
3313  QSystemLocale::CurrencyToStringArgument arg(value, symbol);
3315  if (!res.isNull())
3316  return res.toString();
3317  }
3318 #endif
3319  const QLocalePrivate *d = this->d();
3320  quint8 idx = d->m_currency_format_idx;
3321  quint8 size = d->m_currency_format_size;
3322  if (d->m_currency_negative_format_size && value < 0) {
3325  value = -value;
3326  }
3327  QString str = d->longLongToString(value);
3328  QString sym = symbol.isNull() ? currencySymbol() : symbol;
3329  if (sym.isEmpty())
3332  return format.arg(str, sym);
3333 }
3334 
3340 {
3341 #ifndef QT_NO_SYSTEMLOCALE
3342  if (d() == systemPrivate()) {
3343  QSystemLocale::CurrencyToStringArgument arg(value, symbol);
3345  if (!res.isNull())
3346  return res.toString();
3347  }
3348 #endif
3349  const QLocalePrivate *d = this->d();
3350  quint8 idx = d->m_currency_format_idx;
3351  quint8 size = d->m_currency_format_size;
3352  QString str = d->unsLongLongToString(value);
3353  QString sym = symbol.isNull() ? currencySymbol() : symbol;
3354  if (sym.isEmpty())
3357  return format.arg(str, sym);
3358 }
3359 
3364 QString QLocale::toCurrencyString(double value, const QString &symbol) const
3365 {
3366 #ifndef QT_NO_SYSTEMLOCALE
3367  if (d() == systemPrivate()) {
3368  QSystemLocale::CurrencyToStringArgument arg(value, symbol);
3370  if (!res.isNull())
3371  return res.toString();
3372  }
3373 #endif
3374  const QLocalePrivate *d = this->d();
3375  quint8 idx = d->m_currency_format_idx;
3376  quint8 size = d->m_currency_format_size;
3377  if (d->m_currency_negative_format_size && value < 0) {
3380  value = -value;
3381  }
3382  QString str = d->doubleToString(value, d->m_currency_digits,
3384  QString sym = symbol.isNull() ? currencySymbol() : symbol;
3385  if (sym.isEmpty())
3388  return format.arg(str, sym);
3389 }
3390 
3411 {
3412 #ifndef QT_NO_SYSTEMLOCALE
3413  if (d() == systemPrivate()) {
3415  if (!res.isNull()) {
3416  QStringList result = res.toStringList();
3417  if (!result.isEmpty())
3418  return result;
3419  }
3420  }
3421 #endif
3422  return QStringList(bcp47Name());
3423 }
3424 
3437 {
3438 #ifndef QT_NO_SYSTEMLOCALE
3439  if (d() == systemPrivate()) {
3441  if (!res.isNull())
3442  return res.toString();
3443  }
3444 #endif
3445  return getLocaleData(endonyms_data + d()->m_language_endonym_idx, d()->m_language_endonym_size);
3446 }
3447 
3460 {
3461 #ifndef QT_NO_SYSTEMLOCALE
3462  if (d() == systemPrivate()) {
3464  if (!res.isNull())
3465  return res.toString();
3466  }
3467 #endif
3468  return getLocaleData(endonyms_data + d()->m_country_endonym_idx, d()->m_country_endonym_size);
3469 }
3470 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
int dayOfWeek() const
Returns the weekday (1 = Monday to 7 = Sunday) for this date.
Definition: qdatetime.cpp:408
static void updateSystemPrivate()
Definition: qlocale.cpp:478
double d
Definition: qnumeric_p.h:62
quint16 m_standalone_long_month_names_idx
Definition: qlocale_p.h:196
const T * constData() const
QChar positiveSign() const
Returns the positive sign character of this locale.
Definition: qlocale.cpp:1830
virtual ~QSystemLocale()
Deletes the object.
Definition: qlocale.cpp:461
QChar group() const
Definition: qlocale_p.h:72
quint16 m_standalone_long_month_names_size
Definition: qlocale_p.h:196
QChar decimal() const
Definition: qlocale_p.h:71
Qt::LayoutDirection textDirection() const
Returns the text direction of the language.
Definition: qlocale.cpp:2286
bool qt_u_strToLower(const QString &str, QString *out, const QLocale &locale)
quint16 index
Definition: qlocale.h:789
#define QT_MAX_FLOAT
Returns the float represented by the localized string s, or 0.0 if the conversion failed...
Definition: qlocale.cpp:1242
quint16 m_narrow_month_names_idx
Definition: qlocale_p.h:200
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
int type
Definition: qmetatype.cpp:239
bool numberToCLocale(const QString &num, GroupSeparatorMode group_sep_mode, CharBuff *result) const
Definition: qlocale.cpp:2945
quint16 m_language_id
Definition: qlocale_p.h:180
Language language() const
Returns the language of this locale.
Definition: qlocale.cpp:920
static qint64 bytearrayToLongLong(const char *num, int base, bool *ok, bool *overflow=0)
Definition: qlocale.cpp:3186
static mach_timebase_info_data_t info
unsigned char c[8]
Definition: qnumeric_p.h:62
qint64 stringToLongLong(const QString &num, int base, bool *ok, GroupSeparatorMode group_sep_mode) const
Definition: qlocale.cpp:3105
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
quint16 m_country_id
Definition: qlocale_p.h:180
static QList< QLocale > matchingLocales(QLocale::Language language, QLocale::Script script, QLocale::Country country)
Returns a list of valid locale objects that match the given language, script and country.
Definition: qlocale.cpp:1937
QString scriptCode() const
Definition: qlocale.cpp:181
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static const QSystemLocale * systemLocale()
Definition: qlocale.cpp:471
QChar zero() const
Definition: qlocale_p.h:75
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
quint16 countryId() const
Definition: qlocale_p.h:81
QList< Qt::DayOfWeek > weekdays() const
Returns a list of days that are considered weekdays according to the current locale.
Definition: qlocale.cpp:2237
bool isValid() const
Returns true if this date is valid; otherwise returns false.
Definition: qdatetime.cpp:340
quint16 m_standalone_narrow_day_names_size
Definition: qlocale_p.h:203
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
Definition: qvariant.cpp:3102
bool isNull() const
Returns true if the character is the Unicode character 0x0000 (&#39;\0&#39;); otherwise returns false...
Definition: qchar.h:262
Data p
Definition: qlocale.h:803
static QString countryToString(Country country)
Returns a QString containing the name of country.
Definition: qlocale.cpp:1036
QString timeFormat(FormatType format=LongFormat) const
Returns the time format used for the current locale.
Definition: qlocale.cpp:1535
static const unsigned char script_code_list[]
QByteArray & append(char c)
Appends the character ch to this byte array.
static const QLocalePrivate * systemPrivate()
Definition: qlocale.cpp:535
quint16 m_standalone_narrow_day_names_idx
Definition: qlocale_p.h:203
Q_CORE_EXPORT double qstrtod(const char *s00, const char **se, bool *ok)
QDateTime toDateTime(const QString &string, FormatType format=LongFormat) const
Parses the date/time string given in string and returns the time.
Definition: qlocale.cpp:1649
QString createSeparatedList(const QStringList &strl) const
Returns a string that represents a join of a given list of strings with a separator defined by the lo...
Definition: qlocale.cpp:855
QString monthName(int, FormatType format=LongFormat) const
Returns the localized name of month, in the format specified by type.
Definition: qlocale.cpp:2007
uint toUInt(const QString &s, bool *ok=0, int base=0) const
Returns the unsigned int represented by the localized string s, using base base.
Definition: qlocale.cpp:1161
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QChar exponential() const
Returns the exponential character of this locale.
Definition: qlocale.cpp:1843
QChar plus() const
Definition: qlocale_p.h:76
static const QLocalePrivate * defaultPrivate()
Definition: qlocale.cpp:548
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString & prepend(QChar c)
Definition: qstring.h:261
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
Definition: qstring.cpp:5483
int month() const
Returns the number corresponding to the month of this date, using the following convention: ...
Definition: qdatetime.cpp:382
quint16 m_short_day_names_idx
Definition: qlocale_p.h:204
bool parseFormat(const QString &format)
Definition: qdatetime.cpp:4769
FormatType
Definition: qlocale.h:659
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
static QLocale::Language codeToLanguage(const QString &code)
Definition: qlocale.cpp:103
QChar zeroDigit() const
Returns the zero digit character of this locale.
Definition: qlocale.cpp:1804
quint16 m_short_month_names_size
Definition: qlocale_p.h:198
quint16 m_narrow_month_names_size
Definition: qlocale_p.h:200
quint16 m_standalone_short_month_names_size
Definition: qlocale_p.h:195
QSystemLocale()
Constructs a QSystemLocale object.
Definition: qlocale.cpp:445
quint16 languageId() const
Definition: qlocale_p.h:80
static bool qt_is_nan(double d)
Definition: qnumeric_p.h:183
int day() const
Returns the day of the month (1 to 31) of this date.
Definition: qdatetime.cpp:395
bool isValid() const
Returns true if both the date and the time are valid; otherwise returns false.
Definition: qdatetime.cpp:2346
#define QT_END_INCLUDE_NAMESPACE
This macro is equivalent to QT_BEGIN_NAMESPACE.
Definition: qglobal.h:92
quint16 m_standalone_long_day_names_idx
Definition: qlocale_p.h:202
static const QLocalePrivate * dataPointerHelper(quint16 index)
Definition: qlocale.cpp:598
The QDate class provides date functions.
Definition: qdatetime.h:55
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int msec() const
Returns the millisecond part (0 to 999) of the time.
Definition: qdatetime.cpp:1611
static const ushort pm_data[]
bool qt_splitLocaleName(const QString &name, QString &lang, QString &script, QString &cntry)
Definition: qlocale.cpp:302
quint16 m_long_time_format_idx
Definition: qlocale_p.h:194
static const QLocalePrivate * findLocale(const QString &name)
Definition: qlocale.cpp:377
unsigned char quint8
Definition: qglobal.h:934
static QList< Country > countriesForLanguage(Language lang)
Returns the list of countries that have entires for language in Qt&#39;s locale database.
Definition: qlocale.cpp:1974
NumberOption
Definition: qlocale.h:660
QString name() const
Returns the language and country of this locale as a string of the form "language_country", where language is a lowercase, two-letter ISO 639 language code, and country is an uppercase, two- or three-letter ISO 3166 country code.
Definition: qlocale.cpp:963
QString & exponentForm(QChar zero, QChar decimal, QChar exponential, QChar group, QChar plus, QChar minus, QString &digits, int decpt, uint precision, PrecisionMode pm, bool always_show_decpt)
static const ushort currency_symbol_data[]
static double bytearrayToDouble(const char *num, bool *ok, bool *overflow=0)
Definition: qlocale.cpp:3134
quint16 m_short_date_format_size
Definition: qlocale_p.h:191
The QString class provides a Unicode character string.
Definition: qstring.h:83
DayOfWeek
Definition: qnamespace.h:1410
static const char language_name_list[]
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static const unsigned char country_code_list[]
void setNumberOptions(NumberOptions options)
Sets the options related to number conversions for this QLocale instance.
Definition: qlocale.cpp:786
static const uint base
Definition: qurl.cpp:268
void append(const T &t)
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
static QString fromRawData(const QChar *, int size)
Constructs a QString that uses the first size Unicode characters in the array unicode.
Definition: qstring.cpp:7673
quint16 m_weekend_end
Definition: qlocale_p.h:220
QString toString(qlonglong i) const
Returns a localized string representation of i.
Definition: qlocale.cpp:1295
QuotationStyle
Definition: qlocale.h:782
Q_CORE_EXPORT QTextStream & dec(QTextStream &s)
NumberOptions numberOptions() const
Returns the options related to number conversions for this QLocale instance.
Definition: qlocale.cpp:802
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
quint16 m_short_day_names_size
Definition: qlocale_p.h:204
static QLocale system()
Returns a QLocale object initialized to the system locale.
Definition: qlocale.cpp:1917
static const ushort currency_display_name_data[]
quint16 m_standalone_narrow_month_names_size
Definition: qlocale_p.h:197
static int sign(int x)
static QString doubleToString(const QChar zero, const QChar plus, const QChar minus, const QChar exponent, const QChar group, const QChar decimal, double d, int precision, DoubleForm form, int width, unsigned flags)
Definition: qlocale.cpp:2613
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
QLocale & operator=(const QLocale &other)
Assigns other to this QLocale object and returns a reference to this QLocale object.
Definition: qlocale.cpp:771
QStringList uiLanguages() const
Returns an ordered list of locale names for translation purposes in preference order.
Definition: qlocale.cpp:3410
static QString getLocaleData(const ushort *data, int size)
Definition: qlocale.cpp:573
static void getLangAndCountry(const QString &name, QLocale::Language &lang, QLocale::Script &script, QLocale::Country &cntry)
Definition: qlocale.cpp:357
static const ushort am_data[]
#define QT_RETHROW
Definition: qglobal.h:1539
QStringList toStringList() const
Returns the variant as a QStringList if the variant has type() StringList, String ...
Definition: qvariant.cpp:2259
static QString unsLongLongToString(const QChar zero, const QChar group, const QChar plus, quint64 l, int precision, int base, int width, unsigned flags)
Definition: qlocale.cpp:2870
static const unsigned char language_code_list[]
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
int qt_repeatCount(const QString &s, int i)
Definition: qlocale.cpp:421
The QTime class provides clock time functions.
Definition: qdatetime.h:148
QLocale::Language language
static QString longLongToString(const QChar zero, const QChar group, const QChar plus, const QChar minus, qint64 l, int precision, int base, int width, unsigned flags)
Definition: qlocale.cpp:2775
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
quint64 stringToUnsLongLong(const QString &num, int base, bool *ok, GroupSeparatorMode group_sep_mode) const
Definition: qlocale.cpp:3119
qlonglong toULongLong(const QString &s, bool *ok=0, int base=0) const
Returns the unsigned long long int represented by the localized string s, using base base...
Definition: qlocale.cpp:1220
void * v
Definition: qlocale.h:802
quint16 m_standalone_short_day_names_size
Definition: qlocale_p.h:201
static const ushort months_data[]
QString nativeLanguageName() const
Returns a native name of the language for the locale.
Definition: qlocale.cpp:3436
QLocale()
Constructs a QLocale object initialized with the default locale.
Definition: qlocale.cpp:669
static QString getLocaleListData(const ushort *data, int size, int index)
Definition: qlocale.cpp:555
QTime toTime(const QString &string, FormatType=LongFormat) const
Parses the time string given in string and returns the time.
Definition: qlocale.cpp:1606
QChar decimalPoint() const
Returns the decimal point character of this locale.
Definition: qlocale.cpp:1765
void truncate(int pos)
Truncates the string at the given position index.
Definition: qstring.cpp:4603
QString qt_readEscapedFormatString(const QString &format, int *idx)
Definition: qlocale.cpp:387
static bool timeFormatContainsAP(const QString &format)
Definition: qlocale.cpp:1354
static const int ImperialMeasurementSystemsCount
QString languageCode() const
Definition: qlocale.cpp:162
double stringToDouble(const QString &num, bool *ok, GroupSeparatorMode group_sep_mode) const
Definition: qlocale.cpp:3092
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
QString dateTimeFormat(FormatType format=LongFormat) const
Returns the date time format used for the current locale.
Definition: qlocale.cpp:1575
QString quoteString(const QString &str, QuotationStyle style=StandardQuotation) const
Returns str quoted according to the current locale using the given quotation style.
Definition: qlocale.cpp:816
QString toUpper(const QString &str) const
Returns an uppercase copy of str.
Definition: qlocale.cpp:2307
QChar groupSeparator() const
Returns the group separator character of this locale.
Definition: qlocale.cpp:1778
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
QString pmText() const
Returns the localized name of the "PM" suffix for times specified using the conventions of the 12-hou...
Definition: qlocale.cpp:2376
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static QString scriptToString(Script script)
Returns a QString containing the name of script.
Definition: qlocale.cpp:1053
const char * name
quint16 m_standalone_long_day_names_size
Definition: qlocale_p.h:202
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
quint8 m_currency_negative_format_size
Definition: qlocale_p.h:213
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static QString timeZone()
Definition: qlocale.cpp:1371
static const ushort currency_format_data[]
LayoutDirection
Definition: qnamespace.h:1580
quint16 m_standalone_short_day_names_idx
Definition: qlocale_p.h:201
short toShort(const QString &s, bool *ok=0, int base=0) const
Returns the short int represented by the localized string s, using base base.
Definition: qlocale.cpp:1077
QString toCurrencyString(qlonglong, const QString &symbol=QString()) const
Returns a localized string representation of value as a currency.
Definition: qlocale.cpp:3309
unsigned short quint16
Definition: qglobal.h:936
Q_CORE_EXPORT void qWarning(const char *,...)
int second() const
Returns the second part (0 to 59) of the time.
Definition: qdatetime.cpp:1600
static const QLocalePrivate * findLocale(QLocale::Language language, QLocale::Script script, QLocale::Country country)
Definition: qlocale.cpp:241
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
QDataStream & operator<<(QDataStream &ds, const QLocale &l)
Definition: qlocale.cpp:580
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
QChar percent() const
Definition: qlocale_p.h:74
static QChar fromLatin1(char c)
Converts the Latin-1 character c to its equivalent QChar.
Definition: qchar.h:378
static quint64 bytearrayToUnsLongLong(const char *num, int base, bool *ok)
Definition: qlocale.cpp:3228
static const quint16 country_name_index[]
QChar toUpper() const
Returns the uppercase equivalent if the character is lowercase or titlecase; otherwise returns the ch...
Definition: qchar.cpp:1287
quint16 m_long_time_format_size
Definition: qlocale_p.h:194
QChar percent() const
Returns the percent character of this locale.
Definition: qlocale.cpp:1791
bool removeGroupSeparators(QLocalePrivate::CharBuff *num)
QString nativeCountryName() const
Returns a native name of the country for the locale.
Definition: qlocale.cpp:3459
int minute() const
Returns the minute part (0 to 59) of the time.
Definition: qdatetime.cpp:1589
QDate toDate(const QString &string, FormatType=LongFormat) const
Parses the date string given in string and returns the date.
Definition: qlocale.cpp:1627
static uint default_number_options
Definition: qlocale.cpp:431
QString toLower(const QString &str) const
Returns a lowercase copy of str.
Definition: qlocale.cpp:2328
QChar minus() const
Definition: qlocale_p.h:77
quint16 m_standalone_narrow_month_names_idx
Definition: qlocale_p.h:197
static QSystemLocale * _systemLocale
Definition: qlocale.cpp:83
Language
Definition: qlocale.h:148
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
quint16 m_currency_symbol_idx
Definition: qlocale_p.h:210
#define QT_CATCH(A)
Definition: qglobal.h:1537
bool qt_initIcu(const QString &localeString)
Definition: qlocale_icu.cpp:76
quint16 m_narrow_day_names_size
Definition: qlocale_p.h:206
static const char script_name_list[]
quint16 m_standalone_short_month_names_idx
Definition: qlocale_p.h:195
static void setDefault(const QLocale &locale)
Sets the global default locale to locale.
Definition: qlocale.cpp:905
QChar negativeSign() const
Returns the negative sign character of this locale.
Definition: qlocale.cpp:1817
quint8 m_currency_negative_format_idx
Definition: qlocale_p.h:213
CurrencySymbolFormat
Specifies the format of the currency symbol.
Definition: qlocale.h:666
static const ushort standalone_months_data[]
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
quint8 m_currency_format_idx
Definition: qlocale_p.h:212
float toFloat(const QString &s, bool *ok=0) const
Definition: qlocale.cpp:1244
static const CountryLanguage ImperialMeasurementSystems[]
quint16 m_long_month_names_idx
Definition: qlocale_p.h:199
quint16 m_currency_symbol_size
Definition: qlocale_p.h:210
QString amText() const
Returns the localized name of the "AM" suffix for times specified using the conventions of the 12-hou...
Definition: qlocale.cpp:2353
qlonglong qstrtoll(const char *nptr, const char **endptr, register int base, bool *ok)
QDataStream & operator>>(QDataStream &ds, QLocale &l)
Definition: qlocale.cpp:586
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
QChar exponential() const
Definition: qlocale_p.h:78
PrecisionMode
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
quint16 m_short_time_format_idx
Definition: qlocale_p.h:193
static const char country_name_list[]
static quint16 localePrivateIndex(const QLocalePrivate *p)
Definition: qlocale.cpp:611
const QLocalePrivate * d() const
Definition: qlocale.cpp:761
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
static QLocale c()
Returns a QLocale object initialized to the "C" locale.
Definition: qlocale.h:773
static char qToLower(char c)
Definition: qlocale.cpp:1853
quint16 m_narrow_day_names_idx
Definition: qlocale_p.h:206
QString & append(QChar c)
Definition: qstring.cpp:1777
static const ushort list_pattern_part_data[]
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
qlonglong toLongLong(const QString &s, bool *ok=0, int base=0) const
Returns the long long int represented by the localized string s, using base base. ...
Definition: qlocale.cpp:1190
double toDouble(const QString &s, bool *ok=0) const
Returns the double represented by the localized string s, or 0.0 if the conversion failed...
Definition: qlocale.cpp:1279
static QLocale::Script codeToScript(const QString &code)
Definition: qlocale.cpp:124
static const ushort endonyms_data[]
unsigned short ushort
Definition: qglobal.h:995
quint16 m_long_date_format_idx
Definition: qlocale_p.h:192
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
quint16 m_long_day_names_idx
Definition: qlocale_p.h:205
static bool parse_locale_tag(const QString &input, int &i, QString *result, const QString &separators)
Definition: qlocale.cpp:282
static QLocalePrivate * system_lp
Definition: qlocale.cpp:85
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
uint toUInt(bool *ok=0) const
Returns the variant as an unsigned int if the variant has type() UInt , Bool , ByteArray ...
Definition: qvariant.cpp:2644
unsigned int quint32
Definition: qglobal.h:938
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QString standaloneMonthName(int, FormatType format=LongFormat) const
Returns the localized name of month that is used as a standalone text, in the format specified by typ...
Definition: qlocale.cpp:2056
static const quint16 script_name_index[]
QString dateTimeToString(const QString &format, const QDate *date, const QTime *time, const QLocale *q) const
Definition: qlocale.cpp:2389
quint16 m_script_id
Definition: qlocale_p.h:180
static const int zero
QFactoryLoader * l
virtual QVariant query(QueryType type, QVariant in) const
Script script() const
Returns the script of this locale.
Definition: qlocale.cpp:935
MeasurementSystem
Definition: qlocale.h:657
static double qt_snan()
Definition: qnumeric_p.h:80
qulonglong qstrtoull(const char *nptr, const char **endptr, register int base, bool *ok)
friend class QString
Definition: qlocale.h:138
char toLatin1() const
Returns the Latin-1 character equivalent to the QChar, or 0.
Definition: qchar.h:376
static double qt_inf()
Definition: qnumeric_p.h:65
quint16 index
virtual QLocale fallbackLocale() const
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
Definition: qglobal.h:91
QString qlltoa(qlonglong l, int base, const QChar zero)
static QLocale::Country codeToCountry(const QString &code)
Definition: qlocale.cpp:144
bool qt_u_strToUpper(const QString &str, QString *out, const QLocale &locale)
quint8 m_currency_format_size
Definition: qlocale_p.h:212
static const QLocalePrivate * default_lp
Definition: qlocale.cpp:430
static bool qt_is_inf(double d)
Definition: qnumeric_p.h:169
static const ushort days_data[]
Q_CORE_EXPORT QTextStream & scientific(QTextStream &s)
bool validateChars(const QString &str, NumberMode numMode, QByteArray *buff, int decDigits=-1) const
Definition: qlocale.cpp:2999
int year() const
Returns the year of this date.
Definition: qdatetime.cpp:353
static QSystemLocale * QSystemLocale_globalSystemLocale()
QString dayName(int, FormatType format=LongFormat) const
Returns the localized name of the day (where 1 represents Monday, 2 represents Tuesday and so on)...
Definition: qlocale.cpp:2106
static const QLocalePrivate locale_data[]
QString currencySymbol(CurrencySymbolFormat=CurrencySymbol) const
Returns a currency symbol according to the format.
Definition: qlocale.cpp:3267
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
Qt::DayOfWeek firstDayOfWeek() const
Returns the first day of the week according to the current locale.
Definition: qlocale.cpp:2206
static const ushort time_format_data[]
quint16 m_long_day_names_size
Definition: qlocale_p.h:205
quint64 qulonglong
Definition: qglobal.h:952
QString qulltoa(qulonglong l, int base, const QChar _zero)
Country country() const
Returns the country of this locale.
Definition: qlocale.cpp:945
int toInt(const QString &s, bool *ok=0, int base=0) const
Returns the int represented by the localized string s, using base base.
Definition: qlocale.cpp:1133
quint16 m_currency_digits
Definition: qlocale_p.h:216
ushort toUShort(const QString &s, bool *ok=0, int base=0) const
Returns the unsigned short int represented by the localized string s, using base base.
Definition: qlocale.cpp:1105
quint16 m_short_date_format_idx
Definition: qlocale_p.h:191
T value() const
Returns the stored value converted to the template type T.
Definition: qvariant.h:332
QString dateFormat(FormatType format=LongFormat) const
Returns the date format used for the current locale.
Definition: qlocale.cpp:1495
quint16 m_currency_display_name_idx
Definition: qlocale_p.h:211
void reserve(int size)
Attempts to allocate memory for at least size bytes.
Definition: qbytearray.h:449
QLocale defaultLocale
Definition: qdatetime_p.h:267
Q_CORE_EXPORT char * qdtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve, char **resultp)
bool fromString(const QString &text, QDate *date, QTime *time) const
Definition: qdatetime.cpp:6084
static const KeyPair *const end
QLocale::Country country
static QString languageToString(Language language)
Returns a QString containing the name of language.
Definition: qlocale.cpp:1023
QLocale::MeasurementSystem measurementSystem() const
Definition: qlocale.cpp:2218
qint64 qlonglong
Definition: qglobal.h:951
quint16 numberOptions
Definition: qlocale.h:790
bool isZero(double d)
static const quint16 language_name_index[]
QString & insert(int i, QChar c)
Definition: qstring.cpp:1671
quint16 m_first_day_of_week
Definition: qlocale_p.h:218
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
char m_currency_iso_code[3]
Definition: qlocale_p.h:209
quint16 m_long_month_names_size
Definition: qlocale_p.h:199
quint16 m_currency_display_name_size
Definition: qlocale_p.h:211
QChar toLower() const
Returns the lowercase equivalent if the character is uppercase or titlecase; otherwise returns the ch...
Definition: qchar.cpp:1239
MeasurementSystem measurementSystem() const
Returns the measurement system for the locale.
Definition: qlocale.cpp:2265
#define QT_TRY
Definition: qglobal.h:1536
#define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS)
Declares a global static variable with the specified type and name.
Definition: qglobal.h:1982
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
#define INT_MAX
QString & decimalForm(QChar zero, QChar decimal, QChar group, QString &digits, int decpt, uint precision, PrecisionMode pm, bool always_show_decpt, bool thousands_group)
quint16 m_long_date_format_size
Definition: qlocale_p.h:192
quint16 m_short_time_format_size
Definition: qlocale_p.h:193
static const ushort date_format_data[]
static const quint16 locale_index[]
void clear()
Clears the contents of the byte array and makes it empty.
static const int locale_data_size
Definition: qlocale.cpp:596
quint16 m_weekend_start
Definition: qlocale_p.h:219
static bool qIsUpper(char c)
Definition: qlocale.cpp:1848
void reserve(int size)
Reserve space for alloc elements.
Definition: qlist.h:496
QString bcp47Name() const
Returns the dash-separated language, script and country (and possibly other BCP47 fields) of this loc...
Definition: qlocale.cpp:1012
bool isValid() const
Returns true if the time is valid; otherwise returns false.
Definition: qdatetime.cpp:1566
int hour() const
Returns the hour part (0 to 23) of the time.
Definition: qdatetime.cpp:1578
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QString bcp47Name() const
Definition: qlocale.cpp:206
QString standaloneDayName(int, FormatType format=LongFormat) const
Returns the localized name of the day (where 1 represents Monday, 2 represents Tuesday and so on) tha...
Definition: qlocale.cpp:2158
quint16 m_short_month_names_idx
Definition: qlocale_p.h:198
QString countryCode() const
Definition: qlocale.cpp:189