Qt 4.8
qlocale_p.h
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 #ifndef QLOCALE_P_H
43 #define QLOCALE_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
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.
52 //
53 // We mean it.
54 //
55 
56 #include "QtCore/qstring.h"
57 #include "QtCore/qvarlengtharray.h"
58 #include "QtCore/qmetatype.h"
59 
60 #include "qlocale.h"
61 
62 #if defined(Q_OS_SYMBIAN) && !defined(QT_NO_SYSTEMLOCALE)
63 class CEnvironmentChangeNotifier;
64 #endif
65 
67 
69 {
70 public:
71  QChar decimal() const { return QChar(m_decimal); }
72  QChar group() const { return QChar(m_group); }
73  QChar list() const { return QChar(m_list); }
74  QChar percent() const { return QChar(m_percent); }
75  QChar zero() const { return QChar(m_zero); }
76  QChar plus() const { return QChar(m_plus); }
77  QChar minus() const { return QChar(m_minus); }
78  QChar exponential() const { return QChar(m_exponential); }
79 
80  quint16 languageId() const { return m_language_id; }
81  quint16 countryId() const { return m_country_id; }
82 
83  QString bcp47Name() const;
84 
85  QString languageCode() const; // ### QByteArray::fromRawData would be more optimal
86  QString scriptCode() const;
87  QString countryCode() const;
88 
89  static QLocale::Language codeToLanguage(const QString &code);
90  static QLocale::Script codeToScript(const QString &code);
91  static QLocale::Country codeToCountry(const QString &code);
92  static void getLangAndCountry(const QString &name, QLocale::Language &lang,
95  QLocale::Script script,
97 
98 
99  QLocale::MeasurementSystem measurementSystem() const;
100 
101  enum DoubleForm {
102  DFExponent = 0,
105  _DFMax = DFSignificantDigits
106  };
107 
108  enum Flags {
109  NoFlags = 0,
110  Alternate = 0x01,
111  ZeroPadded = 0x02,
112  LeftAdjusted = 0x04,
113  BlankBeforePositive = 0x08,
114  AlwaysShowSign = 0x10,
115  ThousandsGroup = 0x20,
116  CapitalEorX = 0x40,
117 
118  ShowBase = 0x80,
119  UppercaseBase = 0x100,
120  ForcePoint = Alternate
121  };
122 
125  ParseGroupSeparators
126  };
127 
128  static QString doubleToString(const QChar zero, const QChar plus,
129  const QChar minus, const QChar exponent,
130  const QChar group, const QChar decimal,
131  double d, int precision,
132  DoubleForm form,
133  int width, unsigned flags);
134  static QString longLongToString(const QChar zero, const QChar group,
135  const QChar plus, const QChar minus,
136  qint64 l, int precision, int base,
137  int width, unsigned flags);
138  static QString unsLongLongToString(const QChar zero, const QChar group,
139  const QChar plus,
140  quint64 l, int precision,
141  int base, int width,
142  unsigned flags);
143 
144  QString doubleToString(double d,
145  int precision = -1,
146  DoubleForm form = DFSignificantDigits,
147  int width = -1,
148  unsigned flags = NoFlags) const;
149  QString longLongToString(qint64 l, int precision = -1,
150  int base = 10,
151  int width = -1,
152  unsigned flags = NoFlags) const;
153  QString unsLongLongToString(quint64 l, int precision = -1,
154  int base = 10,
155  int width = -1,
156  unsigned flags = NoFlags) const;
157  double stringToDouble(const QString &num, bool *ok, GroupSeparatorMode group_sep_mode) const;
158  qint64 stringToLongLong(const QString &num, int base, bool *ok, GroupSeparatorMode group_sep_mode) const;
159  quint64 stringToUnsLongLong(const QString &num, int base, bool *ok, GroupSeparatorMode group_sep_mode) const;
160 
161 
162  static double bytearrayToDouble(const char *num, bool *ok, bool *overflow = 0);
163  static qint64 bytearrayToLongLong(const char *num, int base, bool *ok, bool *overflow = 0);
164  static quint64 bytearrayToUnsLongLong(const char *num, int base, bool *ok);
165 
167  bool numberToCLocale(const QString &num,
168  GroupSeparatorMode group_sep_mode,
169  CharBuff *result) const;
170  inline char digitToCLocale(const QChar &c) const;
171 
172  static void updateSystemPrivate();
173 
174  enum NumberMode { IntegerMode, DoubleStandardMode, DoubleScientificMode };
175  bool validateChars(const QString &str, NumberMode numMode, QByteArray *buff, int decDigits = -1) const;
176 
177  QString dateTimeToString(const QString &format, const QDate *date, const QTime *time,
178  const QLocale *q) const;
179 
180  quint16 m_language_id, m_script_id, m_country_id;
181 
182  quint16 m_decimal, m_group, m_list, m_percent,
183  m_zero, m_minus, m_plus, m_exponential;
184  quint16 m_quotation_start, m_quotation_end;
185  quint16 m_alternate_quotation_start, m_alternate_quotation_end;
186 
187  quint16 m_list_pattern_part_start_idx, m_list_pattern_part_start_size;
188  quint16 m_list_pattern_part_mid_idx, m_list_pattern_part_mid_size;
189  quint16 m_list_pattern_part_end_idx, m_list_pattern_part_end_size;
190  quint16 m_list_pattern_part_two_idx, m_list_pattern_part_two_size;
191  quint16 m_short_date_format_idx, m_short_date_format_size;
192  quint16 m_long_date_format_idx, m_long_date_format_size;
193  quint16 m_short_time_format_idx, m_short_time_format_size;
194  quint16 m_long_time_format_idx, m_long_time_format_size;
195  quint16 m_standalone_short_month_names_idx, m_standalone_short_month_names_size;
196  quint16 m_standalone_long_month_names_idx, m_standalone_long_month_names_size;
197  quint16 m_standalone_narrow_month_names_idx, m_standalone_narrow_month_names_size;
198  quint16 m_short_month_names_idx, m_short_month_names_size;
199  quint16 m_long_month_names_idx, m_long_month_names_size;
200  quint16 m_narrow_month_names_idx, m_narrow_month_names_size;
201  quint16 m_standalone_short_day_names_idx, m_standalone_short_day_names_size;
202  quint16 m_standalone_long_day_names_idx, m_standalone_long_day_names_size;
203  quint16 m_standalone_narrow_day_names_idx, m_standalone_narrow_day_names_size;
204  quint16 m_short_day_names_idx, m_short_day_names_size;
205  quint16 m_long_day_names_idx, m_long_day_names_size;
206  quint16 m_narrow_day_names_idx, m_narrow_day_names_size;
207  quint16 m_am_idx, m_am_size;
208  quint16 m_pm_idx, m_pm_size;
209  char m_currency_iso_code[3];
210  quint16 m_currency_symbol_idx, m_currency_symbol_size;
211  quint16 m_currency_display_name_idx, m_currency_display_name_size;
212  quint8 m_currency_format_idx, m_currency_format_size;
213  quint8 m_currency_negative_format_idx, m_currency_negative_format_size;
214  quint16 m_language_endonym_idx, m_language_endonym_size;
215  quint16 m_country_endonym_idx, m_country_endonym_size;
221 
222 };
223 
224 inline char QLocalePrivate::digitToCLocale(const QChar &in) const
225 {
226  const QChar _zero = zero();
227  const QChar _group = group();
228  const ushort zeroUnicode = _zero.unicode();
229  const ushort tenUnicode = zeroUnicode + 10;
230 
231  if (in.unicode() >= zeroUnicode && in.unicode() < tenUnicode)
232  return '0' + in.unicode() - zeroUnicode;
233 
234  if (in.unicode() >= '0' && in.unicode() <= '9')
235  return in.toLatin1();
236 
237  if (in == plus())
238  return '+';
239 
240  if (in == minus())
241  return '-';
242 
243  if (in == decimal())
244  return '.';
245 
246  if (in == group())
247  return ',';
248 
249  if (in == exponential() || in == exponential().toUpper())
250  return 'e';
251 
252  // In several languages group() is the char 0xA0, which looks like a space.
253  // People use a regular space instead of it and complain it doesn't work.
254  if (_group.unicode() == 0xA0 && in.unicode() == ' ')
255  return ',';
256 
257  return 0;
258 }
259 
260 #if defined(Q_OS_SYMBIAN) && !defined(QT_NO_SYSTEMLOCALE)
261 class QEnvironmentChangeNotifier
262 {
263 public:
264  QEnvironmentChangeNotifier();
265  ~QEnvironmentChangeNotifier();
266 
267  static TInt localeChanged(TAny *data);
268 
269 private:
270  CEnvironmentChangeNotifier *iChangeNotifier;
271 };
272 #endif
273 
275 bool qt_splitLocaleName(const QString &name, QString &lang, QString &script, QString &cntry);
276 int qt_repeatCount(const QString &s, int i);
277 
279 
282 
283 #endif // QLOCALE_P_H
double d
Definition: qnumeric_p.h:62
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
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QChar zero() const
Definition: qlocale_p.h:75
quint16 countryId() const
Definition: qlocale_p.h:81
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
int qt_repeatCount(const QString &s, int i)
Definition: qlocale.cpp:421
quint16 m_quotation_start
Definition: qlocale_p.h:184
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QChar plus() const
Definition: qlocale_p.h:76
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
quint16 languageId() const
Definition: qlocale_p.h:80
The QDate class provides date functions.
Definition: qdatetime.h:55
static const QLocalePrivate * findLocale(const QString &name)
Definition: qlocale.cpp:377
quint16 m_list_pattern_part_two_size
Definition: qlocale_p.h:190
unsigned char quint8
Definition: qglobal.h:934
quint16 m_short_date_format_size
Definition: qlocale_p.h:191
The QString class provides a Unicode character string.
Definition: qstring.h:83
quint16 m_alternate_quotation_start
Definition: qlocale_p.h:185
static const uint base
Definition: qurl.cpp:268
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
quint16 m_weekend_end
Definition: qlocale_p.h:220
quint16 m_short_day_names_size
Definition: qlocale_p.h:204
quint16 m_standalone_narrow_month_names_size
Definition: qlocale_p.h:197
quint16 m_am_size
Definition: qlocale_p.h:207
quint16 m_currency_rounding
Definition: qlocale_p.h:217
The QTime class provides clock time functions.
Definition: qdatetime.h:148
QLocale::Language language
quint16 m_zero
Definition: qlocale_p.h:182
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QString qt_readEscapedFormatString(const QString &format, int *idx)
Definition: qlocale.cpp:387
quint16 m_standalone_short_day_names_size
Definition: qlocale_p.h:201
quint16 m_list_pattern_part_start_size
Definition: qlocale_p.h:187
unsigned __int64 quint64
Definition: qglobal.h:943
const char * name
quint16 m_standalone_long_day_names_size
Definition: qlocale_p.h:202
quint8 m_currency_negative_format_size
Definition: qlocale_p.h:213
char digitToCLocale(const QChar &c) const
Definition: qlocale_p.h:224
QChar list() const
Definition: qlocale_p.h:73
unsigned short quint16
Definition: qglobal.h:936
static const char * data(const QByteArray &arr)
quint16 m_country_endonym_size
Definition: qlocale_p.h:215
QChar percent() const
Definition: qlocale_p.h:74
quint16 m_long_time_format_size
Definition: qlocale_p.h:194
__int64 qint64
Definition: qglobal.h:942
quint16 m_list_pattern_part_end_size
Definition: qlocale_p.h:189
QChar minus() const
Definition: qlocale_p.h:77
Language
Definition: qlocale.h:148
quint16 m_narrow_day_names_size
Definition: qlocale_p.h:206
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
#define Q_DECLARE_METATYPE(TYPE)
This macro makes the type Type known to QMetaType as long as it provides a public default constructor...
Definition: qmetatype.h:265
quint16 m_pm_size
Definition: qlocale_p.h:208
bool qt_splitLocaleName(const QString &name, QString &lang, QString &script, QString &cntry)
Definition: qlocale.cpp:302
quint16 m_currency_symbol_size
Definition: qlocale_p.h:210
QChar exponential() const
Definition: qlocale_p.h:78
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
unsigned short ushort
Definition: qglobal.h:995
QVarLengthArray< char, 256 > CharBuff
Definition: qlocale_p.h:166
quint16 m_list_pattern_part_mid_size
Definition: qlocale_p.h:188
quint16 m_language_endonym_size
Definition: qlocale_p.h:214
quint16 m_script_id
Definition: qlocale_p.h:180
static const int zero
QFactoryLoader * l
MeasurementSystem
Definition: qlocale.h:657
char toLatin1() const
Returns the Latin-1 character equivalent to the QChar, or 0.
Definition: qchar.h:376
quint8 m_currency_format_size
Definition: qlocale_p.h:212
quint16 m_long_day_names_size
Definition: qlocale_p.h:205
quint16 m_currency_digits
Definition: qlocale_p.h:216
QLocale::Country country
quint16 m_first_day_of_week
Definition: qlocale_p.h:218
quint16 m_long_month_names_size
Definition: qlocale_p.h:199
quint16 m_currency_display_name_size
Definition: qlocale_p.h:211
quint16 m_long_date_format_size
Definition: qlocale_p.h:192
quint16 m_short_time_format_size
Definition: qlocale_p.h:193
quint16 m_weekend_start
Definition: qlocale_p.h:219
The QList class is a template class that provides lists.
Definition: qdatastream.h:62