diff options
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qchar.cpp | 63 | ||||
-rw-r--r-- | src/corelib/tools/qchar.h | 13 | ||||
-rw-r--r-- | src/corelib/tools/qcryptographichash.cpp | 106 | ||||
-rw-r--r-- | src/corelib/tools/qcryptographichash.h | 6 | ||||
-rw-r--r-- | src/corelib/tools/qeasingcurve.cpp | 1 | ||||
-rw-r--r-- | src/corelib/tools/qlist.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qlocale.qdoc | 4 | ||||
-rw-r--r-- | src/corelib/tools/qlocale_win.cpp | 2 | ||||
-rw-r--r-- | src/corelib/tools/qregexp.cpp | 2 | ||||
-rw-r--r-- | src/corelib/tools/qstring.cpp | 76 | ||||
-rw-r--r-- | src/corelib/tools/qstring.h | 13 | ||||
-rw-r--r-- | src/corelib/tools/qstringbuilder.cpp | 29 | ||||
-rw-r--r-- | src/corelib/tools/qstringbuilder.h | 44 |
13 files changed, 154 insertions, 207 deletions
diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp index 01241dce6b..0261843a3a 100644 --- a/src/corelib/tools/qchar.cpp +++ b/src/corelib/tools/qchar.cpp @@ -413,33 +413,16 @@ QT_BEGIN_NAMESPACE */ /*! + \fn QChar::QChar(char ch) + Constructs a QChar corresponding to ASCII/Latin-1 character \a ch. */ -QChar::QChar(char ch) -{ -#ifndef QT_NO_CODEC_FOR_C_STRINGS - if (QTextCodec::codecForCStrings()) - // ##### - ucs = QTextCodec::codecForCStrings()->toUnicode(&ch, 1).at(0).unicode(); - else -#endif - ucs = uchar(ch); -} /*! + \fn QChar::QChar(uchar ch) + Constructs a QChar corresponding to ASCII/Latin-1 character \a ch. */ -QChar::QChar(uchar ch) -{ -#ifndef QT_NO_CODEC_FOR_C_STRINGS - if (QTextCodec::codecForCStrings()) { - // ##### - char c = char(ch); - ucs = QTextCodec::codecForCStrings()->toUnicode(&c, 1).at(0).unicode(); - } else -#endif - ucs = ch; -} /*! \fn QChar::QChar(uchar cell, uchar row) @@ -1256,49 +1239,35 @@ ushort QChar::toCaseFolded(ushort ucs2) Returns the Latin-1 character equivalent to the QChar, or 0. This is mainly useful for non-internationalized software. - \sa toAscii(), unicode(), QTextCodec::codecForCStrings() + \sa toAscii(), unicode() */ /*! - 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. + \fn char QChar::toAscii() const + + Returns the Latin-1 character value of the QChar, or 0 if the character is not + representable. 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() + \note It is not possible to distinguish a non-Latin 1 character from an ASCII 0 + (NUL) character. Prefer to use unicode(), which does not have this ambiguity. + + \sa toLatin1(), unicode() */ -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::fromAscii(char) + Converts the ASCII character \a c to it's equivalent QChar. This is mainly useful for non-internationalized software. An alternative is to use QLatin1Char. - \sa fromLatin1(), unicode(), QTextCodec::codecForCStrings() + \sa fromLatin1(), unicode() */ -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 /*! diff --git a/src/corelib/tools/qchar.h b/src/corelib/tools/qchar.h index df3d7eac33..3209ffb0f2 100644 --- a/src/corelib/tools/qchar.h +++ b/src/corelib/tools/qchar.h @@ -86,9 +86,8 @@ public: Q_DECL_CONSTEXPR QChar(QLatin1Char ch) : ucs(ch.unicode()) {} // implicit #ifndef QT_NO_CAST_FROM_ASCII - // these two constructors are NOT inline const_expr! - QT_ASCII_CAST_WARN_CONSTRUCTOR explicit QChar(char c); - QT_ASCII_CAST_WARN_CONSTRUCTOR explicit QChar(uchar c); + QT_ASCII_CAST_WARN Q_DECL_CONSTEXPR explicit QChar(char c) : ucs(uchar(c)) { } + QT_ASCII_CAST_WARN Q_DECL_CONSTEXPR explicit QChar(uchar c) : ucs(c) { } #endif // Unicode information @@ -222,13 +221,13 @@ public: UnicodeVersion unicodeVersion() const; - char toAscii() const; + inline char toAscii() const; inline char toLatin1() const; inline ushort unicode() const { return ucs; } inline ushort &unicode() { return ucs; } - static QChar fromAscii(char c); - static QChar fromLatin1(char c); + static inline QChar fromAscii(char c); + static inline QChar fromLatin1(char c); inline bool isNull() const { return ucs == 0; } bool isPrint() const; @@ -344,8 +343,10 @@ private: Q_DECLARE_TYPEINFO(QChar, Q_MOVABLE_TYPE); +inline char QChar::toAscii() const { return ucs > 0xff ? 0 : char(ucs); } inline char QChar::toLatin1() const { return ucs > 0xff ? '\0' : char(ucs); } inline QChar QChar::fromLatin1(char c) { return QChar(ushort(uchar(c))); } +inline QChar QChar::fromAscii(char c) { return QChar(ushort(uchar(c))); } inline void QChar::setCell(uchar acell) { ucs = ushort((ucs & 0xff00) + acell); } diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index 164660f818..31a0fdc5e6 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -46,8 +46,53 @@ #include "../../3rdparty/md4/md4.h" #include "../../3rdparty/md4/md4.cpp" #include "../../3rdparty/sha1/sha1.cpp" + +/* + These typedefs are needed by the RFC6234 code. Normally they would come + from from stdint.h, but since this header is not available on all platforms + (MSVC 2008, for example), we need to define them ourselves. +*/ +typedef QT_PREPEND_NAMESPACE(quint64) uint64_t; +typedef QT_PREPEND_NAMESPACE(quint32) uint32_t; +typedef QT_PREPEND_NAMESPACE(quint8) uint8_t; +typedef QT_PREPEND_NAMESPACE(qint16) int_least16_t; +// Header from rfc6234 with 1 modification: +// sha1.h - commented out '#include <stdint.h>' on line 74 +#include "../../3rdparty/rfc6234/sha.h" + +/* + These 2 functions replace macros of the same name in sha224-256.c and + sha384-512.c. Originally, these macros relied on a global static 'addTemp' + variable. We do not want this for 2 reasons: + + 1. since we are including the sources directly, the declaration of the 2 conflict + + 2. static variables are not thread-safe, we do not want multiple threads + computing a hash to corrupt one another +*/ +static int SHA224_256AddLength(SHA256Context *context, unsigned int length); +static int SHA384_512AddLength(SHA512Context *context, unsigned int length); + +// Sources from rfc6234, with 4 modifications: +// sha224-256.c - commented out 'static uint32_t addTemp;' on line 68 +// sha224-256.c - appended 'M' to the SHA224_256AddLength macro on line 70 +#include "../../3rdparty/rfc6234/sha224-256.c" +// sha384-512.c - commented out 'static uint64_t addTemp;' on line 302 +// sha384-512.c - appended 'M' to the SHA224_256AddLength macro on line 304 +#include "../../3rdparty/rfc6234/sha384-512.c" + #include <qiodevice.h> +static inline int SHA224_256AddLength(SHA256Context *context, unsigned int length) +{ + uint32_t addTemp; + return SHA224_256AddLengthM(context, length); +} +static inline int SHA384_512AddLength(SHA512Context *context, unsigned int length) +{ + uint64_t addTemp; + return SHA384_512AddLengthM(context, length); +} QT_BEGIN_NAMESPACE @@ -59,6 +104,10 @@ public: MD5Context md5Context; md4_context md4Context; Sha1State sha1Context; + SHA224Context sha224Context; + SHA256Context sha256Context; + SHA384Context sha384Context; + SHA512Context sha512Context; }; QByteArray result; }; @@ -75,7 +124,7 @@ public: QCryptographicHash can be used to generate cryptographic hashes of binary or text data. - Currently MD4, MD5, and SHA-1 are supported. + Currently MD4, MD5, SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512 are supported. */ /*! @@ -83,7 +132,11 @@ public: \value Md4 Generate an MD4 hash sum \value Md5 Generate an MD5 hash sum - \value Sha1 Generate an SHA1 hash sum + \value Sha1 Generate an SHA-1 hash sum + \value Sha224 Generate an SHA-224 hash sum + \value Sha256 Generate an SHA-256 hash sum + \value Sha384 Generate an SHA-384 hash sum + \value Sha512 Generate an SHA-512 hash sum */ /*! @@ -119,6 +172,18 @@ void QCryptographicHash::reset() case Sha1: sha1InitState(&d->sha1Context); break; + case Sha224: + SHA224Reset(&d->sha224Context); + break; + case Sha256: + SHA256Reset(&d->sha256Context); + break; + case Sha384: + SHA384Reset(&d->sha384Context); + break; + case Sha512: + SHA512Reset(&d->sha512Context); + break; } d->result.clear(); } @@ -139,6 +204,18 @@ void QCryptographicHash::addData(const char *data, int length) case Sha1: sha1Update(&d->sha1Context, (const unsigned char *)data, length); break; + case Sha224: + SHA224Input(&d->sha224Context, reinterpret_cast<const unsigned char *>(data), length); + break; + case Sha256: + SHA256Input(&d->sha256Context, reinterpret_cast<const unsigned char *>(data), length); + break; + case Sha384: + SHA384Input(&d->sha384Context, reinterpret_cast<const unsigned char *>(data), length); + break; + case Sha512: + SHA512Input(&d->sha512Context, reinterpret_cast<const unsigned char *>(data), length); + break; } d->result.clear(); } @@ -201,6 +278,31 @@ QByteArray QCryptographicHash::result() const d->result.resize(20); sha1FinalizeState(©); sha1ToHash(©, (unsigned char *)d->result.data()); + break; + } + case Sha224: { + SHA224Context copy = d->sha224Context; + d->result.resize(SHA224HashSize); + SHA224Result(©, reinterpret_cast<unsigned char *>(d->result.data())); + break; + } + case Sha256:{ + SHA256Context copy = d->sha256Context; + d->result.resize(SHA256HashSize); + SHA256Result(©, reinterpret_cast<unsigned char *>(d->result.data())); + break; + } + case Sha384:{ + SHA384Context copy = d->sha384Context; + d->result.resize(SHA384HashSize); + SHA384Result(©, reinterpret_cast<unsigned char *>(d->result.data())); + break; + } + case Sha512:{ + SHA512Context copy = d->sha512Context; + d->result.resize(SHA512HashSize); + SHA512Result(©, reinterpret_cast<unsigned char *>(d->result.data())); + break; } } return d->result; diff --git a/src/corelib/tools/qcryptographichash.h b/src/corelib/tools/qcryptographichash.h index 59314e1963..2bfc03373a 100644 --- a/src/corelib/tools/qcryptographichash.h +++ b/src/corelib/tools/qcryptographichash.h @@ -58,7 +58,11 @@ public: enum Algorithm { Md4, Md5, - Sha1 + Sha1, + Sha224, + Sha256, + Sha384, + Sha512 }; QCryptographicHash(Algorithm method); diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp index 1ca9a55d72..81778f908f 100644 --- a/src/corelib/tools/qeasingcurve.cpp +++ b/src/corelib/tools/qeasingcurve.cpp @@ -1110,6 +1110,7 @@ QEasingCurve::~QEasingCurve() Swaps curve \a other with this curve. This operation is very fast and never fails. +*/ /*! Compare this easing curve with \a other and returns true if they are diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 8f36e5c2ae..bf6933732c 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -402,7 +402,7 @@ Q_INLINE_TEMPLATE void QList<T>::node_copy(Node *from, Node *to, Node *src) } } else { if (src != from && to - from > 0) - memcpy(from, src, (to - from) * sizeof(Node *)); + memcpy(from, src, (to - from) * sizeof(Node)); } } diff --git a/src/corelib/tools/qlocale.qdoc b/src/corelib/tools/qlocale.qdoc index 2fff58333d..3a386c17d6 100644 --- a/src/corelib/tools/qlocale.qdoc +++ b/src/corelib/tools/qlocale.qdoc @@ -89,7 +89,7 @@ pair; it does not use the system locale database. \note For the current keyboard input locale take a look at - QInputPanel::locale(). + QInputMethod::locale(). QLocale's data is based on Common Locale Data Repository v1.8.1. @@ -114,7 +114,7 @@ California, Berkeley and its contributors. \sa QString::arg(), QString::toInt(), QString::toDouble(), - QInputPanel::locale() + QInputMethod::locale() */ /*! diff --git a/src/corelib/tools/qlocale_win.cpp b/src/corelib/tools/qlocale_win.cpp index cd9fffc7a5..e787f2fa2a 100644 --- a/src/corelib/tools/qlocale_win.cpp +++ b/src/corelib/tools/qlocale_win.cpp @@ -525,7 +525,7 @@ QVariant QSystemLocalePrivate::toCurrencyString(const QSystemLocale::CurrencyToS QVariant QSystemLocalePrivate::uiLanguages() { if (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA) { - typedef BOOL (*GetUserPreferredUILanguagesFunc) ( + typedef BOOL (WINAPI *GetUserPreferredUILanguagesFunc) ( DWORD dwFlags, PULONG pulNumLanguages, PWSTR pwszLanguagesBuffer, diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp index e8c0d4eccc..d7bcd0edbc 100644 --- a/src/corelib/tools/qregexp.cpp +++ b/src/corelib/tools/qregexp.cpp @@ -3934,6 +3934,7 @@ static void invalidateEngine(QRegExpPrivate *priv) QRegExp::QRegExp() { priv = new QRegExpPrivate; + prepareEngine(priv); } /*! @@ -3949,6 +3950,7 @@ QRegExp::QRegExp() QRegExp::QRegExp(const QString &pattern, Qt::CaseSensitivity cs, PatternSyntax syntax) { priv = new QRegExpPrivate(QRegExpEngineKey(pattern, syntax, cs)); + prepareEngine(priv); } /*! diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index d0c5506228..e73c52980f 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -96,10 +96,6 @@ QT_BEGIN_NAMESPACE -#ifndef QT_NO_TEXTCODEC -QTextCodec *QString::codecForCStrings; -#endif - #ifdef QT_USE_ICU // qlocale_icu.cpp extern bool qt_ucol_strcoll(const QChar *source, int sourceLength, const QChar *target, int targetLength, int *result); @@ -471,9 +467,8 @@ const QString::Null QString::null = { }; \snippet doc/src/snippets/qstring/main.cpp 0 QString converts the \c{const char *} data into Unicode using the - fromAscii() function. By default, fromAscii() treats character - above 128 as Latin-1 characters, but this can be changed by - calling QTextCodec::setCodecForCStrings(). + fromAscii() function. fromAscii() treats ordinals above 128 as Latin-1 + characters. In all of the QString functions that take \c{const char *} parameters, the \c{const char *} is interpreted as a classic @@ -611,9 +606,7 @@ const QString::Null QString::null = { }; toLatin1(), toUtf8(), and toLocal8Bit(). \list - \o toAscii() returns an 8-bit string encoded using the codec - specified by QTextCodec::codecForCStrings (by default, that is - Latin 1). + \o toAscii() returns a Latin-1 (ISO 8859-1) encoded 8-bit string. \o toLatin1() returns a Latin-1 (ISO 8859-1) encoded 8-bit string. \o toUtf8() returns a UTF-8 encoded 8-bit string. UTF-8 is a superset of US-ASCII (ANSI X3.4-1986) that supports the entire @@ -721,11 +714,11 @@ const QString::Null QString::null = { }; \section1 More Efficient String Construction Many strings are known at compile time. But the trivial - constructor QString("Hello"), will convert the string literal - to a QString using the codecForCStrings(). To avoid this one - can use the QStringLiteral macro to directly create the required - data at compile time. Constructing a QString out of the literal - does then not cause any overhead at runtime. + constructor QString("Hello"), will copy the contents of the string, + treating the contents as Latin-1. To avoid this one can use the + QStringLiteral macro to directly create the required data at compile + time. Constructing a QString out of the literal does then not cause + any overhead at runtime. A slightly less efficient way is to use QLatin1String. This class wraps a C string literal, precalculates it length at compile time and can @@ -3658,9 +3651,7 @@ QByteArray QString::toLatin1() const /*! Returns an 8-bit representation of the string as a QByteArray. - If a codec has been set using QTextCodec::setCodecForCStrings(), - it is used to convert Unicode to 8-bit char; otherwise this - function does the same as toLatin1(). + This function does the same as toLatin1(). Note that, despite the name, this function does not necessarily return an US-ASCII (ANSI X3.4-1986) string and its result may not be US-ASCII compatible. @@ -3669,10 +3660,6 @@ QByteArray QString::toLatin1() const */ QByteArray QString::toAscii() const { -#ifndef QT_NO_TEXTCODEC - if (codecForCStrings) - return codecForCStrings->fromUnicode(*this); -#endif // QT_NO_TEXTCODEC return toLatin1(); } @@ -3806,23 +3793,6 @@ QString::Data *QString::fromLatin1_helper(const char *str, int size) QString::Data *QString::fromAscii_helper(const char *str, int size) { -#ifndef QT_NO_TEXTCODEC - if (codecForCStrings) { - Data *d; - if (!str) { - d = const_cast<Data *>(&shared_null.str); - } else if (size == 0 || (!*str && size < 0)) { - d = const_cast<Data *>(&shared_empty.str); - } else { - if (size < 0) - size = qstrlen(str); - QString s = codecForCStrings->toUnicode(str, size); - d = s.d; - d->ref.ref(); - } - return d; - } -#endif return fromLatin1_helper(str, size); } @@ -3871,11 +3841,7 @@ QString QString::fromLocal8Bit_helper(const char *str, int size) If \a size is -1 (default), it is taken to be strlen(\a str). - Note that, despite the name, this function actually uses the codec - defined by QTextCodec::setCodecForCStrings() to convert \a str to - Unicode. Depending on the codec, it may not accept valid US-ASCII (ANSI - X3.4-1986) input. If no codec has been set, this function does the same - as fromLatin1(). + This function does the same as fromLatin1(). \sa toAscii(), fromLatin1(), fromUtf8(), fromLocal8Bit() */ @@ -5144,19 +5110,8 @@ QString &QString::vsprintf(const char* cformat, va_list ap) const char *c = cformat; for (;;) { // Copy non-escape chars to result -#ifndef QT_NO_TEXTCODEC - int i = 0; - while (*(c + i) != '\0' && *(c + i) != '%') - ++i; - if (codecForCStrings) - result.append(codecForCStrings->toUnicode(c, i)); - else - result.append(fromLatin1(c, i)); - c += i; -#else while (*c != '\0' && *c != '%') result.append(QLatin1Char(*c++)); -#endif if (*c == '\0') break; @@ -7068,8 +7023,7 @@ bool QString::isRightToLeft() const This operator is mostly useful to pass a QString to a function that accepts a std::string object. - If the QString contains Unicode characters that the - QTextCodec::codecForCStrings() codec cannot handle, using this operator + If the QString contains non-Latin1 Unicode characters, using this can lead to loss of information. This operator is only available if Qt is configured with STL @@ -8742,9 +8696,7 @@ QByteArray QStringRef::toLatin1() const Returns an 8-bit representation of the string as a QByteArray. - If a codec has been set using QTextCodec::setCodecForCStrings(), - it is used to convert Unicode to 8-bit char; otherwise this - function does the same as toLatin1(). + This function does the same as toLatin1(). Note that, despite the name, this function does not necessarily return an US-ASCII (ANSI X3.4-1986) string and its result may not be US-ASCII compatible. @@ -8753,10 +8705,6 @@ QByteArray QStringRef::toLatin1() const */ QByteArray QStringRef::toAscii() const { -#ifndef QT_NO_TEXTCODEC - if (QString::codecForCStrings) - return QString::codecForCStrings->fromUnicode(unicode(), length()); -#endif // QT_NO_TEXTCODEC return toLatin1(); } diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index bdadba8bd4..6fc86fc04b 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -502,10 +502,10 @@ public: // ASCII compatibility #ifndef QT_NO_CAST_FROM_ASCII - inline QT_ASCII_CAST_WARN_CONSTRUCTOR QString(const char *ch) + inline QT_ASCII_CAST_WARN QString(const char *ch) : d(fromAscii_helper(ch, ch ? int(strlen(ch)) : -1)) {} - inline QT_ASCII_CAST_WARN_CONSTRUCTOR QString(const QByteArray &a) + inline QT_ASCII_CAST_WARN QString(const QByteArray &a) : d(fromAscii_helper(a.constData(), qstrnlen(a.constData(), a.size()))) {} inline QT_ASCII_CAST_WARN QString &operator=(const char *ch) @@ -609,9 +609,6 @@ private: Data *d; inline QString(Data *dd, int /*dummy*/) : d(dd) {} -#ifndef QT_NO_TEXTCODEC - static QTextCodec *codecForCStrings; -#endif static int grow(int); static void free(Data *); void realloc(); @@ -931,9 +928,6 @@ inline bool operator!=(const QString &s, QString::Null) { return !s.isNull(); } #ifndef QT_NO_CAST_FROM_ASCII inline bool qStringComparisonHelper(const QString &s1, const char *s2) { -# ifndef QT_NO_TEXTCODEC - if (QString::codecForCStrings) return (s1 == QString::fromAscii(s2, s2 ? int(strlen(s2)) : -1)); -# endif return (s1 == QLatin1String(s2)); } inline bool QString::operator==(const char *s) const @@ -1220,9 +1214,6 @@ inline bool operator>=(const QStringRef &s1, const QStringRef &s2) inline bool qStringComparisonHelper(const QStringRef &s1, const char *s2) { -# ifndef QT_NO_TEXTCODEC - if (QString::codecForCStrings) return (s1 == QString::fromAscii(s2, s2 ? int(strlen(s2)) : -1)); -# endif return (s1 == QLatin1String(s2)); } diff --git a/src/corelib/tools/qstringbuilder.cpp b/src/corelib/tools/qstringbuilder.cpp index 3d6b0eb709..6999972172 100644 --- a/src/corelib/tools/qstringbuilder.cpp +++ b/src/corelib/tools/qstringbuilder.cpp @@ -105,14 +105,6 @@ QT_BEGIN_NAMESPACE */ void QAbstractConcatenable::convertFromAscii(const char *a, int len, QChar *&out) { -#ifndef QT_NO_TEXTCODEC - if (QString::codecForCStrings && len) { - QString tmp = QString::fromAscii(a, len > 0 ? len : -1); - memcpy(out, reinterpret_cast<const char *>(tmp.constData()), sizeof(QChar) * tmp.size()); - out += tmp.length(); - return; - } -#endif if (len == -1) { if (!a) return; @@ -124,25 +116,4 @@ void QAbstractConcatenable::convertFromAscii(const char *a, int len, QChar *&out } } -/*! \internal */ -void QAbstractConcatenable::convertToAscii(const QChar* a, int len, char*& out) -{ -#ifndef QT_NO_TEXTCODEC - if (QString::codecForCStrings) { - QByteArray tmp = QString::codecForCStrings->fromUnicode(a, len); - memcpy(out, tmp.constData(), tmp.size()); - out += tmp.length(); - return; - } -#endif - if (len == -1) { - while (a->unicode()) - convertToLatin1(*a++, out); - } else { - for (int i = 0; i < len; ++i) - convertToLatin1(a[i], out); - } -} - - QT_END_NAMESPACE diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/tools/qstringbuilder.h index 5a4c27d22a..4c963185ad 100644 --- a/src/corelib/tools/qstringbuilder.h +++ b/src/corelib/tools/qstringbuilder.h @@ -62,30 +62,9 @@ struct Q_CORE_EXPORT QAbstractConcatenable { protected: static void convertFromAscii(const char *a, int len, QChar *&out); - static void convertToAscii(const QChar *a, int len, char *&out); static inline void convertFromAscii(char a, QChar *&out) { -#ifndef QT_NO_TEXTCODEC - if (QString::codecForCStrings) - *out++ = QChar::fromAscii(a); - else -#endif - *out++ = QLatin1Char(a); - } - - static inline void convertToAscii(QChar a, char *&out) - { -#ifndef QT_NO_TEXTCODEC - if (QString::codecForCStrings) - *out++ = a.toAscii(); //### - else -#endif - convertToLatin1(a, out); - } - - static inline void convertToLatin1(QChar a, char *&out) - { - *out++ = a.unicode() > 0xff ? '?' : char(a.unicode()); + *out++ = QLatin1Char(a); } }; @@ -192,10 +171,6 @@ template <> struct QConcatenable<QChar> : private QAbstractConcatenable static int size(const QChar) { return 1; } static inline void appendTo(const QChar c, QChar *&out) { *out++ = c; } -#ifndef QT_NO_CAST_TO_ASCII - static inline QT_ASCII_CAST_WARN void appendTo(const QChar c, char *&out) - { convertToAscii(c, out); } -#endif }; template <> struct QConcatenable<QCharRef> : private QAbstractConcatenable @@ -206,10 +181,6 @@ template <> struct QConcatenable<QCharRef> : private QAbstractConcatenable static int size(const QCharRef &) { return 1; } static inline void appendTo(const QCharRef &c, QChar *&out) { *out++ = QChar(c); } -#ifndef QT_NO_CAST_TO_ASCII - static inline QT_ASCII_CAST_WARN void appendTo(const QCharRef &c, char *&out) - { convertToAscii(c, out); } -#endif }; template <> struct QConcatenable<QLatin1String> @@ -242,10 +213,6 @@ template <> struct QConcatenable<QString> : private QAbstractConcatenable memcpy(out, reinterpret_cast<const char*>(a.constData()), sizeof(QChar) * n); out += n; } -#ifndef QT_NO_CAST_TO_ASCII - static inline QT_ASCII_CAST_WARN void appendTo(const QString &a, char *&out) - { convertToAscii(a.constData(), a.length(), out); } -#endif }; template <int N> struct QConcatenable<QConstStringDataPtr<N> > : private QAbstractConcatenable @@ -259,10 +226,6 @@ template <int N> struct QConcatenable<QConstStringDataPtr<N> > : private QAbstra memcpy(out, reinterpret_cast<const char*>(a.ptr->data), sizeof(QChar) * N); out += N; } -#ifndef QT_NO_CAST_TO_ASCII - static inline QT_ASCII_CAST_WARN void appendTo(const type &a, char *&out) - { convertToAscii(a.ptr->data, N, out); } -#endif }; template <> struct QConcatenable<QStringRef> : private QAbstractConcatenable @@ -277,11 +240,6 @@ template <> struct QConcatenable<QStringRef> : private QAbstractConcatenable memcpy(out, reinterpret_cast<const char*>(a.constData()), sizeof(QChar) * n); out += n; } -#ifndef QT_NO_CAST_TO_ASCII - static inline QT_ASCII_CAST_WARN void appendTo(const QStringRef &a, char *&out) - { convertToAscii(a.constData(), a.length(), out); } -#endif - }; template <int N> struct QConcatenable<char[N]> : private QAbstractConcatenable |