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

📄 qchar.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
}/*!    Returns the uppercase equivalent if the character is lowercase or titlecase;    otherwise returns the character itself.*/QChar QChar::toUpper() const{    const QUnicodeTables::Properties *p = qGetProp(ucs);    if (!p->upperCaseSpecial)        return ucs + p->upperCaseDiff;    return ucs;}/*! \overloadReturns the uppercase equivalent of the UCS-4-encoded character specifiedby \a ucs4 if the character is lowercase or titlecase; otherwise returnsthe character itself. */uint QChar::toUpper(uint ucs4){    if (ucs4 > LAST_UNICODE_CHAR)        return ucs4;    const QUnicodeTables::Properties *p = qGetProp(ucs4);    if (!p->upperCaseSpecial)        return ucs4 + p->upperCaseDiff;    return ucs4;}/*! \overloadReturns the uppercase equivalent of the UCS-2-encoded character specifiedby \a ucs2 if the character is lowercase or titlecase; otherwise returnsthe character itself. */ushort QChar::toUpper(ushort ucs2){    const QUnicodeTables::Properties *p = qGetProp(ucs2);    if (!p->upperCaseSpecial)        return ucs2 + p->upperCaseDiff;    return ucs2;}/*!    Returns the title case equivalent if the character is lowercase or uppercase;    otherwise returns the character itself.*/QChar QChar::toTitleCase() const{    const QUnicodeTables::Properties *p = qGetProp(ucs);    if (!p->titleCaseSpecial)        return ucs + p->titleCaseDiff;    return ucs;}/*!    \overload    Returns the title case equivalent of the UCS-4-encoded character specified    by \a ucs4 if the character is lowercase or uppercase; otherwise returns    the character itself.*/uint QChar::toTitleCase(uint ucs4){    if (ucs4 > LAST_UNICODE_CHAR)        return ucs4;    const QUnicodeTables::Properties *p = qGetProp(ucs4);    if (!p->titleCaseSpecial)        return ucs4 + p->titleCaseDiff;    return ucs4;}/*!    \overload    Returns the title case equivalent of the UCS-2-encoded character specified    by \a ucs2 if the character is lowercase or uppercase; otherwise returns    the character itself.*/ushort QChar::toTitleCase(ushort ucs2){    const QUnicodeTables::Properties *p = qGetProp(ucs2);    if (!p->titleCaseSpecial)        return ucs2 + p->titleCaseDiff;    return ucs2;}static inline uint foldCase(const ushort *ch, const ushort *start){    uint c = *ch;    if (QChar(c).isLowSurrogate() && ch > start && QChar(*(ch - 1)).isHighSurrogate())        c = QChar::surrogateToUcs4(*(ch - 1), c);    return *ch + qGetProp(c)->caseFoldDiff;}static inline uint foldCase(uint ch, uint &last){    uint c = ch;    if (QChar(c).isLowSurrogate() && QChar(last).isHighSurrogate())        c = QChar::surrogateToUcs4(last, c);    last = ch;    return ch + qGetProp(c)->caseFoldDiff;}static inline ushort foldCase(ushort ch){    return ch + qGetProp(ch)->caseFoldDiff;}/*!    Returns the case folded equivalent of the character. For most Unicode characters this    is the same as toLowerCase().*/QChar QChar::toCaseFolded() const{    return ucs + qGetProp(ucs)->caseFoldDiff;}/*!    \overload    Returns the case folded equivalent of the UCS-4-encoded character specified    by \a ucs4. For most Unicode characters this is the same as toLowerCase().*/uint QChar::toCaseFolded(uint ucs4){    if (ucs4 > LAST_UNICODE_CHAR)        return ucs4;    return ucs4 + qGetProp(ucs4)->caseFoldDiff;}/*!    \overload    Returns the case folded equivalent of the UCS-2-encoded character specified    by \a ucs2. For most Unicode characters this is the same as toLowerCase().*/ushort QChar::toCaseFolded(ushort ucs2){    return ucs2 + qGetProp(ucs2)->caseFoldDiff;}/*!    \fn char QChar::latin1() const    Use toLatin1() instead.*//*!    \fn char QChar::ascii() const    Use toAscii() instead.*//*!    \fn char QChar::toLatin1() const    Returns the Latin-1 character equivalent to the QChar, or 0. This    is mainly useful for non-internationalized software.    \sa toAscii(), unicode(), QTextCodec::codecForCStrings()*//*!    Returns the character value of the QChar obtained using the current    codec used to read C strings, or 0 if the character is not representable    using this codec. The default codec handles Latin-1 encoded text,    but this can be changed to assist developers writing source code using    other encodings.    The main purpose of this function is to preserve ASCII characters used    in C strings. This is mainly useful for developers of non-internationalized    software.    \sa toLatin1(), unicode(), QTextCodec::codecForCStrings()*/const char QChar::toAscii() const{#ifndef QT_NO_CODEC_FOR_C_STRINGS    if (QTextCodec::codecForCStrings())        // #####        return QTextCodec::codecForCStrings()->fromUnicode(QString(*this)).at(0);#endif    return ucs > 0xff ? 0 : char(ucs);}/*!    \fn QChar QChar::fromLatin1(char c)    Converts the Latin-1 character \a c to its equivalent QChar. This    is mainly useful for non-internationalized software.    \sa fromAscii(), unicode(), QTextCodec::codecForCStrings()*//*!    Converts the ASCII character \a c to its equivalent QChar. This    is mainly useful for non-internationalized software.    An alternative is to use QLatin1Char.    \sa fromLatin1(), unicode(), QTextCodec::codecForCStrings()*/QChar QChar::fromAscii(char c){#ifndef QT_NO_CODEC_FOR_C_STRINGS    if (QTextCodec::codecForCStrings())        // #####        return QTextCodec::codecForCStrings()->toUnicode(&c, 1).at(0).unicode();#endif    return QChar(ushort((uchar)c));}#ifndef QT_NO_DATASTREAM/*!  \relates QChar  Writes the char \a chr to the stream \a out.  \sa {Format of the QDataStream operators} */QDataStream &operator<<(QDataStream &out, const QChar &chr){    out << quint16(chr.unicode());    return out;}/*!  \relates QChar  Reads a char from the stream \a in into char \a chr.  \sa {Format of the QDataStream operators} */QDataStream &operator>>(QDataStream &in, QChar &chr){    quint16 u;    in >> u;    chr.unicode() = ushort(u);    return in;}#endif/*!    \fn ushort & QChar::unicode()    Returns a reference to the numeric Unicode value of the QChar.*//*!    \fn ushort QChar::unicode() const    \overload*//*****************************************************************************  Documentation of QChar related functions *****************************************************************************//*!    \fn bool operator==(QChar c1, QChar c2)    \relates QChar    Returns true if \a c1 and \a c2 are the same Unicode character;    otherwise returns false.*//*!    \fn int operator!=(QChar c1, QChar c2)    \relates QChar    Returns true if \a c1 and \a c2 are not the same Unicode    character; otherwise returns false.*//*!    \fn int operator<=(QChar c1, QChar c2)    \relates QChar    Returns true if the numeric Unicode value of \a c1 is less than    or equal to that of \a c2; otherwise returns false.*//*!    \fn int operator>=(QChar c1, QChar c2)    \relates QChar    Returns true if the numeric Unicode value of \a c1 is greater than    or equal to that of \a c2; otherwise returns false.*//*!    \fn int operator<(QChar c1, QChar c2)    \relates QChar    Returns true if the numeric Unicode value of \a c1 is less than    that of \a c2; otherwise returns false.*//*!    \fn int operator>(QChar c1, QChar c2)    \relates QChar    Returns true if the numeric Unicode value of \a c1 is greater than    that of \a c2; otherwise returns false.*//*!    \fn bool QChar::mirrored() const    Use hasMirrored() instead.*//*!    \fn QChar QChar::lower() const    Use toLower() instead.*//*!    \fn QChar QChar::upper() const    Use toUpper() instead.*//*!    \fn bool QChar::networkOrdered()    See if QSysInfo::ByteOrder == QSysInfo::BigEndian instead.*/// ---------------------------------------------------------------------------static QString decompose(const QString &str, bool canonical, QChar::UnicodeVersion version){    unsigned short buffer[3];    QString s = str;    const unsigned short *utf16 = s.utf16();    const unsigned short *uc = utf16 + s.length();    while (uc != utf16) {        uint ucs4 = *(--uc);        if (QChar(ucs4).isLowSurrogate() && uc != utf16) {            ushort high = *(uc - 1);            if (QChar(high).isHighSurrogate()) {                --uc;                ucs4 = QChar::surrogateToUcs4(high, ucs4);            }        }        if (QChar::unicodeVersion(ucs4) > version)            continue;        int length;        int tag;        const unsigned short *d = decomposition(ucs4, &length, &tag, buffer);        if (!d || (canonical && tag != QChar::Canonical))            continue;        s.replace(uc - utf16, ucs4 > 0x10000 ? 2 : 1, (const QChar *)d, length);        // since the insert invalidates the pointers and we do decomposition recursive        int pos = uc - utf16;        utf16 = s.utf16();        uc = utf16 + pos + length;    }    return s;}static ushort ligature(ushort u1, ushort u2){    // hangul L-V pair    int LIndex = u1 - Hangul_LBase;    if (0 <= LIndex && LIndex < Hangul_LCount) {        int VIndex = u2 - Hangul_VBase;        if (0 <= VIndex && VIndex < Hangul_VCount)            return Hangul_SBase + (LIndex * Hangul_VCount + VIndex) * Hangul_TCount;    }    // hangul LV-T pair    int SIndex = u1 - Hangul_SBase;    if (0 <= SIndex && SIndex < Hangul_SCount && (SIndex % Hangul_TCount) == 0) {        int TIndex = u2 - Hangul_TBase;        if (0 <= TIndex && TIndex <= Hangul_TCount)            return u1 + TIndex;    }    const unsigned short index = GET_LIGATURE_INDEX(u2);    if (index == 0xffff)        return 0;    const unsigned short *ligatures = uc_ligature_map+index;    ushort length = *ligatures;    ++ligatures;    // ### use bsearch    for (uint i = 0; i < length; ++i)        if (ligatures[2*i] == u1)            return ligatures[2*i+1];    return 0;}static QString compose(const QString &str){    QString s = str;    if (s.length() < 2)        return s;    // the loop can partly ignore high Unicode as all ligatures are in the BMP    int starter = 0;    int lastCombining = 0;    int pos = 0;    while (pos < s.length()) {        uint uc = s.utf16()[pos];        if (QChar(uc).isHighSurrogate() && pos < s.length()-1) {            ushort low = s.utf16()[pos+1];            if (QChar(low).isLowSurrogate()) {                uc = QChar::surrogateToUcs4(uc, low);                ++pos;            }        }        int combining = QChar::combiningClass(uc);        if (starter == pos - 1 || combining > lastCombining) {            // allowed to form ligature with S            QChar ligature = ::ligature(s.utf16()[starter], uc);            if (ligature.unicode()) {                s[starter] = ligature;                s.remove(pos, 1);                continue;            }        }        if (!combining)            starter = pos;        lastCombining = combining;        ++pos;    }    return s;}static QString canonicalOrder(const QString &str, QChar::UnicodeVersion version){    QString s = str;    const int l = s.length()-1;    int pos = 0;    while (pos < l) {        int p2 = pos+1;        uint u1 = s.at(pos).unicode();        if (QChar(u1).isHighSurrogate()) {            ushort low = s.at(pos+1).unicode();            if (QChar(low).isLowSurrogate()) {                p2++;                u1 = QChar::surrogateToUcs4(u1, low);                if (p2 >= l)                    break;            }        }        uint u2 = s.at(p2).unicode();        if (QChar(u2).isHighSurrogate() && p2 < l-1) {            ushort low = s.at(p2+1).unicode();            if (QChar(low).isLowSurrogate()) {                p2++;                u2 = QChar::surrogateToUcs4(u2, low);            }        }        int c2 = QChar::combiningClass(u2);        if (QChar::unicodeVersion(u2) > version)            c2 = 0;        if (c2 == 0) {            pos = p2+1;            continue;        }        int c1 = QChar::combiningClass(u1);        if (QChar::unicodeVersion(u1) > version)            c1 = 0;        if (c1 > c2) {            QChar *uc = s.data();            int p = pos;            // exchange characters            if (u2 < 0x10000) {                uc[p++] = u2;            } else {                uc[p++] = QChar::highSurrogate(u2);                uc[p++] = QChar::lowSurrogate(u2);            }            if (u1 < 0x10000) {                uc[p++] = u1;            } else {                uc[p++] = QChar::highSurrogate(u1);                uc[p++] = QChar::lowSurrogate(u1);            }            if (pos > 0)                --pos;            if (pos > 0 && s.at(pos).isLowSurrogate())                --pos;        } else {            ++pos;            if (u1 > 0x10000)                ++pos;        }    }    return s;}int QUnicodeTables::script(unsigned int uc){    if (uc > 0xffff)        return Common;    int script = uc_scripts[uc >> 7];    if (script < ScriptSentinel)        return script;    script = (((script - ScriptSentinel) * UnicodeBlockSize) + UnicodeBlockCount);    script = uc_scripts[script + (uc & 0x7f)];    return script;}Q_CORE_EXPORT QUnicodeTables::LineBreakClass QUnicodeTables::lineBreakClass(uint ucs4){    return (QUnicodeTables::LineBreakClass) qGetProp(ucs4)->line_break_class;}

⌨️ 快捷键说明

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