QLatin1String: harmonize null byte handling with the rest of QString
After the introduction of QByteArrayView, all the QString::fromXxx overloads and the constructor will include the null bytes inside QByteArrays and so will QLatin1Strings created from QByteArrayViews. This was the lone stand-out that wasn't fixed in 6.0, so do it now. [ChangeLog][Important Behavior Changes] Since Qt 6.0, all QString and QLatin1String methods consuming QByteArray and QByteArrayView objects will include any embedded null bytes and treat them as U+0000 Unicode characters, whereas in Qt 4.x and 5.x, they would stop at the first null byte like bare C strings. Qt 6.3 contains a fix for a couple of the methods that mistakenly persisted the old behavior in 6.0-6.2, namely the QLatin1String constructor from QByteArray and the equality and inequality operators between QByteArray and QString. Task-number: QTBUG-97451 Change-Id: Icb2516126f674e7b8bb3fffd16ad5621cf3e64ec Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
5bc315fbe2
commit
f9139b19bf
@ -88,7 +88,7 @@ public:
|
||||
constexpr explicit QLatin1String(const char *f, const char *l)
|
||||
: QLatin1String(f, qsizetype(l - f)) {}
|
||||
constexpr inline explicit QLatin1String(const char *s, qsizetype sz) noexcept : m_size(sz), m_data(s) {}
|
||||
explicit QLatin1String(const QByteArray &s) noexcept : m_size(qsizetype(qstrnlen(s.constData(), s.size()))), m_data(s.constData()) {}
|
||||
explicit QLatin1String(const QByteArray &s) noexcept : m_size(s.size()), m_data(s.constData()) {}
|
||||
constexpr explicit QLatin1String(QByteArrayView s) noexcept : m_size(s.size()), m_data(s.data()) {}
|
||||
|
||||
inline QString toString() const;
|
||||
@ -1424,9 +1424,9 @@ QT_ASCII_CAST_WARN inline bool QString::operator>=(const QByteArray &s) const
|
||||
{ return QString::compare_helper(constData(), size(), s.constData(), s.size()) >= 0; }
|
||||
|
||||
inline bool QByteArray::operator==(const QString &s) const
|
||||
{ return QString::compare_helper(s.constData(), s.size(), constData(), qstrnlen(constData(), size())) == 0; }
|
||||
{ return QString::compare_helper(s.constData(), s.size(), constData(), size()) == 0; }
|
||||
inline bool QByteArray::operator!=(const QString &s) const
|
||||
{ return QString::compare_helper(s.constData(), s.size(), constData(), qstrnlen(constData(), size())) != 0; }
|
||||
{ return QString::compare_helper(s.constData(), s.size(), constData(), size()) != 0; }
|
||||
inline bool QByteArray::operator<(const QString &s) const
|
||||
{ return QString::compare_helper(s.constData(), s.size(), constData(), size()) > 0; }
|
||||
inline bool QByteArray::operator>(const QString &s) const
|
||||
|
Loading…
x
Reference in New Issue
Block a user