Qt 4.8
Classes | Functions
qlocale_p.h File Reference
#include "QtCore/qstring.h"
#include "QtCore/qvarlengtharray.h"
#include "QtCore/qmetatype.h"
#include "qlocale.h"

Go to the source code of this file.

Classes

struct  QLocalePrivate
 

Functions

QString qt_readEscapedFormatString (const QString &format, int *idx)
 
int qt_repeatCount (const QString &s, int i)
 
bool qt_splitLocaleName (const QString &name, QString &lang, QString &script, QString &cntry)
 

Function Documentation

◆ qt_readEscapedFormatString()

QString qt_readEscapedFormatString ( const QString format,
int *  idx 
)

Definition at line 387 of file qlocale.cpp.

Referenced by QLocalePrivate::dateTimeToString(), QLocalePrivate::digitToCLocale(), macToQtFormat(), timeFormatContainsAP(), and QSystemLocalePrivate::winToQtFormat().

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 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
QString & append(QChar c)
Definition: qstring.cpp:1777
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ qt_repeatCount()

int qt_repeatCount ( const QString s,
int  i 
)

Definition at line 421 of file qlocale.cpp.

Referenced by QLocalePrivate::dateTimeToString(), QLocalePrivate::digitToCLocale(), macToQtFormat(), and QSystemLocalePrivate::winToQtFormat().

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 }
unsigned char c[8]
Definition: qnumeric_p.h:62
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102

◆ qt_splitLocaleName()

bool qt_splitLocaleName ( const QString name,
QString lang,
QString script,
QString cntry 
)

Definition at line 302 of file qlocale.cpp.

Referenced by QLocalePrivate::digitToCLocale(), QLocalePrivate::getLangAndCountry(), getMacLocaleName(), and getWinLocaleName().

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 }
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
bool isNull() const
Returns true if the character is the Unicode character 0x0000 (&#39;\0&#39;); otherwise returns false...
Definition: qchar.h:262
static const unsigned char script_code_list[]
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
Q_CORE_EXPORT void qWarning(const char *,...)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
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
static bool parse_locale_tag(const QString &input, int &i, QString *result, const QString &separators)
Definition: qlocale.cpp:282