equal
deleted
inserted
replaced
127 { |
127 { |
128 return (c >= 0 && c <=127); |
128 return (c >= 0 && c <=127); |
129 } |
129 } |
130 #endif |
130 #endif |
131 |
131 |
|
132 #if defined(Q_OS_SYMBIAN) |
|
133 void qt_symbianUpdateSystemPrivate(); |
|
134 void qt_symbianInitSystemLocale(); |
|
135 #endif |
|
136 |
132 /****************************************************************************** |
137 /****************************************************************************** |
133 ** Helpers for accessing Qt locale database |
138 ** Helpers for accessing Qt locale database |
134 */ |
139 */ |
135 |
140 |
136 QT_BEGIN_INCLUDE_NAMESPACE |
141 QT_BEGIN_INCLUDE_NAMESPACE |
469 if (sys_fmt.at(i).unicode() == QLatin1Char('\'')) { |
474 if (sys_fmt.at(i).unicode() == QLatin1Char('\'')) { |
470 QString text = readEscapedFormatString(sys_fmt, &i); |
475 QString text = readEscapedFormatString(sys_fmt, &i); |
471 if (text == QLatin1String("'")) |
476 if (text == QLatin1String("'")) |
472 result += QLatin1String("''"); |
477 result += QLatin1String("''"); |
473 else |
478 else |
474 result += QLatin1Char('\'') + text + QLatin1Char('\''); |
479 result += QString(QLatin1Char('\'') + text + QLatin1Char('\'')); |
475 continue; |
480 continue; |
476 } |
481 } |
477 |
482 |
478 QChar c = sys_fmt.at(i); |
483 QChar c = sys_fmt.at(i); |
479 int repeat = repeatCount(sys_fmt, i); |
484 int repeat = repeatCount(sys_fmt, i); |
685 format_string = true; |
690 format_string = true; |
686 break; |
691 break; |
687 |
692 |
688 case DateTimeFormatLong: |
693 case DateTimeFormatLong: |
689 case DateTimeFormatShort: |
694 case DateTimeFormatShort: |
690 return query(type == DateTimeFormatLong ? DateFormatLong : DateFormatShort).toString() |
695 return QString(query(type == DateTimeFormatLong ? DateFormatLong : DateFormatShort).toString() |
691 + QLatin1Char(' ') + query(type == DateTimeFormatLong ? TimeFormatLong : TimeFormatShort).toString(); |
696 + QLatin1Char(' ') + query(type == DateTimeFormatLong ? TimeFormatLong : TimeFormatShort).toString()); |
692 case DayNameLong: |
697 case DayNameLong: |
693 case DayNameShort: |
698 case DayNameShort: |
694 return winDayName(in.toInt(), (type == DayNameShort)); |
699 return winDayName(in.toInt(), (type == DayNameShort)); |
695 case MonthNameLong: |
700 case MonthNameLong: |
696 case MonthNameShort: |
701 case MonthNameShort: |
702 case TimeToStringLong: |
707 case TimeToStringLong: |
703 return winTimeToString(in.toTime()); |
708 return winTimeToString(in.toTime()); |
704 case DateTimeToStringShort: |
709 case DateTimeToStringShort: |
705 case DateTimeToStringLong: { |
710 case DateTimeToStringLong: { |
706 const QDateTime dt = in.toDateTime(); |
711 const QDateTime dt = in.toDateTime(); |
707 return winDateToString(dt.date(), type == DateTimeToStringShort ? DATE_SHORTDATE : DATE_LONGDATE) |
712 return QString(winDateToString(dt.date(), type == DateTimeToStringShort ? DATE_SHORTDATE : DATE_LONGDATE) |
708 + QLatin1Char(' ') + winTimeToString(dt.time()); } |
713 + QLatin1Char(' ') + winTimeToString(dt.time())); } |
709 |
714 |
710 case ZeroDigit: |
715 case ZeroDigit: |
711 locale_info = LOCALE_SNATIVEDIGITS; |
716 locale_info = LOCALE_SNATIVEDIGITS; |
712 break; |
717 break; |
713 |
718 |
747 struct WindowsToISOListElt { |
752 struct WindowsToISOListElt { |
748 ushort windows_code; |
753 ushort windows_code; |
749 char iso_name[6]; |
754 char iso_name[6]; |
750 }; |
755 }; |
751 |
756 |
752 /* NOTE: This array should be sorted by the first column! */ |
|
753 static const WindowsToISOListElt windows_to_iso_list[] = { |
757 static const WindowsToISOListElt windows_to_iso_list[] = { |
754 { 0x0401, "ar_SA" }, |
758 { 0x0401, "ar_SA" }, |
755 { 0x0402, "bg\0 " }, |
759 { 0x0402, "bg\0 " }, |
756 { 0x0403, "ca\0 " }, |
760 { 0x0403, "ca\0 " }, |
757 { 0x0404, "zh_TW" }, |
761 { 0x0404, "zh_TW" }, |
1412 |
1416 |
1413 static const QSystemLocale *systemLocale() |
1417 static const QSystemLocale *systemLocale() |
1414 { |
1418 { |
1415 if (_systemLocale) |
1419 if (_systemLocale) |
1416 return _systemLocale; |
1420 return _systemLocale; |
|
1421 #if defined(Q_OS_SYMBIAN) |
|
1422 qt_symbianInitSystemLocale(); |
|
1423 #endif |
1417 return QSystemLocale_globalSystemLocale(); |
1424 return QSystemLocale_globalSystemLocale(); |
1418 } |
1425 } |
1419 |
1426 |
1420 void QLocalePrivate::updateSystemPrivate() |
1427 void QLocalePrivate::updateSystemPrivate() |
1421 { |
1428 { |
1422 const QSystemLocale *sys_locale = systemLocale(); |
1429 const QSystemLocale *sys_locale = systemLocale(); |
1423 if (!system_lp) |
1430 if (!system_lp) |
1424 system_lp = globalLocalePrivate(); |
1431 system_lp = globalLocalePrivate(); |
1425 *system_lp = *sys_locale->fallbackLocale().d(); |
1432 *system_lp = *sys_locale->fallbackLocale().d(); |
|
1433 |
|
1434 #if defined(Q_OS_SYMBIAN) |
|
1435 qt_symbianUpdateSystemPrivate(); |
|
1436 #endif |
1426 |
1437 |
1427 QVariant res = sys_locale->query(QSystemLocale::LanguageId, QVariant()); |
1438 QVariant res = sys_locale->query(QSystemLocale::LanguageId, QVariant()); |
1428 if (!res.isNull()) |
1439 if (!res.isNull()) |
1429 system_lp->m_language_id = res.toInt(); |
1440 system_lp->m_language_id = res.toInt(); |
1430 res = sys_locale->query(QSystemLocale::CountryId, QVariant()); |
1441 res = sys_locale->query(QSystemLocale::CountryId, QVariant()); |
1575 \snippet doc/src/snippets/code/src_corelib_tools_qlocale.cpp 2 |
1586 \snippet doc/src/snippets/code/src_corelib_tools_qlocale.cpp 2 |
1576 |
1587 |
1577 This constructor converts the locale name to a language/country |
1588 This constructor converts the locale name to a language/country |
1578 pair; it does not use the system locale database. |
1589 pair; it does not use the system locale database. |
1579 |
1590 |
1580 QLocale's data is based on Common Locale Data Repository v1.6.1. |
1591 QLocale's data is based on Common Locale Data Repository v1.8.1. |
1581 |
1592 |
1582 The double-to-string and string-to-double conversion functions are |
1593 The double-to-string and string-to-double conversion functions are |
1583 covered by the following licenses: |
1594 covered by the following licenses: |
1584 |
1595 |
1585 \legalese |
1596 \legalese |
1776 \value Ewe |
1787 \value Ewe |
1777 \value Walamo |
1788 \value Walamo |
1778 \value Hawaiian |
1789 \value Hawaiian |
1779 \value Tyap |
1790 \value Tyap |
1780 \value Chewa |
1791 \value Chewa |
|
1792 \value Filipino |
|
1793 \value SwissGerman |
|
1794 \value SichuanYi |
|
1795 \value Kpelle |
|
1796 \value LowGerman |
|
1797 \value SouthNdebele |
|
1798 \value NorthernSotho |
|
1799 \value NorthernSami |
|
1800 \value Taroko |
|
1801 \value Gusii |
|
1802 \value Taita |
|
1803 \value Fulah |
|
1804 \value Kikuyu |
|
1805 \value Samburu |
|
1806 \value Sena |
|
1807 \value NorthNdebele |
|
1808 \value Rombo |
|
1809 \value Tachelhit |
|
1810 \value Kabyle |
|
1811 \value Nyankole |
|
1812 \value Bena |
|
1813 \value Vunjo |
|
1814 \value Bambara |
|
1815 \value Embu |
|
1816 \value Cherokee |
|
1817 \value Morisyen |
|
1818 \value Makonde |
|
1819 \value Langi |
|
1820 \value Ganda |
|
1821 \value Bemba |
|
1822 \value Kabuverdianu |
|
1823 \value Meru |
|
1824 \value Kalenjin |
|
1825 \value Nama |
|
1826 \value Machame |
|
1827 \value Colognian |
|
1828 \value Masai |
|
1829 \value Soga |
|
1830 \value Luyia |
|
1831 \value Asu |
|
1832 \value Teso |
|
1833 \value Saho |
|
1834 \value KoyraChiini |
|
1835 \value Rwa |
|
1836 \value Luo |
|
1837 \value Chiga |
|
1838 \value CentralMoroccoTamazight |
|
1839 \value KoyraboroSenni |
|
1840 \value Shambala |
1781 \omitvalue LastLanguage |
1841 \omitvalue LastLanguage |
1782 |
1842 |
1783 \sa language() |
1843 \sa language() |
1784 */ |
1844 */ |
1785 |
1845 |
2028 \value WesternSahara |
2088 \value WesternSahara |
2029 \value Yemen |
2089 \value Yemen |
2030 \value Yugoslavia |
2090 \value Yugoslavia |
2031 \value Zambia |
2091 \value Zambia |
2032 \value Zimbabwe |
2092 \value Zimbabwe |
|
2093 \value SerbiaAndMontenegro |
|
2094 \value Montenegro |
|
2095 \value Serbia |
|
2096 \value SaintBarthelemy |
|
2097 \value SaintMartin |
2033 \omitvalue LastCountry |
2098 \omitvalue LastCountry |
2034 |
2099 |
2035 \sa country() |
2100 \sa country() |
2036 */ |
2101 */ |
2037 |
2102 |
2922 */ |
2987 */ |
2923 |
2988 |
2924 #ifndef QT_NO_DATESTRING |
2989 #ifndef QT_NO_DATESTRING |
2925 QDateTime QLocale::toDateTime(const QString &string, FormatType format) const |
2990 QDateTime QLocale::toDateTime(const QString &string, FormatType format) const |
2926 { |
2991 { |
2927 return toDateTime(string, dateFormat(format)); |
2992 return toDateTime(string, dateTimeFormat(format)); |
2928 } |
2993 } |
2929 #endif |
2994 #endif |
2930 |
2995 |
2931 /*! |
2996 /*! |
2932 \since 4.4 |
2997 \since 4.4 |
3152 Returns a QLocale object initialized to the system locale. |
3217 Returns a QLocale object initialized to the system locale. |
3153 |
3218 |
3154 On Windows and Mac, this locale will use the decimal/grouping characters and date/time |
3219 On Windows and Mac, this locale will use the decimal/grouping characters and date/time |
3155 formats specified in the system configuration panel. |
3220 formats specified in the system configuration panel. |
3156 |
3221 |
3157 \sa QTextCodec::locale() c() |
3222 \sa c() |
3158 */ |
3223 */ |
3159 |
3224 |
3160 QLocale QLocale::system() |
3225 QLocale QLocale::system() |
3161 { |
3226 { |
3162 QLocale result(C); |
3227 QLocale result(C); |
4298 buff->clear(); |
4363 buff->clear(); |
4299 buff->reserve(str.length()); |
4364 buff->reserve(str.length()); |
4300 |
4365 |
4301 const bool scientific = numMode == DoubleScientificMode; |
4366 const bool scientific = numMode == DoubleScientificMode; |
4302 bool lastWasE = false; |
4367 bool lastWasE = false; |
|
4368 bool lastWasDigit = false; |
4303 int eCnt = 0; |
4369 int eCnt = 0; |
4304 int decPointCnt = 0; |
4370 int decPointCnt = 0; |
4305 bool dec = false; |
4371 bool dec = false; |
4306 int decDigitCnt = 0; |
4372 int decDigitCnt = 0; |
4307 |
4373 |
4312 if (numMode != IntegerMode) { |
4378 if (numMode != IntegerMode) { |
4313 // If a double has too many digits after decpt, it shall be Invalid. |
4379 // If a double has too many digits after decpt, it shall be Invalid. |
4314 if (dec && decDigits != -1 && decDigits < ++decDigitCnt) |
4380 if (dec && decDigits != -1 && decDigits < ++decDigitCnt) |
4315 return false; |
4381 return false; |
4316 } |
4382 } |
|
4383 lastWasDigit = true; |
4317 } else { |
4384 } else { |
4318 switch (c) { |
4385 switch (c) { |
4319 case '.': |
4386 case '.': |
4320 if (numMode == IntegerMode) { |
4387 if (numMode == IntegerMode) { |
4321 // If an integer has a decimal point, it shall be Invalid. |
4388 // If an integer has a decimal point, it shall be Invalid. |
4349 return false; |
4416 return false; |
4350 } |
4417 } |
4351 break; |
4418 break; |
4352 |
4419 |
4353 case ',': |
4420 case ',': |
4354 return false; |
4421 //it can only be placed after a digit which is before the decimal point |
|
4422 if (!lastWasDigit || decPointCnt > 0) |
|
4423 return false; |
|
4424 break; |
4355 |
4425 |
4356 case 'e': |
4426 case 'e': |
4357 if (scientific) { |
4427 if (scientific) { |
4358 // If a scientific has more than one 'e', it shall be Invalid. |
4428 // If a scientific has more than one 'e', it shall be Invalid. |
4359 if (++eCnt > 1) |
4429 if (++eCnt > 1) |
4367 |
4437 |
4368 default: |
4438 default: |
4369 // If it's not a valid digit, it shall be Invalid. |
4439 // If it's not a valid digit, it shall be Invalid. |
4370 return false; |
4440 return false; |
4371 } |
4441 } |
|
4442 lastWasDigit = false; |
4372 } |
4443 } |
4373 |
4444 |
4374 lastWasE = c == 'e'; |
4445 lastWasE = c == 'e'; |
4375 buff->append(c); |
4446 if (c != ',') |
|
4447 buff->append(c); |
4376 } |
4448 } |
4377 |
4449 |
4378 return true; |
4450 return true; |
4379 } |
4451 } |
4380 |
4452 |