⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qlocale.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                }                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;}static QString winDateToString(const QDate &date, DWORD flags){    SYSTEMTIME st;    memset(&st, 0, sizeof(SYSTEMTIME));    st.wYear = date.year();    st.wMonth = date.month();    st.wDay = date.day();    LCID id = GetThreadLocale();    QT_WA({        TCHAR buf[255];        if (GetDateFormatW(id, flags, &st, 0, buf, 255))            return QString::fromUtf16((ushort*)buf);    } , {        char buf[255];        if (GetDateFormatA(id, flags, &st, 0, (char*)&buf, 255))            return QString::fromLocal8Bit(buf);    });    return QString();}static QString winTimeToString(const QTime &time){    SYSTEMTIME st;    memset(&st, 0, sizeof(SYSTEMTIME));    st.wHour = time.hour();    st.wMinute = time.minute();    st.wSecond = time.second();    st.wMilliseconds = 0;    DWORD flags = 0;    LCID id = GetThreadLocale();    QT_WA({        TCHAR buf[255];        if (GetTimeFormatW(id, flags, &st, 0, buf, 255))            return QString::fromUtf16((ushort*)buf);    } , {        char buf[255];        if (GetTimeFormatA(id, flags, &st, 0, (char*)&buf, 255))            return QString::fromLocal8Bit(buf);    });    return QString();}static QString winDayName(int day, bool short_format){    static const LCTYPE short_day_map[]        = { LOCALE_SABBREVDAYNAME1, LOCALE_SABBREVDAYNAME2,            LOCALE_SABBREVDAYNAME3, LOCALE_SABBREVDAYNAME4, LOCALE_SABBREVDAYNAME5,            LOCALE_SABBREVDAYNAME6, LOCALE_SABBREVDAYNAME7 };    static const LCTYPE long_day_map[]        = { LOCALE_SDAYNAME1, LOCALE_SDAYNAME2,            LOCALE_SDAYNAME3, LOCALE_SDAYNAME4, LOCALE_SDAYNAME5,            LOCALE_SDAYNAME6, LOCALE_SDAYNAME7 };    day -= 1;    LCTYPE type = short_format                    ? short_day_map[day] : long_day_map[day];    return getWinLocaleInfo(type);}static QString winMonthName(int month, bool short_format){    static const LCTYPE short_month_map[]        = { LOCALE_SABBREVMONTHNAME1, LOCALE_SABBREVMONTHNAME2, LOCALE_SABBREVMONTHNAME3,            LOCALE_SABBREVMONTHNAME4, LOCALE_SABBREVMONTHNAME5, LOCALE_SABBREVMONTHNAME6,            LOCALE_SABBREVMONTHNAME7, LOCALE_SABBREVMONTHNAME8, LOCALE_SABBREVMONTHNAME9,            LOCALE_SABBREVMONTHNAME10, LOCALE_SABBREVMONTHNAME11, LOCALE_SABBREVMONTHNAME12 };    static const LCTYPE long_month_map[]        = { LOCALE_SMONTHNAME1, LOCALE_SMONTHNAME2, LOCALE_SMONTHNAME3,            LOCALE_SMONTHNAME4, LOCALE_SMONTHNAME5, LOCALE_SMONTHNAME6,            LOCALE_SMONTHNAME7, LOCALE_SMONTHNAME8, LOCALE_SMONTHNAME9,            LOCALE_SMONTHNAME10, LOCALE_SMONTHNAME11, LOCALE_SMONTHNAME12 };    month -= 1;    if (month < 0 || month > 11)    return QString();    LCTYPE type = short_format ? short_month_map[month] : long_month_map[month];    return getWinLocaleInfo(type);}QLocale QSystemLocale::fallbackLocale() const{    return QLocale(QString::fromLatin1(getWinLocaleName()));}QVariant QSystemLocale::query(QueryType type, QVariant in = QVariant()) const{    LCTYPE locale_info = 0;    bool format_string = false;    switch(type) {//     case Name://         return getWinLocaleName();    case DecimalPoint:        locale_info = LOCALE_SDECIMAL;                break;    case GroupSeparator:        locale_info = LOCALE_STHOUSAND;                break;    case NegativeSign:        locale_info = LOCALE_SNEGATIVESIGN;                break;    case DateFormatLong:        locale_info = LOCALE_SLONGDATE;        format_string = true;                break;    case DateFormatShort:        locale_info = LOCALE_SSHORTDATE;        format_string = true;                break;    case TimeFormatLong:    case TimeFormatShort:        locale_info = LOCALE_STIMEFORMAT;        format_string = true;                break;    case DayNameLong:    case DayNameShort:        return winDayName(in.toInt(), (type == DayNameShort));    case MonthNameLong:    case MonthNameShort:        return winMonthName(in.toInt(), (type == MonthNameShort));    case DateToStringShort:    case DateToStringLong:        return winDateToString(in.toDate(), type == DateToStringShort ? DATE_SHORTDATE : DATE_LONGDATE);    case TimeToStringShort:    case TimeToStringLong:        return winTimeToString(in.toTime());    case ZeroDigit:        locale_info = LOCALE_SNATIVEDIGITS;        break;    case LanguageId:    case CountryId: {        QString locale = QString::fromLatin1(getWinLocaleName());        QLocale::Language lang;        QLocale::Country cntry;        getLangAndCountry(locale, lang, cntry);        if (type == LanguageId)            return lang;        return cntry;    }    default:        break;    }    if (locale_info) {        QString result = getWinLocaleInfo(locale_info);        if (format_string)            result = winToQtFormat(result);        if (!result.isEmpty())            return result;    }    return QVariant();}/* 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" },    { 0x280a, "es_PE" },    { 0x2c01, "ar_JO" },    { 0x2c09, "en_TT" },    { 0x2c0a, "es_AR" },    { 0x3001, "ar_LB" },    { 0x300a, "es_EC" },    { 0x3401, "ar_KW" },    { 0x340a, "es_CL" },    { 0x3801, "ar_AE" },    { 0x380a, "es_UY" },    { 0x3c01, "ar_BH" },    { 0x3c0a, "es_PY" },    { 0x4001, "ar_QA" },    { 0x400a, "es_BO" },    { 0x440a, "es_SV" },    { 0x480a, "es_HN" },    { 0x4c0a, "es_NI" },    { 0x500a, "es_PR" }};static const int windows_to_iso_count    = sizeof(windows_to_iso_list)/sizeof(WindowsToISOListElt);static const char *winLangCodeToIsoName(int code){    int cmp = code - windows_to_iso_list[0].windows_code;    if (cmp < 0)        return 0;    if (cmp == 0)        return windows_to_iso_list[0].iso_name;    int begin = 0;    int end = windows_to_iso_count;    while (end - begin > 1) {        uint mid = (begin + end)/2;        const WindowsToISOListElt *elt = windows_to_iso_list + mid;        int cmp = code - elt->windows_code;        if (cmp < 0)            end = mid;        else if (cmp > 0)            begin = mid;        else            return elt->iso_name;    }    return 0;}static QString winIso639LangName(LCID id){    QString result;    // Windows returns the wrong ISO639 for some languages, we need to detect them here using    // the language code    QString lang_code;    QT_WA({        TCHAR out[256];        if (GetLocaleInfoW(id, LOCALE_ILANGUAGE, out, 255))            lang_code = QString::fromUtf16((ushort*)out);    } , {        char out[256];        if (GetLocaleInfoA(id, LOCALE_ILANGUAGE, out, 255))            lang_code = QString::fromLocal8Bit(out);    });    if (!lang_code.isEmpty()) {        const char *endptr;        bool ok;        QByteArray latin1_lang_code = lang_code.toLatin1();        int i = qstrtoull(latin1_lang_code, &endptr, 16, &ok);        if (ok && *endptr == '\0') {            switch (i) {                case 0x814:                    result = QLatin1String("nn"); // Nynorsk                    break;                default:                    break;            }        }    }    if (!result.isEmpty())        return result;    // not one of the problematic languages - do the usual lookup    QT_WA({        TCHAR out[256];        if (GetLocaleInfoW(id, LOCALE_SISO639LANGNAME , out, 255))            result = QString::fromUtf16((ushort*)out);    } , {        char out[256];        if (GetLocaleInfoA(id, LOCALE_SISO639LANGNAME, out, 255))            result = QString::fromLocal8Bit(out);    });    return result;}static QString winIso3116CtryName(LCID id){    QString result;    QT_WA({        TCHAR out[256];        if (GetLocaleInfoW(id, LOCALE_SISO3166CTRYNAME, out, 255))            result = QString::fromUtf16((ushort*)out);    } , {        char out[256];        if (GetLocaleInfoA(id, LOCALE_SISO3166CTRYNAME, out, 255))            result = QString::fromLocal8Bit(out);    });    return result;}#elif defined(Q_OS_MAC)/******************************************************************************** Wrappers for Mac locale system functions*/static QByteArray getMacLocaleName(){    QByteArray result = envVarLocale();    if (result.isEmpty()) {        QCFType<CFLocaleRef> l = CFLocaleCopyCurrent();        CFStringRef locale = CFLocaleGetIdentifier(l);        result = QCFString::toQString(locale).toUtf8();    }    return result;}static QString macMonthName(int month, bool short_format){    month -= 1;    if (month < 0 || month > 11)        return QString();#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,                                      short_format ? kCFDateFormatterShortMonthSymbols                                                   : kCFDateFormatterMonthSymbols));        if (values != 0) {            CFStringRef cfstring = static_cast<CFStringRef>(CFArrayGetValueAtIndex(values, month));            return QCFString::toQString(cfstring);        }    }#endif    return QString();}static QString macDayName(int day, bool short_format){    if (day < 1 || day > 7)        return QString();#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,                                                short_format ? kCFDateFormatterShortWeekdaySymbols                                                             : kCFDateFormatterWeekdaySymbols));        if (values != 0) {            CFStringRef cfstring = static_cast<CFStringRef>(CFArrayGetValueAtIndex(values, day % 7));            return QCFString::toQString(cfstring);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -