10#include "private/qstringiterator_p.h"
11#include "private/qgregoriancalendar_p.h"
13#include "private/qcore_mac_p.h"
14#include <CoreFoundation/CoreFoundation.h>
17#include <QtCore/qloggingcategory.h>
18#include <QtCore/qcoreapplication.h>
32 if (!lcLocale().isDebugEnabled())
37 Q_UNUSED(NSUserDefaults.standardUserDefaults);
39 auto singleLineDescription = [](NSArray *
array) {
41 str = [
str stringByReplacingOccurrencesOfString:
@"\n" withString:
@""];
42 return [
str stringByReplacingOccurrencesOfString:
@" " withString:
@""];
45 bool allowMixedLocalizations = [NSBundle.mainBundle.infoDictionary[
@"CFBundleAllowMixedLocalizations"] boolValue];
47 NSBundle *foundation = [NSBundle bundleForClass:NSBundle.class];
48 qCDebug(lcLocale).nospace() <<
"Launched with locale \"" << NSLocale.currentLocale.localeIdentifier
49 <<
"\" based on user's preferred languages " << singleLineDescription(NSLocale.preferredLanguages)
50 <<
", main bundle localizations " << singleLineDescription(NSBundle.mainBundle.localizations)
51 <<
", and allowing mixed localizations " << allowMixedLocalizations
52 <<
"; resulting in main bundle preferred localizations "
53 << singleLineDescription(NSBundle.mainBundle.preferredLocalizations)
54 <<
" and Foundation preferred localizations "
55 << singleLineDescription(foundation.preferredLocalizations);
56 qCDebug(lcLocale) <<
"Reflected by Qt as system locale"
64 CFStringRef locale = CFLocaleGetIdentifier(l);
65 return QString::fromCFString(locale);
71 if (month < 0 || month > 11)
76 kCFDateFormatterNoStyle, kCFDateFormatterNoStyle);
78 CFDateFormatterKey formatterType;
81 formatterType = kCFDateFormatterMonthSymbols;
84 formatterType = kCFDateFormatterShortMonthSymbols;
87 formatterType = kCFDateFormatterVeryShortMonthSymbols;
90 formatterType = kCFDateFormatterStandaloneMonthSymbols;
93 formatterType = kCFDateFormatterShortStandaloneMonthSymbols;
96 formatterType = kCFDateFormatterVeryShortStandaloneMonthSymbols;
99 qWarning(
"macMonthName: Unsupported query type %d",
type);
103 =
static_cast<CFArrayRef
>(CFDateFormatterCopyProperty(formatter, formatterType));
106 CFStringRef cfstring =
static_cast<CFStringRef
>(CFArrayGetValueAtIndex(
values, month));
107 return QString::fromCFString(cfstring);
114 if (day < 1 || day > 7)
119 kCFDateFormatterNoStyle, kCFDateFormatterNoStyle);
121 CFDateFormatterKey formatterType;
124 formatterType = kCFDateFormatterWeekdaySymbols;
127 formatterType = kCFDateFormatterShortWeekdaySymbols;
130 formatterType = kCFDateFormatterVeryShortWeekdaySymbols;
133 formatterType = kCFDateFormatterStandaloneWeekdaySymbols;
136 formatterType = kCFDateFormatterShortStandaloneWeekdaySymbols;
139 formatterType = kCFDateFormatterVeryShortStandaloneWeekdaySymbols;
142 qWarning(
"macDayName: Unsupported query type %d",
type);
146 static_cast<CFArrayRef
>(CFDateFormatterCopyProperty(formatter, formatterType));
149 CFStringRef cfstring =
static_cast<CFStringRef
>(CFArrayGetValueAtIndex(
values, day % 7));
150 return QString::fromCFString(cfstring);
157 static QString cachedZeroDigit;
159 if (cachedZeroDigit.
isNull()) {
162 CFNumberFormatterCreate(
nullptr, locale, kCFNumberFormatterNoStyle);
163 const int zeroDigit = 0;
165 = CFNumberFormatterCreateStringWithValue(
nullptr, numberFormatter,
166 kCFNumberIntType, &zeroDigit);
167 cachedZeroDigit = QString::fromCFString(
value);
171 nil, NSCurrentLocaleDidChangeNotification, [&] {
172 qCDebug(lcLocale) <<
"System locale changed";
176 return cachedZeroDigit;
184 while (
it.hasNext()) {
194 while (
digits++ < minDigits)
207 while (
it.hasNext()) {
213 prev = std::exchange(last, here);
228 CFNumberFormatterCreate(
nullptr, locale, kCFNumberFormatterNoStyle);
230 kCFNumberIntType, &year);
231 auto text = QString::fromCFString(
value);
232 if (year > -1000 && year < 1000)
246 = CFDateFormatterCreate(kCFAllocatorDefault, mylocale, style,
247 kCFDateFormatterNoStyle);
249 return QString::fromCFString(
text);
274 ? kCFDateFormatterShortStyle
275 : kCFDateFormatterLongStyle);
278 return std::move(
text).
replace(fakeYear, trueYear);
283 return std::move(
text).replace(fakeYear, trueYear);
285 qWarning(
"Failed to fix up year when formatting a date in year %d", year);
294 CFDateFormatterStyle style = short_format ? kCFDateFormatterShortStyle : kCFDateFormatterLongStyle;
297 kCFDateFormatterNoStyle,
300 return QString::fromCFString(
text);
313 while (
i < sys_fmt.
size()) {
326 switch (
c.unicode()) {
414 if (
c < u
'A' ||
c > u
'z' || (
c > u
'Z' &&
c < u
'a'))
429 l, style, kCFDateFormatterNoStyle);
430 return macToQtFormat(QString::fromCFString(CFDateFormatterGetFormat(formatter)));
437 l, kCFDateFormatterNoStyle, style);
438 return macToQtFormat(QString::fromCFString(CFDateFormatterGetFormat(formatter)));
444 CFTypeRef
value = CFLocaleGetValue(locale,
key);
447 return QString::fromCFString(CFStringRef(
static_cast<CFTypeRef
>(
value)));
453 CFStringRef system =
static_cast<CFStringRef
>(CFLocaleGetValue(locale, kCFLocaleMeasurementSystem));
454 if (QString::fromCFString(system) ==
"Metric"_L1) {
476 return QString::fromCFString(
static_cast<CFStringRef
>(CFLocaleGetValue(locale, kCFLocaleCurrencyCode)));
478 return QString::fromCFString(
static_cast<CFStringRef
>(CFLocaleGetValue(locale, kCFLocaleCurrencySymbol)));
480 CFStringRef code =
static_cast<CFStringRef
>(CFLocaleGetValue(locale, kCFLocaleCurrencyCode));
482 return QString::fromCFString(
value);
490#ifndef QT_NO_SYSTEMLOCALE
494 switch (
arg.value.metaType().id()) {
496 case QMetaType::UInt: {
497 int v =
arg.value.toInt();
498 value = CFNumberCreate(NULL, kCFNumberIntType, &
v);
501 case QMetaType::Double: {
502 double v =
arg.value.toDouble();
503 value = CFNumberCreate(NULL, kCFNumberDoubleType, &
v);
506 case QMetaType::LongLong:
507 case QMetaType::ULongLong: {
509 value = CFNumberCreate(NULL, kCFNumberLongLongType, &
v);
518 CFNumberFormatterCreate(NULL, locale, kCFNumberFormatterCurrencyStyle);
519 if (!
arg.symbol.isEmpty()) {
520 CFNumberFormatterSetProperty(currencyFormatter, kCFNumberFormatterCurrencySymbol,
521 arg.symbol.toCFString());
524 return QString::fromCFString(
result);
533 begin = QString::fromCFString(
static_cast<CFStringRef
>(CFLocaleGetValue(locale, kCFLocaleQuotationBeginDelimiterKey)));
534 end = QString::fromCFString(
static_cast<CFStringRef
>(CFLocaleGetValue(locale, kCFLocaleQuotationEndDelimiterKey)));
537 begin = QString::fromCFString(
static_cast<CFStringRef
>(CFLocaleGetValue(locale, kCFLocaleAlternateQuotationBeginDelimiterKey)));
538 end = QString::fromCFString(
static_cast<CFStringRef
>(CFLocaleGetValue(locale, kCFLocaleAlternateQuotationEndDelimiterKey)));
547#ifndef QT_NO_SYSTEMLOCALE
554template <auto CodeToValueFunction>
563 if (
auto value = CodeToValueFunction(code.toString()))
580 return getLocaleValue<codeToLanguage>(kCFLocaleLanguageCode);
582 return getLocaleValue<QLocalePrivate::codeToTerritory>(kCFLocaleCountryCode);
584 return getLocaleValue<QLocalePrivate::codeToScript>(kCFLocaleScriptCode);
592 ? kCFDateFormatterShortStyle
593 : kCFDateFormatterLongStyle);
597 ? kCFDateFormatterShortStyle
598 : kCFDateFormatterLongStyle);
634 (
type ==
AMText ? kCFDateFormatterAMSymbol : kCFDateFormatterPMSymbol)));
635 return QString::fromCFString(
value);
646 const CFIndex cnt = CFArrayGetCount(languages);
648 for (CFIndex
i = 0;
i < cnt; ++
i) {
649 const QString lang = QString::fromCFString(
650 static_cast<CFStringRef
>(CFArrayGetValueAtIndex(languages,
i)));
constexpr bool isDigit() const noexcept
Returns true if the character is a decimal digit (Number_DecimalDigit); otherwise returns false.
constexpr char16_t unicode() const noexcept
Returns the numeric Unicode value of the QChar.
\inmodule QtCore\reentrant
\inmodule QtCore \reentrant
int month() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
int day() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
int year() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QDate currentDate()
Returns the system clock's current date.
static int yearSharingWeekDays(QDate date)
static QLocale::Language codeToLanguage(QStringView code, QLocale::LanguageCodeTypes codeTypes=QLocale::AnyLanguageCode) noexcept
QStringList uiLanguages() const
List of locale names for use in selecting translations.
static QLocale system()
Returns a QLocale object initialized to the system locale.
constexpr qsizetype size() const noexcept
Returns the size of this string view, in UTF-16 code units (that is, surrogate pairs count as two for...
constexpr QChar at(qsizetype n) const noexcept
Returns the character at position n in this string view.
constexpr QStringView mid(qsizetype pos, qsizetype n=-1) const noexcept
Returns the substring of length length starting at position start in this object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString & replace(qsizetype i, qsizetype len, QChar after)
bool isNull() const
Returns true if this string is null; otherwise returns false.
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
@ StringToAlternateQuotation
@ StandaloneMonthNameLong
@ StandaloneDayNameNarrow
@ StandaloneMonthNameNarrow
@ StringToStandardQuotation
@ StandaloneMonthNameShort
virtual QVariant query(QueryType type, QVariant in=QVariant()) const
virtual QLocale fallbackLocale() const
\inmodule QtCore \reentrant
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
cache insert(employee->id(), employee)
QSet< QString >::iterator it
Combined button and popup list for selecting options.
#define Q_COREAPP_STARTUP_FUNCTION(AFUNC)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
qsizetype qt_repeatCount(QStringView s)
QString qt_readEscapedFormatString(QStringView format, qsizetype *idx)
static QVariant getMacTimeFormat(CFDateFormatterStyle style)
static QVariant macDateToString(QDate date, bool short_format)
static QVariant getCFLocaleValue(CFStringRef key)
static void printLocalizationInformation()
static QVariant macDayName(int day, QSystemLocale::QueryType type)
static QVariant macMeasurementSystem()
static QVariant macTimeToString(QTime time, bool short_format)
static QVariant macMonthName(int month, QSystemLocale::QueryType type)
static QVariant macCurrencySymbol(QLocale::CurrencySymbolFormat format)
static QString zeroPad(QString &&number, qsizetype minDigits, const QString &zero)
static QVariant macToQtFormat(QStringView sys_fmt)
static QString fourDigitYear(int year, const QString &zero)
static QVariant macFormatCurrency(const QSystemLocale::CurrencyToStringArgument &arg)
static QString getMacLocaleName()
static QString trimTwoDigits(QString &&number)
static QVariant getMacDateFormat(CFDateFormatterStyle style)
static QString macDateToStringImpl(QDate date, CFDateFormatterStyle style)
static QString macZeroDigit()
static quint8 macFirstDayOfWeek()
static QLocale::Language codeToLanguage(QStringView s)
static QVariant macQuoteString(QSystemLocale::QueryType type, QStringView str)
static QVariant getLocaleValue(CFStringRef key)
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLenum GLsizei GLsizei GLint * values
[15]
GLsizei const GLfloat * v
[13]
GLint GLsizei GLsizei GLenum format
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
static const auto matcher
[0]