Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qlocale.cpp File Reference

(4431ffa8b90f4d089f98544e8c2eeac6cfc7abb2)

#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 (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 (qsizetype *sysIndex=nullptr)
 
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)
 
static Q_DECL_COLD_FUNCTION void badSeparatorWarning (const char *method, char sep)
 
template<typename T >
static T toIntegral_helper (const QLocalePrivate *d, QStringView str, bool *ok)
 
static bool timeFormatContainsAP (QStringView format)
 
static bool sameLocale (const QLocaleData *locale, const QCalendarLocale &calendar)
 
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(QLocaleId localeId)
Definition qlocale.cpp:468
GLuint index
[2]

Function Documentation

◆ badSeparatorWarning()

static Q_DECL_COLD_FUNCTION void badSeparatorWarning ( const char * method,
char sep )
static

Definition at line 1386 of file qlocale.cpp.

References method, qWarning, and sep.

Referenced by QLocale::bcp47Name(), QLocale::name(), and QLocale::uiLanguages().

+ Here is the caller graph for this function:

◆ c_private()

static QLocalePrivate * c_private ( )
static

Definition at line 689 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 4498 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 833 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 840 of file qlocale.cpp.

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

Referenced by QMimeType::comment(), findLocalePrivate(), and language::lookupEnum().

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

◆ findLocaleIndexById()

static qsizetype findLocaleIndexById ( QLocaleId localeId)
static

Definition at line 468 of file qlocale.cpp.

References locale_data, locale_index, and Q_ASSERT.

Referenced by QLocaleData::findLocaleIndex().

+ 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 894 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 537 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 557 of file qlocale.cpp.

References QString::fromLatin1(), 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 935 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 863 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 4936 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 869 of file qlocale.cpp.

◆ Q_GLOBAL_STATIC()

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

Definition at line 880 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 625 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:675

Definition at line 675 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 567 of file qlocale.cpp.

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

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

+ 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 3033 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 3058 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 3108 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 3084 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:

◆ sameLocale()

static bool sameLocale ( const QLocaleData * locale,
const QCalendarLocale & calendar )
static

Definition at line 3022 of file qlocale.cpp.

References calendar.

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

+ Here is the caller graph for this function:

◆ systemData()

static const QLocaleData * systemData ( qsizetype * sysIndex = nullptr)
static

Definition at line 793 of file qlocale.cpp.

References QLocaleData::findLocaleIndex(), locale_data, QMutex::lock(), Q_UNUSED, 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 917 of file qlocale.cpp.

References Q_UNUSED, systemLocale(), and systemLocaleData.

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 2188 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 1434 of file qlocale.cpp.

References d, Int64, ok, and str.

◆ updateSystemPrivate()

static void updateSystemPrivate ( )
static

Definition at line 758 of file qlocale.cpp.

References QLocale::AnyScript, default_data, QSystemLocale::LanguageId, locale_data, QSystemLocale::LocaleChanged, QLocalePrivate::s_generation, 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 546 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 686 of file qlocale.cpp.

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

◆ locale_data_size

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

◆ systemLocaleData