Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qlocale.cpp File Reference
#include "qglobal.h"
#include "qplatformdefs.h"
#include "qdatastream.h"
#include "qdebug.h"
#include "qhashfunctions.h"
#include "qstring.h"
#include "qlocale.h"
#include "qlocale_p.h"
#include "qlocale_tools_p.h"
#include <private/qtools_p.h>
#include "qnamespace.h"
#include "qdatetime.h"
#include "qstringlist.h"
#include "qvariant.h"
#include "qvarlengtharray.h"
#include "qstringbuilder.h"
#include "private/qnumeric_p.h"
#include <cmath>
#include "qmutex.h"
#include "private/qcalendarbackend_p.h"
#include "private/qgregoriancalendar_p.h"
#include "qcalendar.h"
#include <q20iterator.h>
#include "qlocale_data_p.h"
#include "moc_qlocale.cpp"
+ Include dependency graph for qlocale.cpp:

Go to the source code of this file.

Macros

#define CheckCandidate(id)
 

Functions

static qsizetype findLocaleIndexById (const QLocaleId &localeId)
 
static QStringView findTag (QStringView name) noexcept
 
static bool validTag (QStringView tag)
 
static bool isScript (QStringView tag)
 
bool qt_splitLocaleName (QStringView name, QStringView *lang, QStringView *script, QStringView *land)
 
QString qt_readEscapedFormatString (QStringView format, qsizetype *idx)
 
qsizetype qt_repeatCount (QStringView s)
 
static QLocalePrivatec_private ()
 
static const QSystemLocalesystemLocale ()
 
static void updateSystemPrivate ()
 
static const QLocaleDatasystemData ()
 
static const QLocaleDatadefaultData ()
 
static qsizetype defaultIndex ()
 
QDataStreamoperator<< (QDataStream &ds, const QLocale &l)
 
QDataStreamoperator>> (QDataStream &ds, QLocale &l)
 
 Q_GLOBAL_STATIC (QSharedDataPointer< QLocalePrivate >, defaultLocalePrivate, new QLocalePrivate(defaultData(), defaultIndex())) static QLocalePrivate *localePrivateByName(QStringView name)
 
static QLocalePrivatefindLocalePrivate (QLocale::Language language, QLocale::Script script, QLocale::Territory territory)
 
static std::optional< QStringsystemLocaleString (const QLocaleData *that, QSystemLocale::QueryType type)
 
static QString localeString (const QLocaleData *that, QSystemLocale::QueryType type, QLocaleData::DataRange range)
 
template<typename T >
static T toIntegral_helper (const QLocalePrivate *d, QStringView str, bool *ok)
 
static bool timeFormatContainsAP (QStringView format)
 
static QString rawMonthName (const QCalendarLocale &localeData, const char16_t *monthsData, int month, QLocale::FormatType type)
 
static QString rawStandaloneMonthName (const QCalendarLocale &localeData, const char16_t *monthsData, int month, QLocale::FormatType type)
 
static QString rawWeekDayName (const QLocaleData *data, const int day, QLocale::FormatType type)
 
static QString rawStandaloneWeekDayName (const QLocaleData *data, const int day, QLocale::FormatType type)
 
static bool checkParsed (QByteArrayView num, qsizetype used)
 
QDebug operator<< (QDebug dbg, const QLocale &l)
 

Variables

static Q_CONSTINIT QSystemLocale_systemLocale = nullptr
 
static Q_CONSTINIT QLocaleData systemLocaleData = {}
 
static Q_CONSTINIT const QLocaleDatadefault_data = nullptr
 
static constexpr qsizetype locale_data_size = q20::ssize(locale_data) - 1
 

Macro Definition Documentation

◆ CheckCandidate

#define CheckCandidate (   id)
Value:
do { \
if (!tried.contains(id)) { \
if (index >= 0) \
return index; \
tried.push_back(id); \
} \
} while (false)
static qsizetype findLocaleIndexById(const QLocaleId &localeId)
Definition qlocale.cpp:466
GLuint index
[2]

Function Documentation

◆ c_private()

static QLocalePrivate * c_private ( )
static

Definition at line 686 of file qlocale.cpp.

References locale_data, and QLocale::OmitGroupSeparator.

Referenced by findLocalePrivate(), QLocale::matchingLocales(), and Q_GLOBAL_STATIC().

+ Here is the caller graph for this function:

◆ checkParsed()

static bool checkParsed ( QByteArrayView  num,
qsizetype  used 
)
static

Definition at line 4334 of file qlocale.cpp.

References ascii_isspace().

Referenced by QLocaleData::bytearrayToLongLong(), and QLocaleData::bytearrayToUnsLongLong().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ defaultData()

static const QLocaleData * defaultData ( )
static

Definition at line 809 of file qlocale.cpp.

References default_data, and systemData().

Referenced by defaultIndex(), and findLocalePrivate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ defaultIndex()

static qsizetype defaultIndex ( )
static

Definition at line 816 of file qlocale.cpp.

References defaultData(), QLocaleData::findLocaleIndex(), locale_data, Q_ASSERT, QtPrivate::q_points_into_range(), and systemLocaleData.

Referenced by findLocalePrivate(), language::lookupEnum(), and QLocale::system().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findLocaleIndexById()

static qsizetype findLocaleIndexById ( const QLocaleId localeId)
static

Definition at line 466 of file qlocale.cpp.

References QLocaleId::acceptLanguage(), QLocaleId::acceptScriptTerritory(), QLocaleData::id(), QLocaleId::language_id, locale_data, locale_index, and Q_ASSERT.

Referenced by QLocaleData::findLocaleIndex().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findLocalePrivate()

static QLocalePrivate * findLocalePrivate ( QLocale::Language  language,
QLocale::Script  script,
QLocale::Territory  territory 
)
static

Definition at line 871 of file qlocale.cpp.

References QLocale::C, c_private(), defaultData(), defaultIndex(), QLocale::DefaultNumberOptions, QLocaleData::findLocaleIndex(), locale_data, locale_data_size, and Q_ASSERT.

+ Here is the call graph for this function:

◆ findTag()

static QStringView findTag ( QStringView  name)
staticnoexcept

Definition at line 535 of file qlocale.cpp.

References i.

Referenced by qt_splitLocaleName().

+ Here is the caller graph for this function:

◆ isScript()

static bool isScript ( QStringView  tag)
static

Definition at line 555 of file qlocale.cpp.

References QString::fromLatin1(), QString::indexOf(), script_code_list, and tag.

Referenced by qt_splitLocaleName(), and QmlIR::IRBuilder::visit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ localeString()

static QString localeString ( const QLocaleData that,
QSystemLocale::QueryType  type,
QLocaleData::DataRange  range 
)
static

Definition at line 912 of file qlocale.cpp.

References opt, single_character_data, and systemLocaleString().

Referenced by QLocaleData::decimalPoint(), QLocaleData::groupSeparator(), QLocaleData::negativeSign(), QLocaleData::positiveSign(), and QLocaleData::zeroDigit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator<<() [1/2]

QDataStream & operator<< ( QDataStream ds,
const QLocale l 
)

Definition at line 839 of file qlocale.cpp.

References QLocale::name().

+ Here is the call graph for this function:

◆ operator<<() [2/2]

QDebug operator<< ( QDebug  dbg,
const QLocale l 
)

Definition at line 4758 of file qlocale.cpp.

References QLocale::language(), QLocale::languageToString(), QLocale::script(), QLocale::scriptToString(), QLocale::territory(), and QLocale::territoryToString().

+ Here is the call graph for this function:

◆ operator>>()

QDataStream & operator>> ( QDataStream ds,
QLocale l 
)

Definition at line 845 of file qlocale.cpp.

◆ Q_GLOBAL_STATIC()

Q_GLOBAL_STATIC ( QSharedDataPointer< QLocalePrivate ,
defaultLocalePrivate  ,
new   QLocalePrivatedefaultData(), defaultIndex() 
)

Definition at line 857 of file qlocale.cpp.

References QLocale::C, c_private(), QLocale::DefaultNumberOptions, QLocaleData::findLocaleIndex(), QLocaleId::fromName(), locale_data, locale_data_size, QLocale::OmitGroupSeparator, and Q_ASSERT.

+ Here is the call graph for this function:

◆ qt_readEscapedFormatString()

QString qt_readEscapedFormatString ( QStringView  format,
qsizetype idx 
)

Definition at line 623 of file qlocale.cpp.

References i, and Q_ASSERT.

Referenced by QCalendarBackend::dateTimeToString(), macToQtFormat(), and timeFormatContainsAP().

+ Here is the caller graph for this function:

◆ qt_repeatCount()

qsizetype qt_repeatCount ( QStringView  s)

Counts the number of identical leading characters in s.

If s is empty, returns 0.

Otherwise, returns the number of consecutive {s.front()} characters at the start of s.

qt_repeatCount(u"a"); // == 1
qt_repeatCount(u"ab"); // == 1
qt_repeatCount(u"aab"); // == 2
qsizetype qt_repeatCount(QStringView s)
Definition qlocale.cpp:673

Definition at line 673 of file qlocale.cpp.

References j.

Referenced by countRepeat(), QCalendarBackend::dateTimeToString(), and macToQtFormat().

+ Here is the caller graph for this function:

◆ qt_splitLocaleName()

bool qt_splitLocaleName ( QStringView  name,
QStringView lang,
QStringView script,
QStringView land 
)

Definition at line 565 of file qlocale.cpp.

References findTag(), isScript(), Q_FALLTHROUGH, sep, state, tag, and validTag().

Referenced by QLocaleId::fromName(), and getWinLocaleName().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rawMonthName()

static QString rawMonthName ( const QCalendarLocale localeData,
const char16_t *  monthsData,
int  month,
QLocale::FormatType  type 
)
static

Definition at line 2895 of file qlocale.cpp.

References QLocale::LongFormat, QLocale::NarrowFormat, and QLocale::ShortFormat.

Referenced by QCalendarBackend::monthName(), and rawStandaloneMonthName().

+ Here is the caller graph for this function:

◆ rawStandaloneMonthName()

static QString rawStandaloneMonthName ( const QCalendarLocale localeData,
const char16_t *  monthsData,
int  month,
QLocale::FormatType  type 
)
static

Definition at line 2920 of file qlocale.cpp.

References QString::isEmpty(), QLocale::LongFormat, QLocale::NarrowFormat, rawMonthName(), and QLocale::ShortFormat.

Referenced by QCalendarBackend::standaloneMonthName().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rawStandaloneWeekDayName()

static QString rawStandaloneWeekDayName ( const QLocaleData data,
const int  day,
QLocale::FormatType  type 
)
static

Definition at line 2970 of file qlocale.cpp.

References days_data, QLocale::LongFormat, QLocale::NarrowFormat, rawWeekDayName(), and QLocale::ShortFormat.

Referenced by QCalendarBackend::standaloneWeekDayName().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rawWeekDayName()

static QString rawWeekDayName ( const QLocaleData data,
const int  day,
QLocale::FormatType  type 
)
static

Definition at line 2946 of file qlocale.cpp.

References days_data, QLocale::LongFormat, QLocale::NarrowFormat, and QLocale::ShortFormat.

Referenced by rawStandaloneWeekDayName(), and QCalendarBackend::weekDayName().

+ Here is the caller graph for this function:

◆ systemData()

static const QLocaleData * systemData ( )
static

Definition at line 786 of file qlocale.cpp.

References locale_data, QMutex::lock(), systemLocaleData, and updateSystemPrivate().

Referenced by QLocale::QLocale(), defaultData(), QLocale::matchingLocales(), and QLocale::system().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ systemLocale()

◆ systemLocaleString()

static std::optional< QString > systemLocaleString ( const QLocaleData that,
QSystemLocale::QueryType  type 
)
static

Definition at line 894 of file qlocale.cpp.

References Q_UNUSED, QSystemLocale::query(), systemLocale(), systemLocaleData, and QVariant::toString().

Referenced by localeString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ timeFormatContainsAP()

static bool timeFormatContainsAP ( QStringView  format)
static

Definition at line 2098 of file qlocale.cpp.

References i, and qt_readEscapedFormatString().

Referenced by QCalendarBackend::dateTimeToString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toIntegral_helper()

template<typename T >
static T toIntegral_helper ( const QLocalePrivate d,
QStringView  str,
bool *  ok 
)
inlinestatic

Definition at line 1357 of file qlocale.cpp.

References d, Int64, ok, and str.

◆ updateSystemPrivate()

static void updateSystemPrivate ( )
static

Definition at line 755 of file qlocale.cpp.

References QLocale::AnyScript, QSystemLocale::fallbackLocaleIndex(), QSystemLocale::LanguageId, locale_data, QSystemLocale::LocaleChanged, QSystemLocale::query(), QSystemLocale::ScriptId, systemLocale(), systemLocaleData, and QSystemLocale::TerritoryId.

Referenced by systemData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validTag()

static bool validTag ( QStringView  tag)
static

Definition at line 544 of file qlocale.cpp.

References ch, QtMiscUtils::isAsciiLetterOrNumber(), and tag.

Referenced by qt_splitLocaleName().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ _systemLocale

Q_CONSTINIT QSystemLocale* _systemLocale = nullptr
static

◆ default_data

Q_CONSTINIT const QLocaleData* default_data = nullptr
static

Definition at line 684 of file qlocale.cpp.

Referenced by defaultData(), and QLocale::setDefault().

◆ locale_data_size

constexpr qsizetype locale_data_size = q20::ssize(locale_data) - 1
staticconstexpr

Definition at line 854 of file qlocale.cpp.

Referenced by findLocalePrivate(), QLocale::matchingLocales(), and Q_GLOBAL_STATIC().

◆ systemLocaleData