forked from qt-creator/qt-creator
Fix mime type parsing with Qt 5
The behavior of QStringView::mid is slightly different between Qt 5 and Qt 6, so use Utils::midView which was created exactly to cover that. Change-Id: Ia084e93c36fb152ac725f1b8eaa38a07dfb939e1 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -40,8 +40,11 @@
|
|||||||
#include "mimemagicrule_p.h"
|
#include "mimemagicrule_p.h"
|
||||||
|
|
||||||
#include "mimetypeparser_p.h"
|
#include "mimetypeparser_p.h"
|
||||||
#include <QtCore/QList>
|
|
||||||
|
#include "porting.h"
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
|
#include <QtCore/QList>
|
||||||
#include <qendian.h>
|
#include <qendian.h>
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
@@ -260,8 +263,11 @@ MimeMagicRule::MimeMagicRule(const QString &type,
|
|||||||
|
|
||||||
// Parse for offset as "1" or "1:10"
|
// Parse for offset as "1" or "1:10"
|
||||||
const int colonIndex = offsets.indexOf(QLatin1Char(':'));
|
const int colonIndex = offsets.indexOf(QLatin1Char(':'));
|
||||||
const QStringView startPosStr = QStringView{offsets}.mid(0, colonIndex); // \ These decay to returning 'offsets'
|
const QStringView startPosStr
|
||||||
const QStringView endPosStr = QStringView{offsets}.mid(colonIndex + 1);// / unchanged when colonIndex == -1
|
= Utils::midView(offsets, 0, colonIndex); // \ These decay to returning 'offsets'
|
||||||
|
const QStringView endPosStr = Utils::midView(offsets,
|
||||||
|
colonIndex
|
||||||
|
+ 1); // / unchanged when colonIndex == -1
|
||||||
if (Q_UNLIKELY(!MimeTypeParserBase::parseNumber(startPosStr, &m_startPos, errorString)) ||
|
if (Q_UNLIKELY(!MimeTypeParserBase::parseNumber(startPosStr, &m_startPos, errorString)) ||
|
||||||
Q_UNLIKELY(!MimeTypeParserBase::parseNumber(endPosStr, &m_endPos, errorString))) {
|
Q_UNLIKELY(!MimeTypeParserBase::parseNumber(endPosStr, &m_endPos, errorString))) {
|
||||||
m_type = Invalid;
|
m_type = Invalid;
|
||||||
|
@@ -65,7 +65,7 @@ inline StringView make_stringview(const QString &s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// QStringView::mid in Qt5 does not do bounds checking, in Qt6 it does
|
// QStringView::mid in Qt5 does not do bounds checking, in Qt6 it does
|
||||||
inline QStringView midView(const QString &s, int offset, int length)
|
inline QStringView midView(const QString &s, int offset, int length = -1)
|
||||||
{
|
{
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||||
const int size = s.size();
|
const int size = s.size();
|
||||||
@@ -77,7 +77,7 @@ inline QStringView midView(const QString &s, int offset, int length)
|
|||||||
if (length + offset <= 0)
|
if (length + offset <= 0)
|
||||||
return {};
|
return {};
|
||||||
return QStringView(s).left(length + offset);
|
return QStringView(s).left(length + offset);
|
||||||
} else if (length > size - offset)
|
} else if (length < 0 || length > size - offset)
|
||||||
return QStringView(s).mid(offset);
|
return QStringView(s).mid(offset);
|
||||||
return QStringView(s).mid(offset, length);
|
return QStringView(s).mid(offset, length);
|
||||||
#else
|
#else
|
||||||
|
Reference in New Issue
Block a user