summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qstring.cpp42
-rw-r--r--src/corelib/tools/qstring.h25
2 files changed, 51 insertions, 16 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index fd0d1286f6..69650f50ef 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -369,6 +369,42 @@ inline char qToLower(char ch)
return ch;
}
+/*!
+ \internal
+*/
+bool qStringComparisonHelper(const QString &s1, const char *s2)
+{
+ // ### optimize me
+ return s1 == QString::fromAscii(s2);
+}
+
+/*!
+ \internal
+*/
+bool qStringComparisonHelper(const QString &s1, const QByteArray &s2)
+{
+ // ### optimize me
+ return s1 == QString::fromAscii(s2);
+}
+
+/*!
+ \internal
+*/
+bool qStringComparisonHelper(const QStringRef &s1, const char *s2)
+{
+ // ### optimize me
+ return s1 == QString::fromAscii(s2);
+}
+
+/*!
+ \internal
+*/
+bool qStringComparisonHelper(const QStringRef &s1, const QByteArray &s2)
+{
+ // ### optimize me
+ return s1 == QString::fromAscii(s2);
+}
+
const QString::Null QString::null = { };
/*!
@@ -3935,7 +3971,7 @@ QByteArray QString::toLatin1() const
*/
QByteArray QString::toAscii() const
{
- return toLatin1();
+ return toUtf8();
}
#if !defined(Q_OS_MAC) && defined(Q_OS_UNIX)
@@ -4064,7 +4100,9 @@ QString::Data *QString::fromLatin1_helper(const char *str, int size)
QString::Data *QString::fromAscii_helper(const char *str, int size)
{
- return fromLatin1_helper(str, size);
+ QString s = fromUtf8(str, size);
+ s.d->ref.ref();
+ return s.d;
}
/*! \fn QString QString::fromLatin1(const char *str, int size)
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 <typename T> class QVector;
typedef QTypedArrayData<ushort> 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)