Change to/fromAscii to to/fromUtf8 in the QString conversions
This commit matches the previous documentation commit that says that the conversions are applied using to/fromUtf8. Change-Id: I304e4d866ddedac5094fef8500cbeba299a02cb5 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: hjk <qthjk@ovi.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
parent
3f9b508652
commit
b6e4c859d3
@ -330,7 +330,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
|
||||
*str = QLatin1String(d->data.b ? "true" : "false");
|
||||
break;
|
||||
case QVariant::ByteArray:
|
||||
*str = QString::fromAscii(v_cast<QByteArray>(d)->constData());
|
||||
*str = QString::fromUtf8(v_cast<QByteArray>(d)->constData());
|
||||
break;
|
||||
case QVariant::StringList:
|
||||
if (v_cast<QStringList>(d)->count() == 1)
|
||||
@ -484,7 +484,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
|
||||
QByteArray *ba = static_cast<QByteArray *>(result);
|
||||
switch (d->type) {
|
||||
case QVariant::String:
|
||||
*ba = v_cast<QString>(d)->toAscii();
|
||||
*ba = v_cast<QString>(d)->toUtf8();
|
||||
break;
|
||||
case QVariant::Double:
|
||||
*ba = QByteArray::number(d->data.d, 'g', DBL_DIG);
|
||||
@ -1178,7 +1178,7 @@ QVariant::QVariant(QDataStream &s)
|
||||
#ifndef QT_NO_CAST_FROM_ASCII
|
||||
QVariant::QVariant(const char *val)
|
||||
{
|
||||
QString s = QString::fromAscii(val);
|
||||
QString s = QString::fromUtf8(val);
|
||||
create(String, &s);
|
||||
}
|
||||
#endif
|
||||
|
@ -375,7 +375,7 @@ inline char qToLower(char ch)
|
||||
Q_CORE_EXPORT bool qStringComparisonHelper(const QString &s1, const char *s2)
|
||||
{
|
||||
// ### optimize me
|
||||
return s1 == QString::fromAscii(s2);
|
||||
return s1 == QString::fromUtf8(s2);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -384,7 +384,7 @@ Q_CORE_EXPORT bool qStringComparisonHelper(const QString &s1, const char *s2)
|
||||
Q_CORE_EXPORT bool qStringComparisonHelper(const QString &s1, const QByteArray &s2)
|
||||
{
|
||||
// ### optimize me
|
||||
return s1 == QString::fromAscii(s2);
|
||||
return s1 == QString::fromUtf8(s2);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -393,7 +393,7 @@ Q_CORE_EXPORT bool qStringComparisonHelper(const QString &s1, const QByteArray &
|
||||
Q_CORE_EXPORT bool qStringComparisonHelper(const QStringRef &s1, const char *s2)
|
||||
{
|
||||
// ### optimize me
|
||||
return s1 == QString::fromAscii(s2);
|
||||
return s1 == QString::fromUtf8(s2);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -402,7 +402,7 @@ Q_CORE_EXPORT bool qStringComparisonHelper(const QStringRef &s1, const char *s2)
|
||||
Q_CORE_EXPORT bool qStringComparisonHelper(const QStringRef &s1, const QByteArray &s2)
|
||||
{
|
||||
// ### optimize me
|
||||
return s1 == QString::fromAscii(s2);
|
||||
return s1 == QString::fromUtf8(s2);
|
||||
}
|
||||
|
||||
const QString::Null QString::null = { };
|
||||
|
@ -558,25 +558,25 @@ public:
|
||||
: d(fromAscii_helper(a.constData(), qstrnlen(a.constData(), a.size())))
|
||||
{}
|
||||
inline QT_ASCII_CAST_WARN QString &operator=(const char *ch)
|
||||
{ return (*this = fromAscii(ch, ch ? int(strlen(ch)) : -1)); }
|
||||
{ return (*this = fromUtf8(ch, ch ? int(strlen(ch)) : -1)); }
|
||||
inline QT_ASCII_CAST_WARN QString &operator=(const QByteArray &a)
|
||||
{ return (*this = fromAscii(a.constData(), qstrnlen(a.constData(), a.size()))); }
|
||||
{ return (*this = fromUtf8(a.constData(), qstrnlen(a.constData(), a.size()))); }
|
||||
inline QT_ASCII_CAST_WARN QString &operator=(char c)
|
||||
{ return (*this = QChar::fromAscii(c)); }
|
||||
|
||||
// these are needed, so it compiles with STL support enabled
|
||||
inline QT_ASCII_CAST_WARN QString &prepend(const char *s)
|
||||
{ return prepend(QString::fromAscii(s, s ? int(strlen(s)) : -1)); }
|
||||
{ return prepend(QString::fromUtf8(s, s ? int(strlen(s)) : -1)); }
|
||||
inline QT_ASCII_CAST_WARN QString &prepend(const QByteArray &s)
|
||||
{ return prepend(QString::fromAscii(s.constData(), qstrnlen(s.constData(), s.size()))); }
|
||||
{ return prepend(QString::fromUtf8(s.constData(), qstrnlen(s.constData(), s.size()))); }
|
||||
inline QT_ASCII_CAST_WARN QString &append(const char *s)
|
||||
{ return append(QString::fromAscii(s, s ? int(strlen(s)) : -1)); }
|
||||
{ return append(QString::fromUtf8(s, s ? int(strlen(s)) : -1)); }
|
||||
inline QT_ASCII_CAST_WARN QString &append(const QByteArray &s)
|
||||
{ return append(QString::fromAscii(s.constData(), qstrnlen(s.constData(), s.size()))); }
|
||||
{ return append(QString::fromUtf8(s.constData(), qstrnlen(s.constData(), s.size()))); }
|
||||
inline QT_ASCII_CAST_WARN QString &operator+=(const char *s)
|
||||
{ return append(QString::fromAscii(s, s ? int(strlen(s)) : -1)); }
|
||||
{ return append(QString::fromUtf8(s, s ? int(strlen(s)) : -1)); }
|
||||
inline QT_ASCII_CAST_WARN QString &operator+=(const QByteArray &s)
|
||||
{ return append(QString::fromAscii(s.constData(), qstrnlen(s.constData(), s.size()))); }
|
||||
{ return append(QString::fromUtf8(s.constData(), qstrnlen(s.constData(), s.size()))); }
|
||||
inline QT_ASCII_CAST_WARN QString &operator+=(char c)
|
||||
{ return append(QChar::fromAscii(c)); }
|
||||
|
||||
@ -590,13 +590,13 @@ public:
|
||||
inline QT_ASCII_CAST_WARN bool operator==(const QByteArray &s) const;
|
||||
inline QT_ASCII_CAST_WARN bool operator!=(const QByteArray &s) const;
|
||||
inline QT_ASCII_CAST_WARN bool operator<(const QByteArray &s) const
|
||||
{ return *this < QString::fromAscii(s); }
|
||||
{ return *this < QString::fromUtf8(s); }
|
||||
inline QT_ASCII_CAST_WARN bool operator>(const QByteArray &s) const
|
||||
{ return *this > QString::fromAscii(s); }
|
||||
{ return *this > QString::fromUtf8(s); }
|
||||
inline QT_ASCII_CAST_WARN bool operator<=(const QByteArray &s) const
|
||||
{ return *this <= QString::fromAscii(s); }
|
||||
{ return *this <= QString::fromUtf8(s); }
|
||||
inline QT_ASCII_CAST_WARN bool operator>=(const QByteArray &s) const
|
||||
{ return *this >= QString::fromAscii(s); }
|
||||
{ return *this >= QString::fromUtf8(s); }
|
||||
#endif
|
||||
|
||||
typedef QChar *iterator;
|
||||
@ -709,30 +709,30 @@ public:
|
||||
{ return s >= *this; }
|
||||
|
||||
inline QT_ASCII_CAST_WARN bool operator==(const char *s) const
|
||||
{ return QString::fromAscii(s) == *this; }
|
||||
{ return QString::fromUtf8(s) == *this; }
|
||||
inline QT_ASCII_CAST_WARN bool operator!=(const char *s) const
|
||||
{ return QString::fromAscii(s) != *this; }
|
||||
{ return QString::fromUtf8(s) != *this; }
|
||||
inline QT_ASCII_CAST_WARN bool operator<(const char *s) const
|
||||
{ return QString::fromAscii(s) > *this; }
|
||||
{ return QString::fromUtf8(s) > *this; }
|
||||
inline QT_ASCII_CAST_WARN bool operator>(const char *s) const
|
||||
{ return QString::fromAscii(s) < *this; }
|
||||
{ return QString::fromUtf8(s) < *this; }
|
||||
inline QT_ASCII_CAST_WARN bool operator<=(const char *s) const
|
||||
{ return QString::fromAscii(s) >= *this; }
|
||||
{ return QString::fromUtf8(s) >= *this; }
|
||||
inline QT_ASCII_CAST_WARN bool operator>=(const char *s) const
|
||||
{ return QString::fromAscii(s) <= *this; }
|
||||
{ return QString::fromUtf8(s) <= *this; }
|
||||
|
||||
inline QT_ASCII_CAST_WARN bool operator==(const QByteArray &s) const
|
||||
{ return QString::fromAscii(s) == *this; }
|
||||
{ return QString::fromUtf8(s) == *this; }
|
||||
inline QT_ASCII_CAST_WARN bool operator!=(const QByteArray &s) const
|
||||
{ return QString::fromAscii(s) != *this; }
|
||||
{ return QString::fromUtf8(s) != *this; }
|
||||
inline QT_ASCII_CAST_WARN bool operator<(const QByteArray &s) const
|
||||
{ return QString::fromAscii(s) > *this; }
|
||||
{ return QString::fromUtf8(s) > *this; }
|
||||
inline QT_ASCII_CAST_WARN bool operator>(const QByteArray &s) const
|
||||
{ return QString::fromAscii(s) < *this; }
|
||||
{ return QString::fromUtf8(s) < *this; }
|
||||
inline QT_ASCII_CAST_WARN bool operator<=(const QByteArray &s) const
|
||||
{ return QString::fromAscii(s) >= *this; }
|
||||
{ return QString::fromUtf8(s) >= *this; }
|
||||
inline QT_ASCII_CAST_WARN bool operator>=(const QByteArray &s) const
|
||||
{ return QString::fromAscii(s) <= *this; }
|
||||
{ return QString::fromUtf8(s) <= *this; }
|
||||
private:
|
||||
int m_size;
|
||||
const char *m_data;
|
||||
@ -991,39 +991,39 @@ inline bool QString::operator==(const char *s) const
|
||||
inline bool QString::operator!=(const char *s) const
|
||||
{ return !qStringComparisonHelper(*this, s); }
|
||||
inline bool QString::operator<(const char *s) const
|
||||
{ return *this < QString::fromAscii(s, s ? int(strlen(s)) : -1); }
|
||||
{ return *this < QString::fromUtf8(s, s ? int(strlen(s)) : -1); }
|
||||
inline bool QString::operator>(const char *s) const
|
||||
{ return *this > QString::fromAscii(s, s ? int(strlen(s)) : -1); }
|
||||
{ return *this > QString::fromUtf8(s, s ? int(strlen(s)) : -1); }
|
||||
inline bool QString::operator<=(const char *s) const
|
||||
{ return *this <= QString::fromAscii(s, s ? int(strlen(s)) : -1); }
|
||||
{ return *this <= QString::fromUtf8(s, s ? int(strlen(s)) : -1); }
|
||||
inline bool QString::operator>=(const char *s) const
|
||||
{ return *this >= QString::fromAscii(s, s ? int(strlen(s)) : -1); }
|
||||
{ return *this >= QString::fromUtf8(s, s ? int(strlen(s)) : -1); }
|
||||
|
||||
inline QT_ASCII_CAST_WARN bool operator==(const char *s1, const QString &s2)
|
||||
{ return qStringComparisonHelper(s2, s1); }
|
||||
inline QT_ASCII_CAST_WARN bool operator!=(const char *s1, const QString &s2)
|
||||
{ return !qStringComparisonHelper(s2, s1); }
|
||||
inline QT_ASCII_CAST_WARN bool operator<(const char *s1, const QString &s2)
|
||||
{ return (QString::fromAscii(s1, s1 ? int(strlen(s1)) : -1) < s2); }
|
||||
{ return (QString::fromUtf8(s1, s1 ? int(strlen(s1)) : -1) < s2); }
|
||||
inline QT_ASCII_CAST_WARN bool operator>(const char *s1, const QString &s2)
|
||||
{ return (QString::fromAscii(s1, s1 ? int(strlen(s1)) : -1) > s2); }
|
||||
{ return (QString::fromUtf8(s1, s1 ? int(strlen(s1)) : -1) > s2); }
|
||||
inline QT_ASCII_CAST_WARN bool operator<=(const char *s1, const QString &s2)
|
||||
{ return (QString::fromAscii(s1, s1 ? int(strlen(s1)) : -1) <= s2); }
|
||||
{ return (QString::fromUtf8(s1, s1 ? int(strlen(s1)) : -1) <= s2); }
|
||||
inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QString &s2)
|
||||
{ return (QString::fromAscii(s1, s1 ? int(strlen(s1)) : -1) >= s2); }
|
||||
{ return (QString::fromUtf8(s1, s1 ? int(strlen(s1)) : -1) >= s2); }
|
||||
|
||||
inline QT_ASCII_CAST_WARN bool operator==(const char *s1, const QLatin1String &s2)
|
||||
{ return QString::fromAscii(s1, s1 ? int(strlen(s1)) : -1) == s2; }
|
||||
{ return QString::fromUtf8(s1, s1 ? int(strlen(s1)) : -1) == s2; }
|
||||
inline QT_ASCII_CAST_WARN bool operator!=(const char *s1, const QLatin1String &s2)
|
||||
{ return QString::fromAscii(s1, s1 ? int(strlen(s1)) : -1) != s2; }
|
||||
{ return QString::fromUtf8(s1, s1 ? int(strlen(s1)) : -1) != s2; }
|
||||
inline QT_ASCII_CAST_WARN bool operator<(const char *s1, const QLatin1String &s2)
|
||||
{ return (QString::fromAscii(s1, s1 ? int(strlen(s1)) : -1) < s2); }
|
||||
{ return (QString::fromUtf8(s1, s1 ? int(strlen(s1)) : -1) < s2); }
|
||||
inline QT_ASCII_CAST_WARN bool operator>(const char *s1, const QLatin1String &s2)
|
||||
{ return (QString::fromAscii(s1, s1 ? int(strlen(s1)) : -1) > s2); }
|
||||
{ return (QString::fromUtf8(s1, s1 ? int(strlen(s1)) : -1) > s2); }
|
||||
inline QT_ASCII_CAST_WARN bool operator<=(const char *s1, const QLatin1String &s2)
|
||||
{ return (QString::fromAscii(s1, s1 ? int(strlen(s1)) : -1) <= s2); }
|
||||
{ return (QString::fromUtf8(s1, s1 ? int(strlen(s1)) : -1) <= s2); }
|
||||
inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QLatin1String &s2)
|
||||
{ return (QString::fromAscii(s1, s1 ? int(strlen(s1)) : -1) >= s2); }
|
||||
{ return (QString::fromUtf8(s1, s1 ? int(strlen(s1)) : -1) >= s2); }
|
||||
|
||||
inline bool operator==(const QLatin1String &s1, const QLatin1String &s2)
|
||||
{ return (s1.size() == s2.size() && !memcmp(s1.latin1(), s2.latin1(), s1.size())); }
|
||||
@ -1053,32 +1053,32 @@ inline bool QByteArray::operator==(const QString &s) const
|
||||
inline bool QByteArray::operator!=(const QString &s) const
|
||||
{ return !qStringComparisonHelper(s, *this); }
|
||||
inline bool QByteArray::operator<(const QString &s) const
|
||||
{ return QString::fromAscii(constData(), size()) < s; }
|
||||
{ return QString::fromUtf8(constData(), size()) < s; }
|
||||
inline bool QByteArray::operator>(const QString &s) const
|
||||
{ return QString::fromAscii(constData(), size()) > s; }
|
||||
{ return QString::fromUtf8(constData(), size()) > s; }
|
||||
inline bool QByteArray::operator<=(const QString &s) const
|
||||
{ return QString::fromAscii(constData(), size()) <= s; }
|
||||
{ return QString::fromUtf8(constData(), size()) <= s; }
|
||||
inline bool QByteArray::operator>=(const QString &s) const
|
||||
{ return QString::fromAscii(constData(), size()) >= s; }
|
||||
{ return QString::fromUtf8(constData(), size()) >= s; }
|
||||
#endif // QT_NO_CAST_FROM_ASCII
|
||||
|
||||
#ifndef QT_NO_CAST_TO_ASCII
|
||||
inline QByteArray &QByteArray::append(const QString &s)
|
||||
{ return append(s.toAscii()); }
|
||||
{ return append(s.toUtf8()); }
|
||||
inline QByteArray &QByteArray::insert(int i, const QString &s)
|
||||
{ return insert(i, s.toAscii()); }
|
||||
{ return insert(i, s.toUtf8()); }
|
||||
inline QByteArray &QByteArray::replace(char c, const QString &after)
|
||||
{ return replace(c, after.toAscii()); }
|
||||
{ return replace(c, after.toUtf8()); }
|
||||
inline QByteArray &QByteArray::replace(const QString &before, const char *after)
|
||||
{ return replace(before.toAscii(), after); }
|
||||
{ return replace(before.toUtf8(), after); }
|
||||
inline QByteArray &QByteArray::replace(const QString &before, const QByteArray &after)
|
||||
{ return replace(before.toAscii(), after); }
|
||||
{ return replace(before.toUtf8(), after); }
|
||||
inline QByteArray &QByteArray::operator+=(const QString &s)
|
||||
{ return operator+=(s.toAscii()); }
|
||||
{ return operator+=(s.toUtf8()); }
|
||||
inline int QByteArray::indexOf(const QString &s, int from) const
|
||||
{ return indexOf(s.toAscii(), from); }
|
||||
{ return indexOf(s.toUtf8(), from); }
|
||||
inline int QByteArray::lastIndexOf(const QString &s, int from) const
|
||||
{ return lastIndexOf(s.toAscii(), from); }
|
||||
{ return lastIndexOf(s.toUtf8(), from); }
|
||||
#endif // QT_NO_CAST_TO_ASCII
|
||||
|
||||
#if !defined(QT_USE_FAST_OPERATOR_PLUS) && !defined(QT_USE_QSTRINGBUILDER)
|
||||
@ -1090,25 +1090,25 @@ inline const QString operator+(QChar s1, const QString &s2)
|
||||
{ QString t(s1); t += s2; return t; }
|
||||
# ifndef QT_NO_CAST_FROM_ASCII
|
||||
inline QT_ASCII_CAST_WARN const QString operator+(const QString &s1, const char *s2)
|
||||
{ QString t(s1); t += QString::fromAscii(s2, s2 ? int(strlen(s2)) : -1); return t; }
|
||||
{ QString t(s1); t += QString::fromUtf8(s2, s2 ? int(strlen(s2)) : -1); return t; }
|
||||
inline QT_ASCII_CAST_WARN const QString operator+(const char *s1, const QString &s2)
|
||||
{ QString t = QString::fromAscii(s1, s1 ? int(strlen(s1)) : -1); t += s2; return t; }
|
||||
{ QString t = QString::fromUtf8(s1, s1 ? int(strlen(s1)) : -1); t += s2; return t; }
|
||||
inline QT_ASCII_CAST_WARN const QString operator+(char c, const QString &s)
|
||||
{ QString t = s; t.prepend(QChar::fromAscii(c)); return t; }
|
||||
inline QT_ASCII_CAST_WARN const QString operator+(const QString &s, char c)
|
||||
{ QString t = s; t += QChar::fromAscii(c); return t; }
|
||||
inline QT_ASCII_CAST_WARN const QString operator+(const QByteArray &ba, const QString &s)
|
||||
{ QString t = QString::fromAscii(ba.constData(), qstrnlen(ba.constData(), ba.size())); t += s; return t; }
|
||||
{ QString t = QString::fromUtf8(ba.constData(), qstrnlen(ba.constData(), ba.size())); t += s; return t; }
|
||||
inline QT_ASCII_CAST_WARN const QString operator+(const QString &s, const QByteArray &ba)
|
||||
{ QString t(s); t += QString::fromAscii(ba.constData(), qstrnlen(ba.constData(), ba.size())); return t; }
|
||||
{ QString t(s); t += QString::fromUtf8(ba.constData(), qstrnlen(ba.constData(), ba.size())); return t; }
|
||||
# endif // QT_NO_CAST_FROM_ASCII
|
||||
#endif // QT_USE_QSTRINGBUILDER
|
||||
|
||||
inline std::string QString::toStdString() const
|
||||
{ const QByteArray asc = toAscii(); return std::string(asc.constData(), asc.length()); }
|
||||
{ const QByteArray asc = toUtf8(); return std::string(asc.constData(), asc.length()); }
|
||||
|
||||
inline QString QString::fromStdString(const std::string &s)
|
||||
{ return fromAscii(s.data(), int(s.size())); }
|
||||
{ return fromUtf8(s.data(), int(s.size())); }
|
||||
|
||||
inline std::wstring QString::toStdWString() const
|
||||
{
|
||||
|
@ -84,7 +84,7 @@ QTestData &operator<<(QTestData &data, const T &value)
|
||||
|
||||
inline QTestData &operator<<(QTestData &data, const char * value)
|
||||
{
|
||||
QString str = QString::fromAscii(value);
|
||||
QString str = QString::fromUtf8(value);
|
||||
data.append(QMetaType::QString, &str);
|
||||
return data;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user