Deprecate {QString,QStringRef,QChar}::{to,from}Ascii

Make them call exactly their Latin 1 counterparts.

For the QString functions that take a single char, also use fromAscii
directly.

Change-Id: I87645aba6ab9cde34c1df3cbc3a979fbd9e91f9d
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
bb10
Thiago Macieira 2012-05-02 16:30:04 +02:00 committed by Qt by Nokia
parent 1ca791faf5
commit 2c9228973f
4 changed files with 37 additions and 27 deletions

View File

@ -1320,6 +1320,7 @@ uint QChar::toCaseFolded(uint ucs4)
/*!
\fn char QChar::toAscii() const
\deprecated
Returns the Latin-1 character value of the QChar, or 0 if the character is not
representable.
@ -1339,6 +1340,7 @@ uint QChar::toCaseFolded(uint ucs4)
/*!
\fn QChar QChar::fromAscii(char)
\deprecated
Converts the ASCII character \a c to it's equivalent QChar. This
is mainly useful for non-internationalized software.

View File

@ -227,12 +227,17 @@ public:
inline UnicodeVersion unicodeVersion() const { return QChar::unicodeVersion(ucs); }
inline char toAscii() const;
#if QT_DEPRECATED_SINCE(5, 0)
QT_DEPRECATED inline char toAscii() const { return toLatin1(); }
#endif
inline char toLatin1() const;
inline ushort unicode() const { return ucs; }
inline ushort &unicode() { return ucs; }
static inline QChar fromAscii(char c);
#if QT_DEPRECATED_SINCE(5, 0)
QT_DEPRECATED static inline QChar fromAscii(char c)
{ return fromLatin1(c); }
#endif
static inline QChar fromLatin1(char c);
inline bool isNull() const { return ucs == 0; }
@ -337,10 +342,8 @@ 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); }

View File

@ -3960,6 +3960,8 @@ QByteArray QString::toLatin1() const
}
/*!
\fn QByteArray QString::toAscii() const
\deprecated
Returns an 8-bit representation of the string as a QByteArray.
This function does the same as toLatin1().
@ -3969,10 +3971,6 @@ QByteArray QString::toLatin1() const
\sa fromAscii(), toLatin1(), toUtf8(), toLocal8Bit(), QTextCodec
*/
QByteArray QString::toAscii() const
{
return toUtf8();
}
#if !defined(Q_OS_MAC) && defined(Q_OS_UNIX)
static QByteArray toLocal8Bit_helper(const QChar *data, int length)
@ -4146,6 +4144,8 @@ QString QString::fromLocal8Bit_helper(const char *str, int size)
}
/*! \fn QString QString::fromAscii(const char *, int size);
\deprecated
Returns a QString initialized with the first \a size characters
from the string \a str.
@ -9078,7 +9078,9 @@ QByteArray QStringRef::toLatin1() const
}
/*!
\fn QByteArray QStringRef::toAscii() const
\since 4.8
\deprecated
Returns an 8-bit representation of the string as a QByteArray.
@ -9089,10 +9091,6 @@ QByteArray QStringRef::toLatin1() const
\sa toLatin1(), toUtf8(), toLocal8Bit(), QTextCodec
*/
QByteArray QStringRef::toAscii() const
{
return toLatin1();
}
/*!
\since 4.8

View File

@ -439,17 +439,12 @@ public:
const ushort *utf16() const;
QByteArray toAscii() const Q_REQUIRED_RESULT;
QByteArray toLatin1() const Q_REQUIRED_RESULT;
QByteArray toUtf8() const Q_REQUIRED_RESULT;
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT;
QVector<uint> toUcs4() const Q_REQUIRED_RESULT;
// note - this are all inline so we can benefit from strlen() compile time optimizations
static inline QString fromAscii(const char *str, int size = -1)
{
return fromUtf8(str, size);
}
static inline QString fromLatin1(const char *str, int size = -1)
{
QStringDataPtr dataPtr = { fromLatin1_helper(str, (str && size == -1) ? int(strlen(str)) : size) };
@ -463,8 +458,6 @@ public:
{
return fromLocal8Bit_helper(str, (str && size == -1) ? int(strlen(str)) : size);
}
static inline QString fromAscii(const QByteArray &str)
{ return fromAscii(str.data(), qstrnlen(str.constData(), str.size())); }
static inline QString fromLatin1(const QByteArray &str)
{ return fromLatin1(str.data(), qstrnlen(str.constData(), str.size())); }
static inline QString fromUtf8(const QByteArray &str)
@ -475,6 +468,15 @@ public:
static QString fromUcs4(const uint *, int size = -1);
static QString fromRawData(const QChar *, int size);
#if QT_DEPRECATED_SINCE(5, 0)
QT_DEPRECATED static inline QString fromAscii(const char *str, int size = -1)
{ return fromLatin1(str, size); }
QT_DEPRECATED static inline QString fromAscii(const QByteArray &str)
{ return fromLatin1(str); }
QByteArray toAscii() const Q_REQUIRED_RESULT
{ return toLatin1(); }
#endif
inline int toWCharArray(wchar_t *array) const;
static inline QString fromWCharArray(const wchar_t *string, int size = -1) Q_REQUIRED_RESULT;
@ -563,7 +565,7 @@ public:
inline QT_ASCII_CAST_WARN QString &operator=(const QByteArray &a)
{ return (*this = fromUtf8(a.constData(), qstrnlen(a.constData(), a.size()))); }
inline QT_ASCII_CAST_WARN QString &operator=(char c)
{ return (*this = QChar::fromAscii(c)); }
{ return (*this = QChar::fromLatin1(c)); }
// these are needed, so it compiles with STL support enabled
inline QT_ASCII_CAST_WARN QString &prepend(const char *s)
@ -579,7 +581,7 @@ public:
inline QT_ASCII_CAST_WARN QString &operator+=(const QByteArray &s)
{ 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)); }
{ return append(QChar::fromLatin1(c)); }
inline QT_ASCII_CAST_WARN bool operator==(const char *s) const;
inline QT_ASCII_CAST_WARN bool operator!=(const char *s) const;
@ -867,9 +869,9 @@ public:
// An operator= for each QChar cast constructors
#ifndef QT_NO_CAST_FROM_ASCII
inline QT_ASCII_CAST_WARN QCharRef &operator=(char c)
{ return operator=(QChar::fromAscii(c)); }
{ return operator=(QChar::fromLatin1(c)); }
inline QT_ASCII_CAST_WARN QCharRef &operator=(uchar c)
{ return operator=(QChar::fromAscii(c)); }
{ return operator=(QChar::fromLatin1(c)); }
#endif
inline QCharRef &operator=(const QCharRef &c) { return operator=(QChar(c)); }
inline QCharRef &operator=(ushort rc) { return operator=(QChar(rc)); }
@ -912,7 +914,9 @@ public:
inline void setCell(uchar cell);
inline void setRow(uchar row);
char toAscii() const { return QChar(*this).toAscii(); }
#if QT_DEPRECATED_SINCE(5, 0)
QT_DEPRECATED char toAscii() const { return QChar(*this).toLatin1(); }
#endif
char toLatin1() const { return QChar(*this).toLatin1(); }
ushort unicode() const { return QChar(*this).unicode(); }
ushort& unicode() { return s.data()[i].unicode(); }
@ -1095,9 +1099,9 @@ inline QT_ASCII_CAST_WARN const QString operator+(const QString &s1, const char
inline QT_ASCII_CAST_WARN const QString operator+(const char *s1, const QString &s2)
{ 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; }
{ QString t = s; t.prepend(QChar::fromLatin1(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; }
{ QString t = s; t += QChar::fromLatin1(c); return t; }
inline QT_ASCII_CAST_WARN const QString operator+(const QByteArray &ba, const QString &s)
{ 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)
@ -1201,7 +1205,10 @@ public:
inline const QChar *data() const { return unicode(); }
inline const QChar *constData() const { return unicode(); }
QByteArray toAscii() const Q_REQUIRED_RESULT;
#if QT_DEPRECATED_SINCE(5, 0)
QT_DEPRECATED QByteArray toAscii() const Q_REQUIRED_RESULT
{ return toLatin1(); }
#endif
QByteArray toLatin1() const Q_REQUIRED_RESULT;
QByteArray toUtf8() const Q_REQUIRED_RESULT;
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT;