1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtCore module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include <QtCore/qvariant.h>
46 #include <QtCore/qstring.h>
47 #include <QtCore/qobjectdefs.h>
60 class QTextStreamPrivate;
64 struct QLocalePrivate;
65 class Q_CORE_EXPORT QLocale
71 friend class QByteArray;
72 friend class QIntValidator;
73 friend class QDoubleValidatorPrivate;
74 friend class QTextStream;
75 friend class QTextStreamPrivate;
78 // GENERATED PART STARTS HERE
79 // see qlocale_data_p.h for more info on generated data
293 CentralMoroccoTamazight = 212,
294 KoyraboroSenni = 213,
296 NorwegianBokmal = Norwegian,
297 NorwegianNynorsk = Nynorsk,
298 LastLanguage = Shambala
307 SimplifiedHanScript = 5,
308 TraditionalHanScript = 6,
312 SimplifiedChineseScript = SimplifiedHanScript,
313 TraditionalChineseScript = TraditionalHanScript,
314 LastScript = TifinaghScript
326 AntiguaAndBarbuda = 9,
344 BosniaAndHerzegowina = 27,
348 BritishIndianOceanTerritory = 31,
349 BruneiDarussalam = 32,
358 CentralAfricanRepublic = 41,
362 ChristmasIsland = 45,
366 DemocraticRepublicOfCongo = 49,
367 PeoplesRepublicOfCongo = 50,
378 DominicanRepublic = 61,
383 EquatorialGuinea = 66,
387 FalklandIslands = 70,
392 MetropolitanFrance = 75,
394 FrenchPolynesia = 77,
395 FrenchSouthernTerritories = 78,
412 HeardAndMcDonaldIslands = 95,
430 DemocraticRepublicOfKorea = 113,
431 RepublicOfKorea = 114,
439 LibyanArabJamahiriya = 122,
451 MarshallIslands = 134,
469 NetherlandsAntilles = 152,
477 NorthernMarianaIslands = 160,
482 PalestinianTerritory = 165,
484 PapuaNewGuinea = 167,
495 RussianFederation = 178,
497 SaintKittsAndNevis = 180,
499 StVincentAndTheGrenadines = 182,
502 SaoTomeAndPrincipe = 185,
510 SolomonIslands = 193,
513 SouthGeorgiaAndTheSouthSandwichIslands = 196,
517 StPierreAndMiquelon = 200,
520 SvalbardAndJanMayenIslands = 203,
524 SyrianArabRepublic = 207,
532 TrinidadAndTobago = 215,
536 TurksAndCaicosIslands = 219,
540 UnitedArabEmirates = 223,
543 UnitedStatesMinorOutlyingIslands = 226,
547 VaticanCityState = 230,
550 BritishVirginIslands = 233,
551 USVirginIslands = 234,
552 WallisAndFutunaIslands = 235,
558 SerbiaAndMontenegro = 241,
561 SaintBarthelemy = 244,
563 LatinAmericaAndTheCaribbean = 246,
564 LastCountry = LatinAmericaAndTheCaribbean
566 // GENERATED PART ENDS HERE
568 enum MeasurementSystem {
572 ImperialSystem = ImperialUSSystem // Qt 4 compatibility
575 enum FormatType { LongFormat, ShortFormat, NarrowFormat };
577 OmitGroupSeparator = 0x01,
578 RejectGroupSeparator = 0x02
580 Q_DECLARE_FLAGS(NumberOptions, NumberOption)
582 enum CurrencySymbolFormat {
589 QLocale(const QString &name);
590 QLocale(Language language, Country country = AnyCountry);
591 QLocale(Language language, Script script, Country country);
592 QLocale(const QLocale &other);
594 QLocale &operator=(const QLocale &other);
596 Language language() const;
597 Script script() const;
598 Country country() const;
599 QString name() const;
601 QString bcp47Name() const;
602 QString nativeLanguageName() const;
603 QString nativeCountryName() const;
605 short toShort(const QString &s, bool *ok = 0) const;
606 ushort toUShort(const QString &s, bool *ok = 0) const;
607 int toInt(const QString &s, bool *ok = 0) const;
608 uint toUInt(const QString &s, bool *ok = 0) const;
609 qlonglong toLongLong(const QString &s, bool *ok = 0) const;
610 qulonglong toULongLong(const QString &s, bool *ok = 0) const;
611 float toFloat(const QString &s, bool *ok = 0) const;
612 double toDouble(const QString &s, bool *ok = 0) const;
614 QString toString(qlonglong i) const;
615 QString toString(qulonglong i) const;
616 inline QString toString(short i) const;
617 inline QString toString(ushort i) const;
618 inline QString toString(int i) const;
619 inline QString toString(uint i) const;
620 QString toString(double i, char f = 'g', int prec = 6) const;
621 inline QString toString(float i, char f = 'g', int prec = 6) const;
622 QString toString(const QDate &date, const QString &formatStr) const;
623 QString toString(const QDate &date, FormatType format = LongFormat) const;
624 QString toString(const QTime &time, const QString &formatStr) const;
625 QString toString(const QTime &time, FormatType format = LongFormat) const;
626 QString toString(const QDateTime &dateTime, FormatType format = LongFormat) const;
627 QString toString(const QDateTime &dateTime, const QString &format) const;
629 QString dateFormat(FormatType format = LongFormat) const;
630 QString timeFormat(FormatType format = LongFormat) const;
631 QString dateTimeFormat(FormatType format = LongFormat) const;
632 #ifndef QT_NO_DATESTRING
633 QDate toDate(const QString &string, FormatType = LongFormat) const;
634 QTime toTime(const QString &string, FormatType = LongFormat) const;
635 QDateTime toDateTime(const QString &string, FormatType format = LongFormat) const;
636 QDate toDate(const QString &string, const QString &format) const;
637 QTime toTime(const QString &string, const QString &format) const;
638 QDateTime toDateTime(const QString &string, const QString &format) const;
641 // ### Qt 5: We need to return QString from these function since
642 // unicode data contains several characters for these fields.
643 QChar decimalPoint() const;
644 QChar groupSeparator() const;
645 QChar percent() const;
646 QChar zeroDigit() const;
647 QChar negativeSign() const;
648 QChar positiveSign() const;
649 QChar exponential() const;
651 QString monthName(int, FormatType format = LongFormat) const;
652 QString standaloneMonthName(int, FormatType format = LongFormat) const;
653 QString dayName(int, FormatType format = LongFormat) const;
654 QString standaloneDayName(int, FormatType format = LongFormat) const;
656 Qt::DayOfWeek firstDayOfWeek() const;
657 QList<Qt::DayOfWeek> weekdays() const;
659 QString amText() const;
660 QString pmText() const;
662 MeasurementSystem measurementSystem() const;
664 Qt::LayoutDirection textDirection() const;
666 QString toUpper(const QString &str) const;
667 QString toLower(const QString &str) const;
669 QString currencySymbol(CurrencySymbolFormat = CurrencySymbol) const;
670 QString toCurrencyString(qlonglong, const QString &symbol = QString()) const;
671 QString toCurrencyString(qulonglong, const QString &symbol = QString()) const;
672 inline QString toCurrencyString(short, const QString &symbol = QString()) const;
673 inline QString toCurrencyString(ushort, const QString &symbol = QString()) const;
674 inline QString toCurrencyString(int, const QString &symbol = QString()) const;
675 inline QString toCurrencyString(uint, const QString &symbol = QString()) const;
676 QString toCurrencyString(double, const QString &symbol = QString()) const;
677 inline QString toCurrencyString(float, const QString &symbol = QString()) const;
679 QStringList uiLanguages() const;
681 bool operator==(const QLocale &other) const;
682 bool operator!=(const QLocale &other) const;
684 static QString languageToString(Language language);
685 static QString countryToString(Country country);
686 static QString scriptToString(Script script);
687 static void setDefault(const QLocale &locale);
689 static QLocale c() { return QLocale(C); }
690 static QLocale system();
692 static QList<QLocale> matchingLocales(QLocale::Language language, QLocale::Script script, QLocale::Country country);
693 static QList<Country> countriesForLanguage(Language lang);
695 void setNumberOptions(NumberOptions options);
696 NumberOptions numberOptions() const;
698 enum QuotationStyle { StandardQuotation, AlternateQuotation };
699 QString quoteString(const QString &str, QuotationStyle style = StandardQuotation) const;
700 QString quoteString(const QStringRef &str, QuotationStyle style = StandardQuotation) const;
702 QString createSeparatedList(const QStringList &strl) const;
703 //private: // this should be private, but can't be
706 quint16 numberOptions;
709 friend struct QLocalePrivate;
710 // ### We now use this field to pack an index into locale_data and NumberOptions.
711 // ### Qt 5: change to a QLocaleData *d; uint numberOptions.
716 const QLocalePrivate *d() const;
718 Q_DECLARE_TYPEINFO(QLocale, Q_MOVABLE_TYPE);
719 Q_DECLARE_OPERATORS_FOR_FLAGS(QLocale::NumberOptions)
721 inline QString QLocale::toString(short i) const
722 { return toString(qlonglong(i)); }
723 inline QString QLocale::toString(ushort i) const
724 { return toString(qulonglong(i)); }
725 inline QString QLocale::toString(int i) const
726 { return toString(qlonglong(i)); }
727 inline QString QLocale::toString(uint i) const
728 { return toString(qulonglong(i)); }
729 inline QString QLocale::toString(float i, char f, int prec) const
730 { return toString(double(i), f, prec); }
732 inline QString QLocale::toCurrencyString(short i, const QString &symbol) const
733 { return toCurrencyString(qlonglong(i), symbol); }
734 inline QString QLocale::toCurrencyString(ushort i, const QString &symbol) const
735 { return toCurrencyString(qulonglong(i), symbol); }
736 inline QString QLocale::toCurrencyString(int i, const QString &symbol) const
737 { return toCurrencyString(qlonglong(i), symbol); }
738 inline QString QLocale::toCurrencyString(uint i, const QString &symbol) const
739 { return toCurrencyString(qulonglong(i), symbol); }
740 inline QString QLocale::toCurrencyString(float i, const QString &symbol) const
741 { return toCurrencyString(double(i), symbol); }
743 #ifndef QT_NO_DATASTREAM
744 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QLocale &);
745 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QLocale &);
748 #ifndef QT_NO_DEBUG_STREAM
749 Q_CORE_EXPORT QDebug operator<<(QDebug, const QLocale &);