diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2012-04-12 18:21:39 +0300 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-13 10:44:28 +0200 |
commit | 9fd2edb6da5f1f6d644cd7c3f35aebe3e88beee2 (patch) | |
tree | d644aeef68584469ec1b9b6cdbc3d86cc7ddf86b /src/corelib | |
parent | b317fe2a606e5b79f24b1e4a1b808f5ff66d3621 (diff) |
replace hardcoded values with a surrogate handling methods
Change-Id: Ib41e08d835f2e8ca2e32b4025c6f5a99840f2e27
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/codecs/qutfcodec.cpp | 6 | ||||
-rw-r--r-- | src/corelib/io/qurl.cpp | 6 | ||||
-rw-r--r-- | src/corelib/json/qjsonparser.cpp | 7 | ||||
-rw-r--r-- | src/corelib/json/qjsonwriter.cpp | 2 |
4 files changed, 11 insertions, 10 deletions
diff --git a/src/corelib/codecs/qutfcodec.cpp b/src/corelib/codecs/qutfcodec.cpp index 18d063a38c..9111ac6379 100644 --- a/src/corelib/codecs/qutfcodec.cpp +++ b/src/corelib/codecs/qutfcodec.cpp @@ -127,7 +127,7 @@ QByteArray QUtf8::convertFromUnicode(const QChar *uc, int len, QTextCodec::Conve continue; } - if (u > 0xffff) { + if (QChar::requiresSurrogates(u)) { *cursor++ = 0xf0 | ((uchar) (u >> 18)); *cursor++ = 0x80 | (((uchar) (u >> 12)) & 0x3f); } else { @@ -196,7 +196,7 @@ QString QUtf8::convertToUnicode(const char *chars, int len, QTextCodec::Converte bool nonCharacter; if (!headerdone && uc == 0xfeff) { // don't do anything, just skip the BOM - } else if (!(nonCharacter = isUnicodeNonCharacter(uc)) && uc > 0xffff && uc < 0x110000) { + } else if (!(nonCharacter = isUnicodeNonCharacter(uc)) && QChar::requiresSurrogates(uc) && uc < 0x110000) { // surrogate pair Q_ASSERT((qch - (ushort*)result.unicode()) + 2 < result.length()); *qch++ = QChar::highSurrogate(uc); @@ -487,7 +487,7 @@ QString QUtf32::convertToUnicode(const char *chars, int len, QTextCodec::Convert } } uint code = (endian == BigEndianness) ? qFromBigEndian<quint32>(tuple) : qFromLittleEndian<quint32>(tuple); - if (code >= 0x10000) { + if (QChar::requiresSurrogates(code)) { *qch++ = QChar::highSurrogate(code); *qch++ = QChar::lowSurrogate(code); } else { diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 0659053937..c6b5ea63eb 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -2388,7 +2388,7 @@ static void mapToLowerCase(QString *str, int from) while (l < 4 && entry->mapping[l]) ++l; if (l > 1) { - if (uc <= 0xffff) + if (!QChar::requiresSurrogates(uc)) str->replace(i, 1, reinterpret_cast<const QChar *>(&entry->mapping[0]), l); else str->replace(i-1, 2, reinterpret_cast<const QChar *>(&entry->mapping[0]), l); @@ -2434,7 +2434,7 @@ static void stripProhibitedOutput(QString *str, int from) uc = QChar::surrogateToUcs4(uc, low); } } - if (uc <= 0xFFFF) { + if (!QChar::requiresSurrogates(uc)) { if (uc < 0x80 || !(uc <= 0x009F || uc == 0x00A0 @@ -2991,7 +2991,7 @@ void qt_nameprep(QString *source, int from) } } if (!isMappedToNothing(uc)) { - if (uc <= 0xFFFF) { + if (!QChar::requiresSurrogates(uc)) { *out++ = *in; } else { *out++ = QChar::highSurrogate(uc); diff --git a/src/corelib/json/qjsonparser.cpp b/src/corelib/json/qjsonparser.cpp index 7d25c81db2..a17426580f 100644 --- a/src/corelib/json/qjsonparser.cpp +++ b/src/corelib/json/qjsonparser.cpp @@ -769,9 +769,10 @@ static inline bool scanUtf8Char(const char *&json, const char *end, uint *result uc = (uc << 6) | (ch & 0x3f); } - if (isUnicodeNonCharacter(uc) || uc >= 0x110000 || - (uc < min_uc) || (uc >= 0xd800 && uc <= 0xdfff)) + if (uc < min_uc || isUnicodeNonCharacter(uc) || + (uc >= 0xd800 && uc <= 0xdfff) || uc >= 0x110000) { return false; + } *result = uc; return true; @@ -850,7 +851,7 @@ bool Parser::parseString(bool *latin1) return false; } } - if (ch > 0xffff) { + if (QChar::requiresSurrogates(ch)) { int pos = reserveSpace(4); *(QJsonPrivate::qle_ushort *)(data + pos) = QChar::highSurrogate(ch); *(QJsonPrivate::qle_ushort *)(data + pos + 2) = QChar::lowSurrogate(ch); diff --git a/src/corelib/json/qjsonwriter.cpp b/src/corelib/json/qjsonwriter.cpp index d392bd7529..7cdc3f0dba 100644 --- a/src/corelib/json/qjsonwriter.cpp +++ b/src/corelib/json/qjsonwriter.cpp @@ -160,7 +160,7 @@ static QByteArray escapedString(const QString &s) continue; } - if (u > 0xffff) { + if (QChar::requiresSurrogates(u)) { *cursor++ = 0xf0 | ((uchar) (u >> 18)); *cursor++ = 0x80 | (((uchar) (u >> 12)) & 0x3f); } else { |