Port mimetypes away from QStringRef

Task-number: QTBUG-84319
Change-Id: I2bed1149df7f11495fd9dc3577828c0790b17dab
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
This commit is contained in:
Lars Knoll 2020-05-22 17:08:38 +02:00
parent ecacb3c62f
commit 82a0f4a193
7 changed files with 8 additions and 8 deletions

View File

@ -250,7 +250,7 @@ void QMimeDatabasePrivate::loadIcon(QMimeTypePrivate &mimePrivate)
static QString fallbackParent(const QString &mimeTypeName)
{
const QStringRef myGroup = mimeTypeName.leftRef(mimeTypeName.indexOf(QLatin1Char('/')));
const QStringView myGroup = QStringView{mimeTypeName}.left(mimeTypeName.indexOf(QLatin1Char('/')));
// All text/* types are subclasses of text/plain.
if (myGroup == QLatin1String("text") && mimeTypeName != QLatin1String("text/plain"))
return QLatin1String("text/plain");

View File

@ -128,7 +128,7 @@ bool QMimeGlobPattern::matchFileName(const QString &inputFilename) const
if (starCount == 1 && m_pattern.at(pattern_len - 1) == QLatin1Char('*')) {
if (len + 1 < pattern_len) return false;
if (m_pattern.at(0) == QLatin1Char('*'))
return filename.indexOf(m_pattern.midRef(1, pattern_len - 2)) != -1;
return filename.indexOf(QStringView{m_pattern}.mid(1, pattern_len - 2)) != -1;
const QChar *c1 = m_pattern.unicode();
const QChar *c2 = filename.unicode();

View File

@ -236,8 +236,8 @@ QMimeMagicRule::QMimeMagicRule(const QString &type,
// Parse for offset as "1" or "1:10"
const int colonIndex = offsets.indexOf(QLatin1Char(':'));
const QStringRef startPosStr = offsets.midRef(0, colonIndex); // \ These decay to returning 'offsets'
const QStringRef endPosStr = offsets.midRef(colonIndex + 1);// / unchanged when colonIndex == -1
const QStringView startPosStr = QStringView{offsets}.mid(0, colonIndex); // \ These decay to returning 'offsets'
const QStringView endPosStr = QStringView{offsets}.mid(colonIndex + 1);// / unchanged when colonIndex == -1
if (Q_UNLIKELY(!QMimeTypeParserBase::parseNumber(startPosStr, &m_startPos, errorString)) ||
Q_UNLIKELY(!QMimeTypeParserBase::parseNumber(endPosStr, &m_endPos, errorString))) {
m_type = Invalid;

View File

@ -306,7 +306,7 @@ bool QMimeBinaryProvider::matchSuffixTree(QMimeGlobMatchResult &result, QMimeBin
const bool caseSensitive = flagsAndWeight & 0x100;
if (caseSensitiveCheck || !caseSensitive) {
result.addMatch(QLatin1String(mimeType), weight,
QLatin1Char('*') + fileName.midRef(charPos + 1), fileName.size() - charPos - 2);
QLatin1Char('*') + QStringView{fileName}.mid(charPos + 1), fileName.size() - charPos - 2);
success = true;
}
}

View File

@ -302,7 +302,7 @@ QString QMimeType::genericIconName() const
// media type (e.g. "video" in "video/ogg") and appending "-x-generic"
// (i.e. "video-x-generic" in the previous example).
const QString group = name();
QStringRef groupRef(&group);
QStringView groupRef(group);
const int slashindex = groupRef.indexOf(QLatin1Char('/'));
if (slashindex != -1)
groupRef = groupRef.left(slashindex);

View File

@ -157,7 +157,7 @@ QMimeTypeParserBase::ParseState QMimeTypeParserBase::nextState(ParseState curren
}
// Parse int number from an (attribute) string
bool QMimeTypeParserBase::parseNumber(const QStringRef &n, int *target, QString *errorMessage)
bool QMimeTypeParserBase::parseNumber(QStringView n, int *target, QString *errorMessage)
{
bool ok;
*target = n.toInt(&ok);

View File

@ -72,7 +72,7 @@ public:
bool parse(QIODevice *dev, const QString &fileName, QString *errorMessage);
static bool parseNumber(const QStringRef &n, int *target, QString *errorMessage);
static bool parseNumber(QStringView n, int *target, QString *errorMessage);
protected:
virtual bool process(const QMimeType &t, QString *errorMessage) = 0;