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 ****************************************************************************/
49 // This file is not part of the Qt API. It exists for the convenience
50 // of internal files. This header file may change from version to version
51 // without notice, or even be removed.
56 #include "QtCore/qstring.h"
57 #include "QtCore/qvarlengtharray.h"
58 #include "QtCore/qvariant.h"
64 #ifndef QT_NO_SYSTEMLOCALE
69 virtual ~QSystemLocale();
71 struct CurrencyToStringArgument
73 CurrencyToStringArgument() { }
74 CurrencyToStringArgument(const QVariant &v, const QString &s)
75 : value(v), symbol(s) { }
83 DecimalPoint, // QString
84 GroupSeparator, // QString
86 NegativeSign, // QString
87 DateFormatLong, // QString
88 DateFormatShort, // QString
89 TimeFormatLong, // QString
90 TimeFormatShort, // QString
91 DayNameLong, // QString, in: int
92 DayNameShort, // QString, in: int
93 MonthNameLong, // QString, in: int
94 MonthNameShort, // QString, in: int
95 DateToStringLong, // QString, in: QDate
96 DateToStringShort, // QString in: QDate
97 TimeToStringLong, // QString in: QTime
98 TimeToStringShort, // QString in: QTime
99 DateTimeFormatLong, // QString
100 DateTimeFormatShort, // QString
101 DateTimeToStringLong, // QString in: QDateTime
102 DateTimeToStringShort, // QString in: QDateTime
103 MeasurementSystem, // uint
104 PositiveSign, // QString
107 FirstDayOfWeek, // Qt::DayOfWeek
108 Weekdays, // QList<Qt::DayOfWeek>
109 CurrencySymbol, // QString in: CurrencyToStringArgument
110 CurrencyToString, // QString in: qlonglong, qulonglong or double
111 UILanguages, // QStringList
112 StringToStandardQuotation, // QString in: QStringRef to quote
113 StringToAlternateQuotation, // QString in: QStringRef to quote
115 ListToSeparatedString, // QString
116 LocaleChanged, // system locale changed
117 NativeLanguageName, // QString
118 NativeCountryName // QString
120 virtual QVariant query(QueryType type, QVariant in) const;
121 virtual QLocale fallbackLocale() const;
125 friend class QSystemLocaleSingleton;
129 struct Q_CORE_EXPORT QLocalePrivate
132 QChar decimal() const { return QChar(m_decimal); }
133 QChar group() const { return QChar(m_group); }
134 QChar list() const { return QChar(m_list); }
135 QChar percent() const { return QChar(m_percent); }
136 QChar zero() const { return QChar(m_zero); }
137 QChar plus() const { return QChar(m_plus); }
138 QChar minus() const { return QChar(m_minus); }
139 QChar exponential() const { return QChar(m_exponential); }
141 quint16 languageId() const { return m_language_id; }
142 quint16 countryId() const { return m_country_id; }
144 QString bcp47Name() const;
146 QString languageCode() const; // ### QByteArray::fromRawData would be more optimal
147 QString scriptCode() const;
148 QString countryCode() const;
150 static QLocale::Language codeToLanguage(const QString &code);
151 static QLocale::Script codeToScript(const QString &code);
152 static QLocale::Country codeToCountry(const QString &code);
153 static void getLangAndCountry(const QString &name, QLocale::Language &lang,
154 QLocale::Script &script, QLocale::Country &cntry);
155 static const QLocalePrivate *findLocale(QLocale::Language language,
156 QLocale::Script script,
157 QLocale::Country country);
160 QLocale::MeasurementSystem measurementSystem() const;
166 _DFMax = DFSignificantDigits
174 BlankBeforePositive = 0x08,
175 AlwaysShowSign = 0x10,
176 ThousandsGroup = 0x20,
180 UppercaseBase = 0x100,
181 ForcePoint = Alternate
184 enum GroupSeparatorMode {
185 FailOnGroupSeparators,
189 static QString doubleToString(const QChar zero, const QChar plus,
190 const QChar minus, const QChar exponent,
191 const QChar group, const QChar decimal,
192 double d, int precision,
194 int width, unsigned flags);
195 static QString longLongToString(const QChar zero, const QChar group,
196 const QChar plus, const QChar minus,
197 qint64 l, int precision, int base,
198 int width, unsigned flags);
199 static QString unsLongLongToString(const QChar zero, const QChar group,
201 quint64 l, int precision,
205 QString doubleToString(double d,
207 DoubleForm form = DFSignificantDigits,
209 unsigned flags = NoFlags) const;
210 QString longLongToString(qint64 l, int precision = -1,
213 unsigned flags = NoFlags) const;
214 QString unsLongLongToString(quint64 l, int precision = -1,
217 unsigned flags = NoFlags) const;
218 double stringToDouble(const QString &num, bool *ok, GroupSeparatorMode group_sep_mode) const;
219 qint64 stringToLongLong(const QString &num, int base, bool *ok, GroupSeparatorMode group_sep_mode) const;
220 quint64 stringToUnsLongLong(const QString &num, int base, bool *ok, GroupSeparatorMode group_sep_mode) const;
223 static double bytearrayToDouble(const char *num, bool *ok, bool *overflow = 0);
224 static qint64 bytearrayToLongLong(const char *num, int base, bool *ok, bool *overflow = 0);
225 static quint64 bytearrayToUnsLongLong(const char *num, int base, bool *ok);
227 typedef QVarLengthArray<char, 256> CharBuff;
228 bool numberToCLocale(const QString &num,
229 GroupSeparatorMode group_sep_mode,
230 CharBuff *result) const;
231 inline char digitToCLocale(QChar c) const;
233 static void updateSystemPrivate();
235 enum NumberMode { IntegerMode, DoubleStandardMode, DoubleScientificMode };
236 bool validateChars(const QString &str, NumberMode numMode, QByteArray *buff, int decDigits = -1) const;
238 QString dateTimeToString(const QString &format, const QDate *date, const QTime *time,
239 const QLocale *q) const;
241 quint16 m_language_id, m_script_id, m_country_id;
243 quint16 m_decimal, m_group, m_list, m_percent,
244 m_zero, m_minus, m_plus, m_exponential;
245 quint16 m_quotation_start, m_quotation_end;
246 quint16 m_alternate_quotation_start, m_alternate_quotation_end;
248 quint16 m_list_pattern_part_start_idx, m_list_pattern_part_start_size;
249 quint16 m_list_pattern_part_mid_idx, m_list_pattern_part_mid_size;
250 quint16 m_list_pattern_part_end_idx, m_list_pattern_part_end_size;
251 quint16 m_list_pattern_part_two_idx, m_list_pattern_part_two_size;
252 quint16 m_short_date_format_idx, m_short_date_format_size;
253 quint16 m_long_date_format_idx, m_long_date_format_size;
254 quint16 m_short_time_format_idx, m_short_time_format_size;
255 quint16 m_long_time_format_idx, m_long_time_format_size;
256 quint16 m_standalone_short_month_names_idx, m_standalone_short_month_names_size;
257 quint16 m_standalone_long_month_names_idx, m_standalone_long_month_names_size;
258 quint16 m_standalone_narrow_month_names_idx, m_standalone_narrow_month_names_size;
259 quint16 m_short_month_names_idx, m_short_month_names_size;
260 quint16 m_long_month_names_idx, m_long_month_names_size;
261 quint16 m_narrow_month_names_idx, m_narrow_month_names_size;
262 quint16 m_standalone_short_day_names_idx, m_standalone_short_day_names_size;
263 quint16 m_standalone_long_day_names_idx, m_standalone_long_day_names_size;
264 quint16 m_standalone_narrow_day_names_idx, m_standalone_narrow_day_names_size;
265 quint16 m_short_day_names_idx, m_short_day_names_size;
266 quint16 m_long_day_names_idx, m_long_day_names_size;
267 quint16 m_narrow_day_names_idx, m_narrow_day_names_size;
268 quint16 m_am_idx, m_am_size;
269 quint16 m_pm_idx, m_pm_size;
270 char m_currency_iso_code[3];
271 quint16 m_currency_symbol_idx, m_currency_symbol_size;
272 quint16 m_currency_display_name_idx, m_currency_display_name_size;
273 quint8 m_currency_format_idx, m_currency_format_size;
274 quint8 m_currency_negative_format_idx, m_currency_negative_format_size;
275 quint16 m_language_endonym_idx, m_language_endonym_size;
276 quint16 m_country_endonym_idx, m_country_endonym_size;
277 quint16 m_currency_digits : 2;
278 quint16 m_currency_rounding : 3;
279 quint16 m_first_day_of_week : 3;
280 quint16 m_weekend_start : 3;
281 quint16 m_weekend_end : 3;
285 inline char QLocalePrivate::digitToCLocale(QChar in) const
287 const QChar _zero = zero();
288 const QChar _group = group();
289 const ushort zeroUnicode = _zero.unicode();
290 const ushort tenUnicode = zeroUnicode + 10;
292 if (in.unicode() >= zeroUnicode && in.unicode() < tenUnicode)
293 return '0' + in.unicode() - zeroUnicode;
295 if (in.unicode() >= '0' && in.unicode() <= '9')
296 return in.toLatin1();
310 if (in == exponential() || in == exponential().toUpper())
313 // In several languages group() is the char 0xA0, which looks like a space.
314 // People use a regular space instead of it and complain it doesn't work.
315 if (_group.unicode() == 0xA0 && in.unicode() == ' ')
321 QString qt_readEscapedFormatString(const QString &format, int *idx);
322 bool qt_splitLocaleName(const QString &name, QString &lang, QString &script, QString &cntry);
323 int qt_repeatCount(const QString &s, int i);
327 Q_DECLARE_METATYPE(QStringRef)
328 Q_DECLARE_METATYPE(QList<Qt::DayOfWeek>)
329 #ifndef QT_NO_SYSTEMLOCALE
330 Q_DECLARE_METATYPE(QSystemLocale::CurrencyToStringArgument)
333 #endif // QLOCALE_P_H