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 <lars.knoll@nokia.com>
This commit is contained in:
Thiago Macieira 2012-04-23 16:39:13 +02:00 committed by Qt by Nokia
parent a637a5ae29
commit 592fe0a026
2 changed files with 51 additions and 16 deletions

View File

@ -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)

View File

@ -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)