📄 qlocale.cpp
字号:
QChar c = sys_fmt.at(i); int repeat = repeatCount(sys_fmt, i); switch (c.unicode()) { // Date case 'y': if (repeat > 5) repeat = 5; else if (repeat == 3) repeat = 2; switch (repeat) { case 1: result += QLatin1String("yy"); // "y" unsupported by Qt, use "yy" break; case 5: result += QLatin1String("yyyy"); // "yyyyy" same as "yyyy" on Windows break; default: result += QString(repeat, QLatin1Char('y')); break; } break; case 'g': if (repeat > 2) repeat = 2; switch (repeat) { case 2: break; // no equivalent of "gg" in Qt default: result += QLatin1Char('g'); break; } break; case 't': if (repeat > 2) repeat = 2; result += QLatin1String("AP"); // "t" unsupported, use "AP" break; default: result += QString(repeat, c); break; } i += repeat; } return result;}#endif // Q_OS_WIN/******************************************************************************** Wrappers for Mac locale system functions*/#ifdef Q_OS_MACstatic QString systemMonthName(int month, QLocale::FormatType format){ QStringList monthNames;#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { QCFType<CFDateFormatterRef> formatter = CFDateFormatterCreate(0, QCFType<CFLocaleRef>(CFLocaleCopyCurrent()), kCFDateFormatterNoStyle, kCFDateFormatterNoStyle); QCFType<CFArrayRef> values = static_cast<CFArrayRef>(CFDateFormatterCopyProperty(formatter, (format == QLocale::LongFormat) ? kCFDateFormatterMonthSymbols : kCFDateFormatterShortMonthSymbols)); if (values != 0) { CFStringRef cfstring = static_cast<CFStringRef>(CFArrayGetValueAtIndex(values, month)); return QCFString::toQString(cfstring); } }#endif return QString();}static QString systemDayName(int day, QLocale::FormatType format){ QStringList monthNames;#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { QCFType<CFDateFormatterRef> formatter = CFDateFormatterCreate(0, QCFType<CFLocaleRef>(CFLocaleCopyCurrent()), kCFDateFormatterNoStyle, kCFDateFormatterNoStyle); QCFType<CFArrayRef> values = static_cast<CFArrayRef>(CFDateFormatterCopyProperty(formatter, (format == QLocale::LongFormat) ? kCFDateFormatterWeekdaySymbols : kCFDateFormatterShortWeekdaySymbols)); if (values != 0) { CFStringRef cfstring = static_cast<CFStringRef>(CFArrayGetValueAtIndex(values, day)); return QCFString::toQString(cfstring); } }#endif return QString();}static QString systemDateToString(const QDate &date, QLocale::FormatType format){#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_3) { CFGregorianDate macGDate; macGDate.year = date.year(); macGDate.month = date.month(); macGDate.day = date.day(); macGDate.hour = 0; macGDate.minute = 0; macGDate.second = 0.0; QCFType<CFDateRef> myDate = CFDateCreate(0, CFGregorianDateGetAbsoluteTime(macGDate, QCFType<CFTimeZoneRef>(CFTimeZoneCopyDefault()))); QCFType<CFLocaleRef> mylocale = CFLocaleCopyCurrent(); CFDateFormatterStyle style = (format == QLocale::LongFormat) ? kCFDateFormatterLongStyle : kCFDateFormatterShortStyle; QCFType<CFDateFormatterRef> myFormatter = CFDateFormatterCreate(kCFAllocatorDefault, mylocale, style, kCFDateFormatterNoStyle); return QCFString(CFDateFormatterCreateStringWithDate(0, myFormatter, myDate)); }#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 return QString();}static QString systemTimeToString(const QTime &time, QLocale::FormatType format){# if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_3) { CFGregorianDate macGDate; // Assume this is local time and the current date QDate dt = QDate::currentDate(); macGDate.year = dt.year(); macGDate.month = dt.month(); macGDate.day = dt.day(); macGDate.hour = time.hour(); macGDate.minute = time.minute(); macGDate.second = time.second(); QCFType<CFDateRef> myDate = CFDateCreate(0, CFGregorianDateGetAbsoluteTime(macGDate, QCFType<CFTimeZoneRef>(CFTimeZoneCopyDefault()))); QCFType<CFLocaleRef> mylocale = CFLocaleCopyCurrent(); CFDateFormatterStyle style = (format == QLocale::LongFormat) ? kCFDateFormatterMediumStyle : kCFDateFormatterShortStyle; QCFType<CFDateFormatterRef> myFormatter = CFDateFormatterCreate(kCFAllocatorDefault, mylocale, kCFDateFormatterNoStyle, style); return QCFString(CFDateFormatterCreateStringWithDate(0, myFormatter, myDate)); }#endif return QString();}static QString systemDateFormat(QLocale::FormatType format){#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_3) { QCFType<CFLocaleRef> l = CFLocaleCopyCurrent(); CFDateFormatterStyle f = kCFDateFormatterLongStyle; if (format == QLocale::ShortFormat) f = kCFDateFormatterShortStyle; QCFType<CFDateFormatterRef> formatter = CFDateFormatterCreate(kCFAllocatorDefault, l, f, kCFDateFormatterNoStyle); return QCFString::toQString(CFDateFormatterGetFormat(formatter)); }#endif return QString();}static QString systemTimeFormat(QLocale::FormatType format){#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_3) { QCFType<CFLocaleRef> l = CFLocaleCopyCurrent(); CFDateFormatterStyle f = kCFDateFormatterLongStyle; if(format == QLocale::ShortFormat) f = kCFDateFormatterShortStyle; QCFType<CFDateFormatterRef> formatter = CFDateFormatterCreate(kCFAllocatorDefault, l, kCFDateFormatterNoStyle, f); return QCFString::toQString(CFDateFormatterGetFormat(formatter)); }#endif return QString();}#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3)static QString getCFLocaleValue(CFLocaleRef locale, CFStringRef key){ CFTypeRef value = CFLocaleGetValue(locale, key); return QCFString::toQString(CFStringRef(static_cast<CFTypeRef>(value)));}static const QLocalePrivate *systemLocale(){ if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_3) return 0; static QLocalePrivate *result = 0; if (result == 0) { const QLocalePrivate *plain = findLocale(QLocalePrivate::systemLocaleName()); QLocalePrivate *custom = new QLocalePrivate(*plain); if (!q_atomic_test_and_set_ptr(&result, 0, custom)) delete custom; } QCFType<CFLocaleRef> cflocale = CFLocaleCopyCurrent(); QString str = getCFLocaleValue(cflocale, kCFLocaleDecimalSeparator); if (!str.isEmpty()) result->m_decimal = str.at(0).unicode(); str = getCFLocaleValue(cflocale, kCFLocaleGroupingSeparator); if (!str.isEmpty()) result->m_group = str.at(0).unicode(); return result;}#endifstatic QString toQtFormat(const QString &sys_fmt){ QString result; int i = 0; while (i < sys_fmt.size()) { if (sys_fmt.at(i).unicode() == '\'') { QString text = readEscapedFormatString(sys_fmt, &i); if (text == QLatin1String("'")) result += QLatin1String("''"); else result += QChar('\'') + text + QChar('\''); continue; } QChar c = sys_fmt.at(i); int repeat = repeatCount(sys_fmt, i); switch (c.unicode()) { case 'G': // Qt doesn't support these :( case 'Y': case 'D': case 'F': case 'w': case 'W': case 'g': case 'A': break; case 'u': // extended year - use 'y' if (repeat < 4) result += QLatin1String("yy"); else result += QLatin1String("yyyy"); break; case 'S': // fractional second if (repeat < 3) result += QLatin1String("z"); else result += QLatin1String("zzz"); break; case 'E': if (repeat <= 3) result += QLatin1String("ddd"); else result += QLatin1String("dddd"); break; case 'e': if (repeat >= 2) result += QLatin1String("dd"); else result += QLatin1String("d"); break; case 'a': result += QLatin1String("AP"); break; case 'k': result += QString(repeat, QLatin1Char('H')); break; case 'K': result += QString(repeat, QLatin1Char('h')); break; case 'z': case 'Z': case 'v': result += QLatin1Char('t'); break; default: result += QString(repeat, c); break; } i += repeat; } return result;}#endif // Q_OS_MACconst QLocalePrivate *QLocale::default_d = 0;QString QLocalePrivate::infinity() const{ return QString::fromLatin1("inf");}QString QLocalePrivate::nan() const{ return QString::fromLatin1("nan");}QString QLocalePrivate::month(int index, bool short_format) const{ if (index < 0 || index >= 12) return QString();#ifndef QT_USE_DATABASE if (this == systemLocale()) { QString str = systemMonthName(index, short_format ? QLocale::ShortFormat : QLocale::LongFormat); if (!str.isEmpty()) return str; }#endif quint32 idx = short_format ? m_short_month_names_idx : m_long_month_names_idx; QStringList month_names = QString::fromUtf8(months_data + idx).split(QLatin1Char(';')); return month_names.at(index);}QString QLocalePrivate::day(int index, bool short_format) const{ if (index < 1 || index > 7) return QString(); if (index == 7) index = 0;#ifndef QT_USE_DATABASE if (this == systemLocale()) { QString str = systemDayName(index, short_format ? QLocale::ShortFormat : QLocale::LongFormat); if (!str.isEmpty()) return str; }#endif quint32 idx = short_format ? m_short_day_names_idx : m_long_day_names_idx; QStringList day_names = QString::fromUtf8(days_data + idx).split(QLatin1Char(';')); return day_names.at(index);}#ifndef QT_NO_DATASTREAMQDataStream &operator<<(QDataStream &ds, const QLocale &l){ ds << l.name(); return ds;}QDataStream &operator>>(QDataStream &ds, QLocale &l){ QString s; ds >> s; l = QLocale(s); return ds;}#endif#if defined(Q_OS_WIN)/* Win95 doesn't have a function to return the ISO lang/country name of the user's locale. Instead it can return a "Windows code". This maps windows codes to ISO country names. */struct WindowsToISOListElt { int windows_code; char iso_name[6];};static const WindowsToISOListElt windows_to_iso_list[] = { { 0x0401, "ar_SA" }, { 0x0402, "bg\0 " }, { 0x0403, "ca\0 " }, { 0x0404, "zh_TW" }, { 0x0405, "cs\0 " }, { 0x0406, "da\0 " }, { 0x0407, "de\0 " }, { 0x0408, "el\0 " }, { 0x0409, "en_US" }, { 0x040a, "es\0 " }, { 0x040b, "fi\0 " }, { 0x040c, "fr\0 " }, { 0x040d, "he\0 " }, { 0x040e, "hu\0 " }, { 0x040f, "is\0 " }, { 0x0410, "it\0 " }, { 0x0411, "ja\0 " }, { 0x0412, "ko\0 " }, { 0x0413, "nl\0 " }, { 0x0414, "no\0 " }, { 0x0415, "pl\0 " }, { 0x0416, "pt_BR" }, { 0x0418, "ro\0 " }, { 0x0419, "ru\0 " }, { 0x041a, "hr\0 " }, { 0x041c, "sq\0 " }, { 0x041d, "sv\0 " }, { 0x041e, "th\0 " }, { 0x041f, "tr\0 " }, { 0x0420, "ur\0 " }, { 0x0421, "in\0 " }, { 0x0422, "uk\0 " }, { 0x0423, "be\0 " }, { 0x0425, "et\0 " }, { 0x0426, "lv\0 " }, { 0x0427, "lt\0 " }, { 0x0429, "fa\0 " }, { 0x042a, "vi\0 " }, { 0x042d, "eu\0 " }, { 0x042f, "mk\0 " }, { 0x0436, "af\0 " }, { 0x0438, "fo\0 " }, { 0x0439, "hi\0 " }, { 0x043e, "ms\0 " }, { 0x0458, "mt\0 " }, { 0x0801, "ar_IQ" }, { 0x0804, "zh_CN" }, { 0x0807, "de_CH" }, { 0x0809, "en_GB" }, { 0x080a, "es_MX" }, { 0x080c, "fr_BE" }, { 0x0810, "it_CH" }, { 0x0812, "ko\0 " }, { 0x0813, "nl_BE" }, { 0x0814, "no\0 " }, { 0x0816, "pt\0 " }, { 0x081a, "sr\0 " }, { 0x081d, "sv_FI" }, { 0x0c01, "ar_EG" }, { 0x0c04, "zh_HK" }, { 0x0c07, "de_AT" }, { 0x0c09, "en_AU" }, { 0x0c0a, "es\0 " }, { 0x0c0c, "fr_CA" }, { 0x0c1a, "sr\0 " }, { 0x1001, "ar_LY" }, { 0x1004, "zh_SG" }, { 0x1007, "de_LU" }, { 0x1009, "en_CA" }, { 0x100a, "es_GT" }, { 0x100c, "fr_CH" }, { 0x1401, "ar_DZ" }, { 0x1407, "de_LI" }, { 0x1409, "en_NZ" }, { 0x140a, "es_CR" }, { 0x140c, "fr_LU" }, { 0x1801, "ar_MA" }, { 0x1809, "en_IE" }, { 0x180a, "es_PA" }, { 0x1c01, "ar_TN" }, { 0x1c09, "en_ZA" }, { 0x1c0a, "es_DO" }, { 0x2001, "ar_OM" }, { 0x2009, "en_JM" }, { 0x200a, "es_VE" }, { 0x2401, "ar_YE" }, { 0x2409, "en\0 " }, { 0x240a, "es_CO" }, { 0x2801, "ar_SY" }, { 0x2809, "en_BZ" },
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -