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())
35#if defined(Q_OS_MACOS)
38 Q_UNUSED(NSUserDefaults.standardUserDefaults);
41 auto singleLineDescription = [](NSArray *
array) {
43 str = [
str stringByReplacingOccurrencesOfString:
@"\n" withString:
@""];
44 return [
str stringByReplacingOccurrencesOfString:
@" " withString:
@""];
47 bool allowMixedLocalizations = [NSBundle.mainBundle.infoDictionary[
@"CFBundleAllowMixedLocalizations"] boolValue];
49 NSBundle *foundation = [NSBundle bundleForClass:NSBundle.class];
50 qCDebug(lcLocale).nospace() <<
"Launched with locale \"" << NSLocale.currentLocale.localeIdentifier
51 <<
"\" based on user's preferred languages " << singleLineDescription(NSLocale.preferredLanguages)
52 <<
", main bundle localizations " << singleLineDescription(NSBundle.mainBundle.localizations)
53 <<
", and allowing mixed localizations " << allowMixedLocalizations
54 <<
"; resulting in main bundle preferred localizations "
55 << singleLineDescription(NSBundle.mainBundle.preferredLocalizations)
56 <<
" and Foundation preferred localizations "
57 << singleLineDescription(foundation.preferredLocalizations);
58 qCDebug(lcLocale) <<
"Reflected by Qt as system locale"
65 QCFType<CFLocaleRef> l = CFLocaleCopyCurrent();
66 CFStringRef locale = CFLocaleGetIdentifier(l);
67 return QString::fromCFString(locale);
73 if (month < 0 || month > 11)
76 QCFType<CFDateFormatterRef> formatter
77 = CFDateFormatterCreate(0, QCFType<CFLocaleRef>(CFLocaleCopyCurrent()),
78 kCFDateFormatterNoStyle, kCFDateFormatterNoStyle);
80 CFDateFormatterKey formatterType;
83 formatterType = kCFDateFormatterMonthSymbols;
86 formatterType = kCFDateFormatterShortMonthSymbols;
89 formatterType = kCFDateFormatterVeryShortMonthSymbols;
92 formatterType = kCFDateFormatterStandaloneMonthSymbols;
95 formatterType = kCFDateFormatterShortStandaloneMonthSymbols;
98 formatterType = kCFDateFormatterVeryShortStandaloneMonthSymbols;
101 qWarning(
"macMonthName: Unsupported query type %d",
type);
104 QCFType<CFArrayRef>
values
105 =
static_cast<CFArrayRef
>(CFDateFormatterCopyProperty(formatter, formatterType));
108 CFStringRef cfstring =
static_cast<CFStringRef
>(CFArrayGetValueAtIndex(
values, month));
109 return QString::fromCFString(cfstring);
116 if (day < 1 || day > 7)
119 QCFType<CFDateFormatterRef> formatter
120 = CFDateFormatterCreate(0, QCFType<CFLocaleRef>(CFLocaleCopyCurrent()),
121 kCFDateFormatterNoStyle, kCFDateFormatterNoStyle);
123 CFDateFormatterKey formatterType;
126 formatterType = kCFDateFormatterWeekdaySymbols;
129 formatterType = kCFDateFormatterShortWeekdaySymbols;
132 formatterType = kCFDateFormatterVeryShortWeekdaySymbols;
135 formatterType = kCFDateFormatterStandaloneWeekdaySymbols;
138 formatterType = kCFDateFormatterShortStandaloneWeekdaySymbols;
141 formatterType = kCFDateFormatterVeryShortStandaloneWeekdaySymbols;
144 qWarning(
"macDayName: Unsupported query type %d",
type);
147 QCFType<CFArrayRef>
values =
148 static_cast<CFArrayRef
>(CFDateFormatterCopyProperty(formatter, formatterType));
151 CFStringRef cfstring =
static_cast<CFStringRef
>(CFArrayGetValueAtIndex(
values, day % 7));
152 return QString::fromCFString(cfstring);
159 static QString cachedZeroDigit;
161 if (cachedZeroDigit.isNull()) {
162 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
163 QCFType<CFNumberFormatterRef> numberFormatter =
164 CFNumberFormatterCreate(
nullptr, locale, kCFNumberFormatterNoStyle);
165 const int zeroDigit = 0;
166 QCFType<CFStringRef>
value
167 = CFNumberFormatterCreateStringWithValue(
nullptr, numberFormatter,
168 kCFNumberIntType, &zeroDigit);
169 cachedZeroDigit = QString::fromCFString(
value);
173 nil, NSCurrentLocaleDidChangeNotification, [&] {
174 qCDebug(lcLocale) <<
"System locale changed";
178 return cachedZeroDigit;
186 while (
it.hasNext()) {
188 if (QChar::isDigit(
it.next())) {
196 while (
digits++ < minDigits)
209 while (
it.hasNext()) {
211 if (QChar::isDigit(
it.next())) {
215 prev = std::exchange(last, here);
228 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
229 QCFType<CFNumberFormatterRef> numberFormatter =
230 CFNumberFormatterCreate(
nullptr, locale, kCFNumberFormatterNoStyle);
231 QCFType<CFStringRef>
value = CFNumberFormatterCreateStringWithValue(
nullptr, numberFormatter,
232 kCFNumberIntType, &year);
233 auto text = QString::fromCFString(
value);
234 if (year > -1000 && year < 1000)
246 QCFType<CFLocaleRef> mylocale = CFLocaleCopyCurrent();
247 QCFType<CFDateFormatterRef> myFormatter
248 = CFDateFormatterCreate(kCFAllocatorDefault, mylocale, style,
249 kCFDateFormatterNoStyle);
250 QCFType<CFStringRef>
text = CFDateFormatterCreateStringWithDate(
nullptr, myFormatter, myDate);
251 return QString::fromCFString(
text);
276 ? kCFDateFormatterShortStyle
277 : kCFDateFormatterLongStyle);
280 return std::move(
text).replace(fakeYear, trueYear);
285 return std::move(
text).replace(fakeYear, trueYear);
287 qWarning(
"Failed to fix up year when formatting a date in year %d", year);
295 QCFType<CFLocaleRef> mylocale = CFLocaleCopyCurrent();
296 CFDateFormatterStyle style = short_format ? kCFDateFormatterShortStyle : kCFDateFormatterLongStyle;
297 QCFType<CFDateFormatterRef> myFormatter = CFDateFormatterCreate(kCFAllocatorDefault,
299 kCFDateFormatterNoStyle,
301 QCFType<CFStringRef>
text = CFDateFormatterCreateStringWithDate(0, myFormatter, myDate);
302 return QString::fromCFString(
text);
315 while (
i < sys_fmt.size()) {
316 if (sys_fmt.at(
i).unicode() ==
'\'') {
328 switch (
c.unicode()) {
414 result += (repeat > 1 && (repeat & 1)) ?
"ttt"_L1 :
"tt"_L1;
418 result += repeat < 4 ?
"tt"_L1 : repeat > 4 ?
"ttt"_L1 :
"t"_L1;
424 if (
c < u
'A' ||
c > u
'z' || (
c > u
'Z' &&
c < u
'a'))
437 QCFType<CFLocaleRef> l = CFLocaleCopyCurrent();
438 QCFType<CFDateFormatterRef> formatter = CFDateFormatterCreate(kCFAllocatorDefault,
439 l, style, kCFDateFormatterNoStyle);
440 return macToQtFormat(QString::fromCFString(CFDateFormatterGetFormat(formatter)));
445 QCFType<CFLocaleRef> l = CFLocaleCopyCurrent();
446 QCFType<CFDateFormatterRef> formatter = CFDateFormatterCreate(kCFAllocatorDefault,
447 l, kCFDateFormatterNoStyle, style);
448 return macToQtFormat(QString::fromCFString(CFDateFormatterGetFormat(formatter)));
453 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
454 CFTypeRef
value = CFLocaleGetValue(locale,
key);
457 return QString::fromCFString(CFStringRef(
static_cast<CFTypeRef
>(
value)));
462 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
463 CFStringRef system =
static_cast<CFStringRef
>(CFLocaleGetValue(locale, kCFLocaleMeasurementSystem));
464 if (QString::fromCFString(system) ==
"Metric"_L1) {
474 QCFType<CFCalendarRef>
calendar = CFCalendarCopyCurrent();
483 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
486 return QString::fromCFString(
static_cast<CFStringRef
>(CFLocaleGetValue(locale, kCFLocaleCurrencyCode)));
488 return QString::fromCFString(
static_cast<CFStringRef
>(CFLocaleGetValue(locale, kCFLocaleCurrencySymbol)));
490 CFStringRef code =
static_cast<CFStringRef
>(CFLocaleGetValue(locale, kCFLocaleCurrencyCode));
491 QCFType<CFStringRef>
value = CFLocaleCopyDisplayNameForPropertyValue(locale, kCFLocaleCurrencyCode, code);
492 return QString::fromCFString(
value);
500#ifndef QT_NO_SYSTEMLOCALE
503 QCFType<CFNumberRef>
value;
504 switch (
arg.value.metaType().id()) {
506 case QMetaType::UInt: {
507 int v =
arg.value.toInt();
508 value = CFNumberCreate(NULL, kCFNumberIntType, &
v);
511 case QMetaType::Double: {
512 double v =
arg.value.toDouble();
513 value = CFNumberCreate(NULL, kCFNumberDoubleType, &
v);
516 case QMetaType::LongLong:
517 case QMetaType::ULongLong: {
519 value = CFNumberCreate(NULL, kCFNumberLongLongType, &
v);
526 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
527 QCFType<CFNumberFormatterRef> currencyFormatter =
528 CFNumberFormatterCreate(NULL, locale, kCFNumberFormatterCurrencyStyle);
529 if (!
arg.symbol.isEmpty()) {
530 CFNumberFormatterSetProperty(currencyFormatter, kCFNumberFormatterCurrencySymbol,
531 arg.symbol.toCFString());
533 QCFType<CFStringRef>
result = CFNumberFormatterCreateStringWithNumber(NULL, currencyFormatter,
value);
534 return QString::fromCFString(
result);
540 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
543 begin = QString::fromCFString(
static_cast<CFStringRef
>(CFLocaleGetValue(locale, kCFLocaleQuotationBeginDelimiterKey)));
544 end = QString::fromCFString(
static_cast<CFStringRef
>(CFLocaleGetValue(locale, kCFLocaleQuotationEndDelimiterKey)));
547 begin = QString::fromCFString(
static_cast<CFStringRef
>(CFLocaleGetValue(locale, kCFLocaleAlternateQuotationBeginDelimiterKey)));
548 end = QString::fromCFString(
static_cast<CFStringRef
>(CFLocaleGetValue(locale, kCFLocaleAlternateQuotationEndDelimiterKey)));
557#ifndef QT_NO_SYSTEMLOCALE
564template <auto CodeToValueFunction>
573 if (
auto value = CodeToValueFunction(code.toString()))
590 return getLocaleValue<codeToLanguage>(kCFLocaleLanguageCode);
592 return getLocaleValue<QLocalePrivate::codeToTerritory>(kCFLocaleCountryCode);
594 return getLocaleValue<QLocalePrivate::codeToScript>(kCFLocaleScriptCode);
602 ? kCFDateFormatterShortStyle
603 : kCFDateFormatterLongStyle);
607 ? kCFDateFormatterShortStyle
608 : kCFDateFormatterLongStyle);
641 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
642 QCFType<CFDateFormatterRef> formatter = CFDateFormatterCreate(NULL, locale, kCFDateFormatterLongStyle, kCFDateFormatterLongStyle);
643 QCFType<CFStringRef>
value =
static_cast<CFStringRef
>(CFDateFormatterCopyProperty(formatter,
644 (
type ==
AMText ? kCFDateFormatterAMSymbol : kCFDateFormatterPMSymbol)));
645 return QString::fromCFString(
value);
655 QCFType<CFArrayRef> languages = CFLocaleCopyPreferredLanguages();
656 const CFIndex cnt = CFArrayGetCount(languages);
658 for (CFIndex
i = 0;
i < cnt; ++
i) {
659 const QString lang = QString::fromCFString(
660 static_cast<CFStringRef
>(CFArrayGetValueAtIndex(languages,
i)));
\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
static QLocale system()
Returns a QLocale object initialized to the system locale.
\macro QT_RESTRICTED_CAST_FROM_ASCII
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 QLocale fallbackLocale() const
virtual QVariant query(QueryType type, QVariant &&in=QVariant()) 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]