From 592fe0a02609503670cc9238d1a4ad29e4e65185 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 23 Apr 2012 16:39:13 +0200 Subject: Change QString's default codec to be UTF-8 This is a crude change, not the most efficient way. I'll clean up and make it prettier later on, when I've had the chance to optimise the UTF-8 codec too. Change-Id: I78e30e8d3bddf6ad0210c9c4cedb9a7ce63d1a7d Reviewed-by: Lars Knoll --- src/corelib/tools/qstring.h | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'src/corelib/tools/qstring.h') diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index bf2928346c..1ddaded7b3 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -80,6 +80,12 @@ template class QVector; typedef QTypedArrayData QStringData; +Q_CORE_EXPORT bool qStringComparisonHelper(const QString &s1, const char *s2); +Q_CORE_EXPORT bool qStringComparisonHelper(const QString &s1, const QByteArray &s2); +Q_CORE_EXPORT bool qStringComparisonHelper(const QStringRef &s1, const char *s2); +Q_CORE_EXPORT bool qStringComparisonHelper(const QStringRef &s1, const QByteArray &s2); + + #if defined(Q_COMPILER_UNICODE_STRINGS) #define QT_UNICODE_LITERAL_II(str) u"" str @@ -441,8 +447,7 @@ public: // note - this are all inline so we can benefit from strlen() compile time optimizations static inline QString fromAscii(const char *str, int size = -1) { - QStringDataPtr dataPtr = { fromAscii_helper(str, (str && size == -1) ? int(strlen(str)) : size) }; - return QString(dataPtr); + return fromUtf8(str, size); } static inline QString fromLatin1(const char *str, int size = -1) { @@ -669,8 +674,10 @@ private: friend class QTextCodec; friend class QStringRef; friend struct QAbstractConcatenable; - friend inline bool qStringComparisonHelper(const QString &s1, const char *s2); - friend inline bool qStringComparisonHelper(const QStringRef &s1, const char *s2); + friend bool qStringComparisonHelper(const QString &s1, const char *s2); + friend bool qStringComparisonHelper(const QString &s1, const QByteArray &s2); + friend bool qStringComparisonHelper(const QStringRef &s1, const char *s2); + friend bool qStringComparisonHelper(const QStringRef &s1, const QByteArray &s2); public: typedef Data * DataPtr; inline DataPtr &data_ptr() { return d; } @@ -734,7 +741,6 @@ private: // Qt 4.x compatibility typedef QLatin1String QLatin1Literal; - inline QString::QString(const QLatin1String &aLatin1) : d(fromLatin1_helper(aLatin1.latin1(), aLatin1.size())) { } inline int QString::length() const @@ -980,10 +986,6 @@ inline bool operator!=(QString::Null, const QString &s) { return !s.isNull(); } 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) -{ - return (s1 == QLatin1String(s2)); -} inline bool QString::operator==(const char *s) const { return qStringComparisonHelper(*this, s); } inline bool QString::operator!=(const char *s) const @@ -1265,11 +1267,6 @@ inline bool operator<=(const QStringRef &s1, const QStringRef &s2) inline bool operator>=(const QStringRef &s1, const QStringRef &s2) { return !(s1 < s2); } -inline bool qStringComparisonHelper(const QStringRef &s1, const char *s2) -{ - return (s1 == QLatin1String(s2)); -} - inline QT_ASCII_CAST_WARN bool operator==(const char *s1, const QStringRef &s2) { return qStringComparisonHelper(s2, s1); } inline QT_ASCII_CAST_WARN bool operator==(const QStringRef &s1, const char *s2) -- cgit v1.2.3