From 2c9228973fc212db044add557839b15a8cb483c3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 2 May 2012 16:30:04 +0200 Subject: 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 Reviewed-by: Olivier Goffart Reviewed-by: Lars Knoll --- src/corelib/tools/qchar.cpp | 2 ++ src/corelib/tools/qchar.h | 11 +++++++---- src/corelib/tools/qstring.cpp | 14 ++++++-------- src/corelib/tools/qstring.h | 37 ++++++++++++++++++++++--------------- 4 files changed, 37 insertions(+), 27 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp index cb5db973e1..ecaeff453b 100644 --- a/src/corelib/tools/qchar.cpp +++ b/src/corelib/tools/qchar.cpp @@ -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. diff --git a/src/corelib/tools/qchar.h b/src/corelib/tools/qchar.h index 63a8df32f4..c8cbd1d0cf 100644 --- a/src/corelib/tools/qchar.h +++ b/src/corelib/tools/qchar.h @@ -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); } diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 5c63661de8..cc9f4dbef0 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -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 diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 965bfb0fe9..3673da1f91 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -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 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; -- cgit v1.2.3