Update mime database from Qt

qtbase/753a08ae0e1204b148cf3935f87349eefe75d338
  QtCore: replace QLatin1String/QLatin1Char with _L1/u'' where
  applicable

Change-Id: I0b636c5b6e5c10f9388e2451e4a55afe04414361
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Eike Ziller
2024-08-09 11:18:41 +02:00
parent 1d4948bc82
commit fcb3f2edc2
6 changed files with 81 additions and 68 deletions

View File

@@ -26,6 +26,8 @@
#include <functional> #include <functional>
#include <stack> #include <stack>
using namespace Qt::StringLiterals;
static QString directoryMimeType() static QString directoryMimeType()
{ {
return QStringLiteral("inode/directory"); return QStringLiteral("inode/directory");
@@ -115,7 +117,7 @@ void MimeDatabasePrivate::loadProviders()
const QStringList mimeDirs; const QStringList mimeDirs;
#endif #endif
const auto fdoIterator = std::find_if(mimeDirs.constBegin(), mimeDirs.constEnd(), [](const QString &mimeDir) -> bool { const auto fdoIterator = std::find_if(mimeDirs.constBegin(), mimeDirs.constEnd(), [](const QString &mimeDir) -> bool {
return QFileInfo::exists(mimeDir + QLatin1String("/packages/freedesktop.org.xml")); } return QFileInfo::exists(mimeDir + "/packages/freedesktop.org.xml"_L1); }
); );
const bool needInternalDB = MimeXMLProvider::InternalDatabaseAvailable && fdoIterator == mimeDirs.constEnd(); const bool needInternalDB = MimeXMLProvider::InternalDatabaseAvailable && fdoIterator == mimeDirs.constEnd();
//qDebug() << "mime dirs:" << mimeDirs; //qDebug() << "mime dirs:" << mimeDirs;
@@ -142,7 +144,7 @@ void MimeDatabasePrivate::loadProviders()
for (const QString &mimeDir : mimeDirs) { for (const QString &mimeDir : mimeDirs) {
const QString cacheFile = mimeDir + QLatin1String("/mime.cache"); const QString cacheFile = mimeDir + "/mime.cache"_L1;
// Check if we already have a provider for this dir // Check if we already have a provider for this dir
const auto predicate = [mimeDir](const std::unique_ptr<MimeProviderBase> &prov) const auto predicate = [mimeDir](const std::unique_ptr<MimeProviderBase> &prov)
{ {
@@ -239,7 +241,7 @@ MimeType MimeDatabasePrivate::mimeTypeForName(const QString &nameOrAlias)
QStringList MimeDatabasePrivate::mimeTypeForFileName(const QString &fileName) QStringList MimeDatabasePrivate::mimeTypeForFileName(const QString &fileName)
{ {
if (fileName.endsWith(QLatin1Char('/'))) if (fileName.endsWith(u'/'))
return { directoryMimeType() }; return { directoryMimeType() };
const MimeGlobMatchResult result = findByFileName(fileName); const MimeGlobMatchResult result = findByFileName(fileName);
@@ -272,7 +274,7 @@ void MimeDatabasePrivate::loadMimeTypePrivate(MimeTypePrivate &mimePrivate)
} }
} }
if (!found) { if (!found) {
const QString file = mimePrivate.name + QLatin1String(".xml"); const QString file = mimePrivate.name + ".xml"_L1;
qWarning() << "No file found for" << file << ", even though update-mime-info said it would exist.\n" qWarning() << "No file found for" << file << ", even though update-mime-info said it would exist.\n"
"Either it was just removed, or the directory doesn't have executable permission..." "Either it was just removed, or the directory doesn't have executable permission..."
<< locateMimeDirectories(); << locateMimeDirectories();
@@ -309,14 +311,14 @@ void MimeDatabasePrivate::loadIcon(MimeTypePrivate &mimePrivate)
QString MimeDatabasePrivate::fallbackParent(const QString &mimeTypeName) const QString MimeDatabasePrivate::fallbackParent(const QString &mimeTypeName) const
{ {
const QStringView myGroup = QStringView{mimeTypeName}.left(mimeTypeName.indexOf(QLatin1Char('/'))); const QStringView myGroup = QStringView{mimeTypeName}.left(mimeTypeName.indexOf(u'/'));
// All text/* types are subclasses of text/plain. // All text/* types are subclasses of text/plain.
if (myGroup == QLatin1String("text") && mimeTypeName != plainTextMimeType()) if (myGroup == "text"_L1 && mimeTypeName != plainTextMimeType())
return plainTextMimeType(); return plainTextMimeType();
// All real-file mimetypes implicitly derive from application/octet-stream // All real-file mimetypes implicitly derive from application/octet-stream
if (myGroup != QLatin1String("inode") && if (myGroup != "inode"_L1 &&
// ignore non-file extensions // ignore non-file extensions
myGroup != QLatin1String("all") && myGroup != QLatin1String("fonts") && myGroup != QLatin1String("print") && myGroup != QLatin1String("uri") myGroup != "all"_L1 && myGroup != "fonts"_L1 && myGroup != "print"_L1 && myGroup != "uri"_L1
&& mimeTypeName != defaultMimeType()) { && mimeTypeName != defaultMimeType()) {
return defaultMimeType(); return defaultMimeType();
} }
@@ -784,7 +786,7 @@ MimeType MimeDatabase::mimeTypeForUrl(const QUrl &url) const
return mimeTypeForFile(url.toLocalFile()); return mimeTypeForFile(url.toLocalFile());
const QString scheme = url.scheme(); const QString scheme = url.scheme();
if (scheme.startsWith(QLatin1String("http")) || scheme == QLatin1String("mailto")) if (scheme.startsWith("http"_L1) || scheme == "mailto"_L1)
return mimeTypeForName(d->defaultMimeType()); return mimeTypeForName(d->defaultMimeType());
return mimeTypeForFile(url.path(), MatchExtension); return mimeTypeForFile(url.path(), MatchExtension);
@@ -813,7 +815,7 @@ MimeType MimeDatabase::mimeTypeForFileNameAndData(const QString &fileName, QIODe
{ {
QMutexLocker locker(&d->mutex); QMutexLocker locker(&d->mutex);
if (fileName.endsWith(QLatin1Char('/'))) if (fileName.endsWith(u'/'))
return d->mimeTypeForName(directoryMimeType()); return d->mimeTypeForName(directoryMimeType());
const bool openedByUs = !device->isOpen() && device->open(QIODevice::ReadOnly); const bool openedByUs = !device->isOpen() && device->open(QIODevice::ReadOnly);
@@ -843,7 +845,7 @@ MimeType MimeDatabase::mimeTypeForFileNameAndData(const QString &fileName, const
{ {
QMutexLocker locker(&d->mutex); QMutexLocker locker(&d->mutex);
if (fileName.endsWith(QLatin1Char('/'))) if (fileName.endsWith(u'/'))
return d->mimeTypeForName(directoryMimeType()); return d->mimeTypeForName(directoryMimeType());
QBuffer buffer(const_cast<QByteArray *>(&data)); QBuffer buffer(const_cast<QByteArray *>(&data));

View File

@@ -9,6 +9,8 @@
#include <QStringList> #include <QStringList>
#include <QDebug> #include <QDebug>
using namespace Qt::StringLiterals;
namespace Utils { namespace Utils {
/*! /*!
@@ -61,17 +63,17 @@ MimeGlobPattern::PatternType MimeGlobPattern::detectPatternType(const QString &p
if (!patternLength) if (!patternLength)
return OtherPattern; return OtherPattern;
const int starCount = pattern.count(QLatin1Char('*')); const int starCount = pattern.count(u'*');
const bool hasSquareBracket = pattern.indexOf(QLatin1Char('[')) != -1; const bool hasSquareBracket = pattern.indexOf(u'[') != -1;
const bool hasQuestionMark = pattern.indexOf(QLatin1Char('?')) != -1; const bool hasQuestionMark = pattern.indexOf(u'?') != -1;
if (!hasSquareBracket && !hasQuestionMark) { if (!hasSquareBracket && !hasQuestionMark) {
if (starCount == 1) { if (starCount == 1) {
// Patterns like "*~", "*.extension" // Patterns like "*~", "*.extension"
if (pattern.at(0) == QLatin1Char('*')) if (pattern.at(0) == u'*')
return SuffixPattern; return SuffixPattern;
// Patterns like "README*" (well this is currently the only one like that...) // Patterns like "README*" (well this is currently the only one like that...)
if (pattern.at(patternLength - 1) == QLatin1Char('*')) if (pattern.at(patternLength - 1) == u'*')
return PrefixPattern; return PrefixPattern;
} else if (starCount == 0) { } else if (starCount == 0) {
// Names without any wildcards like "README" // Names without any wildcards like "README"
@@ -79,10 +81,10 @@ MimeGlobPattern::PatternType MimeGlobPattern::detectPatternType(const QString &p
} }
} }
if (pattern == QLatin1String("[0-9][0-9][0-9].vdr")) if (pattern == "[0-9][0-9][0-9].vdr"_L1)
return VdrPattern; return VdrPattern;
if (pattern == QLatin1String("*.anim[1-9j]")) if (pattern == "*.anim[1-9j]"_L1)
return AnimPattern; return AnimPattern;
return OtherPattern; return OtherPattern;
@@ -139,14 +141,14 @@ bool MimeGlobPattern::matchFileName(const QString &inputFileName) const
case VdrPattern: // "[0-9][0-9][0-9].vdr" case case VdrPattern: // "[0-9][0-9][0-9].vdr" case
return fileNameLength == 7 return fileNameLength == 7
&& fileName.at(0).isDigit() && fileName.at(1).isDigit() && fileName.at(2).isDigit() && fileName.at(0).isDigit() && fileName.at(1).isDigit() && fileName.at(2).isDigit()
&& QStringView{fileName}.mid(3, 4) == QLatin1String(".vdr"); && QStringView{fileName}.mid(3, 4) == ".vdr"_L1;
case AnimPattern: { // "*.anim[1-9j]" case case AnimPattern: { // "*.anim[1-9j]" case
if (fileNameLength < 6) if (fileNameLength < 6)
return false; return false;
const QChar lastChar = fileName.at(fileNameLength - 1); const QChar lastChar = fileName.at(fileNameLength - 1);
const bool lastCharOK = (lastChar.isDigit() && lastChar != QLatin1Char('0')) const bool lastCharOK = (lastChar.isDigit() && lastChar != u'0')
|| lastChar == QLatin1Char('j'); || lastChar == u'j';
return lastCharOK && QStringView{fileName}.mid(fileNameLength - 6, 5) == QLatin1String(".anim"); return lastCharOK && QStringView{fileName}.mid(fileNameLength - 6, 5) == ".anim"_L1;
} }
case OtherPattern: case OtherPattern:
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
@@ -164,23 +166,23 @@ bool MimeGlobPattern::matchFileName(const QString &inputFileName) const
static bool isSimplePattern(const QString &pattern) static bool isSimplePattern(const QString &pattern)
{ {
// starts with "*.", has no other '*' // starts with "*.", has no other '*'
return pattern.lastIndexOf(QLatin1Char('*')) == 0 return pattern.lastIndexOf(u'*') == 0
&& pattern.length() > 1 && pattern.length() > 1
&& pattern.at(1) == QLatin1Char('.') // (other dots are OK, like *.tar.bz2) && pattern.at(1) == u'.' // (other dots are OK, like *.tar.bz2)
// and contains no other special character // and contains no other special character
&& !pattern.contains(QLatin1Char('?')) && !pattern.contains(u'?')
&& !pattern.contains(QLatin1Char('[')) && !pattern.contains(u'[')
; ;
} }
static bool isFastPattern(const QString &pattern) static bool isFastPattern(const QString &pattern)
{ {
// starts with "*.", has no other '*' and no other '.' // starts with "*.", has no other '*' and no other '.'
return pattern.lastIndexOf(QLatin1Char('*')) == 0 return pattern.lastIndexOf(u'*') == 0
&& pattern.lastIndexOf(QLatin1Char('.')) == 1 && pattern.lastIndexOf(u'.') == 1
// and contains no other special character // and contains no other special character
&& !pattern.contains(QLatin1Char('?')) && !pattern.contains(u'?')
&& !pattern.contains(QLatin1Char('[')) && !pattern.contains(u'[')
; ;
} }
@@ -246,14 +248,14 @@ void MimeAllGlobPatterns::matchingGlobs(const QString &fileName,
// Now use the "fast patterns" dict, for simple *.foo patterns with weight 50 // Now use the "fast patterns" dict, for simple *.foo patterns with weight 50
// (which is most of them, so this optimization is definitely worth it) // (which is most of them, so this optimization is definitely worth it)
const int lastDot = fileName.lastIndexOf(QLatin1Char('.')); const int lastDot = fileName.lastIndexOf(u'.');
if (lastDot != -1) { // if no '.', skip the extension lookup if (lastDot != -1) { // if no '.', skip the extension lookup
const int ext_len = fileName.length() - lastDot - 1; const int ext_len = fileName.length() - lastDot - 1;
const QString simpleExtension = fileName.right(ext_len).toLower(); const QString simpleExtension = fileName.right(ext_len).toLower();
// (toLower because fast patterns are always case-insensitive and saved as lowercase) // (toLower because fast patterns are always case-insensitive and saved as lowercase)
const QStringList matchingMimeTypes = m_fastPatterns.value(simpleExtension); const QStringList matchingMimeTypes = m_fastPatterns.value(simpleExtension);
const QString simplePattern = QLatin1String("*.") + simpleExtension; const QString simplePattern = "*."_L1 + simpleExtension;
for (const QString &mime : matchingMimeTypes) { for (const QString &mime : matchingMimeTypes) {
if (!ignoreMimeTypes.contains(mime)) if (!ignoreMimeTypes.contains(mime))
result.addMatch(mime, 50, simplePattern, simpleExtension.size()); result.addMatch(mime, 50, simplePattern, simpleExtension.size());

View File

@@ -9,6 +9,8 @@
#include <QtCore/QMap> #include <QtCore/QMap>
#include <qendian.h> #include <qendian.h>
using namespace Qt::StringLiterals;
namespace Utils { namespace Utils {
// in the same order as Type! // in the same order as Type!
@@ -221,10 +223,10 @@ MimeMagicRule::MimeMagicRule(const QString &type,
m_matchFunction(nullptr) m_matchFunction(nullptr)
{ {
if (Q_UNLIKELY(m_type == Invalid)) if (Q_UNLIKELY(m_type == Invalid))
*errorString = QLatin1String("Type ") + type + QLatin1String(" is not supported"); *errorString = "Type "_L1 + type + " is not supported"_L1;
// 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(u':');
const QStringView startPosStr const QStringView startPosStr
= QStringView(offsets).mid(0, colonIndex); // \ These decay to returning 'offsets' = QStringView(offsets).mid(0, colonIndex); // \ These decay to returning 'offsets'
const QStringView endPosStr = QStringView(offsets) const QStringView endPosStr = QStringView(offsets)
@@ -253,7 +255,7 @@ void MimeMagicRule::init(QString *errorString)
if (Q_UNLIKELY(!ok)) { if (Q_UNLIKELY(!ok)) {
m_type = Invalid; m_type = Invalid;
if (errorString) if (errorString)
*errorString = QLatin1String("Invalid magic rule value \"") + QLatin1String(m_value) + QLatin1Char('"'); *errorString = "Invalid magic rule value \""_L1 + QLatin1String(m_value) + u'"';
return; return;
} }
m_numberMask = !m_mask.isEmpty() ? m_mask.toUInt(&ok, 0) : 0; // autodetect base m_numberMask = !m_mask.isEmpty() ? m_mask.toUInt(&ok, 0) : 0; // autodetect base
@@ -267,7 +269,7 @@ void MimeMagicRule::init(QString *errorString)
if (Q_UNLIKELY(m_mask.size() < 4 || !m_mask.startsWith("0x"))) { if (Q_UNLIKELY(m_mask.size() < 4 || !m_mask.startsWith("0x"))) {
m_type = Invalid; m_type = Invalid;
if (errorString) if (errorString)
*errorString = QLatin1String("Invalid magic rule mask \"") + QLatin1String(m_mask) + QLatin1Char('"'); *errorString = "Invalid magic rule mask \""_L1 + QLatin1String(m_mask) + u'"';
return; return;
} }
const QByteArray &tempMask = QByteArray::fromHex(QByteArray::fromRawData( const QByteArray &tempMask = QByteArray::fromHex(QByteArray::fromRawData(
@@ -275,7 +277,7 @@ void MimeMagicRule::init(QString *errorString)
if (Q_UNLIKELY(tempMask.size() != m_pattern.size())) { if (Q_UNLIKELY(tempMask.size() != m_pattern.size())) {
m_type = Invalid; m_type = Invalid;
if (errorString) if (errorString)
*errorString = QLatin1String("Invalid magic rule mask size \"") + QLatin1String(m_mask) + QLatin1Char('"'); *errorString = "Invalid magic rule mask size \""_L1 + QLatin1String(m_mask) + u'"';
return; return;
} }
m_mask = tempMask; m_mask = tempMask;

View File

@@ -47,6 +47,8 @@ __attribute__((section(".qtmimedatabase"), aligned(4096)))
# endif # endif
#endif #endif
using namespace Qt::StringLiterals;
namespace Utils { namespace Utils {
MimeProviderBase::MimeProviderBase(MimeDatabasePrivate *db, const QString &directory) MimeProviderBase::MimeProviderBase(MimeDatabasePrivate *db, const QString &directory)
@@ -165,7 +167,7 @@ bool MimeBinaryProvider::checkCacheChanged()
void MimeBinaryProvider::ensureLoaded() void MimeBinaryProvider::ensureLoaded()
{ {
if (!m_cacheFile) { if (!m_cacheFile) {
const QString cacheFileName = m_directory + QLatin1String("/mime.cache"); const QString cacheFileName = m_directory + "/mime.cache"_L1;
m_cacheFile = new CacheFile(cacheFileName); m_cacheFile = new CacheFile(cacheFileName);
m_mimetypeListLoaded = false; m_mimetypeListLoaded = false;
m_mimetypeExtra.clear(); m_mimetypeExtra.clear();
@@ -313,7 +315,8 @@ bool MimeBinaryProvider::matchSuffixTree(MimeGlobMatchResult &result,
const bool caseSensitive = flagsAndWeight & 0x100; const bool caseSensitive = flagsAndWeight & 0x100;
if (caseSensitiveCheck || !caseSensitive) { if (caseSensitiveCheck || !caseSensitive) {
result.addMatch(QLatin1String(mimeType), weight, result.addMatch(QLatin1String(mimeType), weight,
QLatin1Char('*') + QStringView{fileName}.mid(charPos + 1), fileName.size() - charPos - 2); u'*' + QStringView{fileName}.mid(charPos + 1),
fileName.size() - charPos - 2);
success = true; success = true;
} }
} }
@@ -505,9 +508,9 @@ bool MimeBinaryProvider::loadMimeTypePrivate(MimeTypePrivate &data)
// load comment and globPatterns // load comment and globPatterns
// shared-mime-info since 1.3 lowercases the xml files // shared-mime-info since 1.3 lowercases the xml files
QString mimeFile = m_directory + QLatin1Char('/') + data.name.toLower() + QLatin1String(".xml"); QString mimeFile = m_directory + u'/' + data.name.toLower() + ".xml"_L1;
if (!QFileInfo::exists(mimeFile)) if (!QFileInfo::exists(mimeFile))
mimeFile = m_directory + QLatin1Char('/') + data.name + QLatin1String(".xml"); // pre-1.3 mimeFile = m_directory + u'/' + data.name + ".xml"_L1; // pre-1.3
QFile qfile(mimeFile); QFile qfile(mimeFile);
if (!qfile.open(QFile::ReadOnly)) if (!qfile.open(QFile::ReadOnly))
@@ -520,10 +523,10 @@ bool MimeBinaryProvider::loadMimeTypePrivate(MimeTypePrivate &data)
QXmlStreamReader xml(&qfile); QXmlStreamReader xml(&qfile);
if (xml.readNextStartElement()) { if (xml.readNextStartElement()) {
if (xml.name() != QLatin1String("mime-type")) { if (xml.name() != "mime-type"_L1) {
return false; return false;
} }
const auto name = xml.attributes().value(QLatin1String("type")); const auto name = xml.attributes().value("type"_L1);
if (name.isEmpty()) if (name.isEmpty())
return false; return false;
if (name.compare(data.name, Qt::CaseInsensitive)) if (name.compare(data.name, Qt::CaseInsensitive))
@@ -531,20 +534,20 @@ bool MimeBinaryProvider::loadMimeTypePrivate(MimeTypePrivate &data)
while (xml.readNextStartElement()) { while (xml.readNextStartElement()) {
const auto tag = xml.name(); const auto tag = xml.name();
if (tag == QLatin1String("comment")) { if (tag == "comment"_L1) {
QString lang = xml.attributes().value(QLatin1String("xml:lang")).toString(); QString lang = xml.attributes().value("xml:lang"_L1).toString();
const QString text = xml.readElementText(); const QString text = xml.readElementText();
if (lang.isEmpty()) { if (lang.isEmpty()) {
lang = QLatin1String("default"); // no locale attribute provided, treat it as default. lang = "default"_L1; // no locale attribute provided, treat it as default.
} }
extra.localeComments.insert(lang, text); extra.localeComments.insert(lang, text);
continue; // we called readElementText, so we're at the EndElement already. continue; // we called readElementText, so we're at the EndElement already.
} else if (tag == QLatin1String("glob-deleteall")) { // as written out by shared-mime-info >= 0.70 } else if (tag == "glob-deleteall"_L1) { // as written out by shared-mime-info >= 0.70
extra.globPatterns.clear(); extra.globPatterns.clear();
mainPattern.clear(); mainPattern.clear();
} else if (tag == QLatin1String("glob")) { // as written out by shared-mime-info >= 0.70 } else if (tag == "glob"_L1) { // as written out by shared-mime-info >= 0.70
const QString pattern = xml.attributes().value(QLatin1String("pattern")).toString(); const QString pattern = xml.attributes().value("pattern"_L1).toString();
if (mainPattern.isEmpty() && pattern.startsWith(QLatin1Char('*'))) { if (mainPattern.isEmpty() && pattern.startsWith(u'*')) {
mainPattern = pattern; mainPattern = pattern;
} }
if (!extra.globPatterns.contains(pattern)) if (!extra.globPatterns.contains(pattern))
@@ -552,7 +555,7 @@ bool MimeBinaryProvider::loadMimeTypePrivate(MimeTypePrivate &data)
} }
xml.skipCurrentElement(); xml.skipCurrentElement();
} }
Q_ASSERT(xml.name() == QLatin1String("mime-type")); Q_ASSERT(xml.name() == "mime-type"_L1);
} }
// Let's assume that shared-mime-info is at least version 0.70 // Let's assume that shared-mime-info is at least version 0.70
@@ -745,7 +748,7 @@ void MimeXMLProvider::ensureLoaded()
const QStringList files = dir.entryList(QDir::Files | QDir::NoDotAndDotDot); const QStringList files = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
allFiles.reserve(files.count()); allFiles.reserve(files.count());
for (const QString &xmlFile : files) for (const QString &xmlFile : files)
allFiles.append(packageDir + QLatin1Char('/') + xmlFile); allFiles.append(packageDir + u'/' + xmlFile);
if (m_allFiles == allFiles) if (m_allFiles == allFiles)
return; return;
@@ -775,7 +778,7 @@ bool MimeXMLProvider::load(const QString &fileName, QString *errorMessage)
QFile file(fileName); QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
if (errorMessage) if (errorMessage)
*errorMessage = QLatin1String("Cannot open ") + fileName + QLatin1String(": ") + file.errorString(); *errorMessage = "Cannot open "_L1 + fileName + ": "_L1 + file.errorString();
return false; return false;
} }

View File

@@ -16,14 +16,16 @@
#include <memory> #include <memory>
using namespace Qt::StringLiterals;
namespace Utils { namespace Utils {
static QString suffixFromPattern(const QString &pattern) static QString suffixFromPattern(const QString &pattern)
{ {
// Not a simple suffix if it looks like: README or *. or *.* or *.JP*G or *.JP? // Not a simple suffix if it looks like: README or *. or *.* or *.JP*G or *.JP?
if (pattern.startsWith(QLatin1String("*.")) && if (pattern.startsWith("*."_L1) &&
pattern.length() > 2 && pattern.length() > 2 &&
pattern.indexOf(QLatin1Char('*'), 2) < 0 && pattern.indexOf(QLatin1Char('?'), 2) < 0) { pattern.indexOf(u'*', 2) < 0 && pattern.indexOf(u'?', 2) < 0) {
return pattern.mid(2); return pattern.mid(2);
} }
return {}; return {};
@@ -233,13 +235,13 @@ QString MimeType::comment() const
QStringList languageList; QStringList languageList;
languageList << QLocale().name(); languageList << QLocale().name();
languageList << QLocale().uiLanguages(); languageList << QLocale().uiLanguages();
languageList << QLatin1String("default"); // use the default locale if possible. languageList << u"default"_qs; // use the default locale if possible.
for (const QString &language : std::as_const(languageList)) { for (const QString &language : std::as_const(languageList)) {
const QString lang = language == QLatin1String("C") ? QLatin1String("en_US") : language; const QString lang = language == "C"_L1 ? u"en_US"_qs : language;
const QString comm = d->localeComments.value(lang); const QString comm = d->localeComments.value(lang);
if (!comm.isEmpty()) if (!comm.isEmpty())
return comm; return comm;
const int pos = lang.indexOf(QLatin1Char('_')); const int pos = lang.indexOf(u'_');
if (pos != -1) { if (pos != -1) {
// "pt_BR" not found? try just "pt" // "pt_BR" not found? try just "pt"
const QString shortLang = lang.left(pos); const QString shortLang = lang.left(pos);
@@ -278,19 +280,19 @@ QString MimeType::genericIconName() const
// (i.e. "video-x-generic" in the previous example). // (i.e. "video-x-generic" in the previous example).
const QString group = name(); const QString group = name();
QStringView groupRef(group); QStringView groupRef(group);
const int slashindex = groupRef.indexOf(QLatin1Char('/')); const int slashindex = groupRef.indexOf(u'/');
if (slashindex != -1) if (slashindex != -1)
groupRef = groupRef.left(slashindex); groupRef = groupRef.left(slashindex);
return groupRef + QLatin1String("-x-generic"); return groupRef + "-x-generic"_L1;
} }
return d->genericIconName; return d->genericIconName;
} }
static QString make_default_icon_name_from_mimetype_name(QString iconName) static QString make_default_icon_name_from_mimetype_name(QString iconName)
{ {
const int slashindex = iconName.indexOf(QLatin1Char('/')); const int slashindex = iconName.indexOf(u'/');
if (slashindex != -1) if (slashindex != -1)
iconName[slashindex] = QLatin1Char('-'); iconName[slashindex] = u'-';
return iconName; return iconName;
} }
@@ -459,13 +461,13 @@ QString MimeType::filterString() const
QString filter; QString filter;
if (!d->globPatterns.empty()) { if (!d->globPatterns.empty()) {
filter += comment() + QLatin1String(" ("); filter += comment() + " ("_L1;
for (int i = 0; i < d->globPatterns.size(); ++i) { for (int i = 0; i < d->globPatterns.size(); ++i) {
if (i != 0) if (i != 0)
filter += QLatin1Char(' '); filter += u' ';
filter += d->globPatterns.at(i); filter += d->globPatterns.at(i);
} }
filter += QLatin1Char(')'); filter += u')';
} }
return filter; return filter;

View File

@@ -13,6 +13,8 @@
#include <QtCore/QXmlStreamWriter> #include <QtCore/QXmlStreamWriter>
#include <QtCore/QStack> #include <QtCore/QStack>
using namespace Qt::StringLiterals;
namespace Utils { namespace Utils {
// XML tags in MIME files // XML tags in MIME files
@@ -129,7 +131,7 @@ bool MimeTypeParserBase::parseNumber(QStringView n, int *target, QString *errorM
*target = n.toInt(&ok); *target = n.toInt(&ok);
if (Q_UNLIKELY(!ok)) { if (Q_UNLIKELY(!ok)) {
if (errorMessage) if (errorMessage)
*errorMessage = QLatin1String("Not a number '") + n + QLatin1String("'."); *errorMessage = "Not a number '"_L1 + n + "'."_L1;
return false; return false;
} }
return true; return true;
@@ -197,7 +199,7 @@ bool MimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
case ParseGlobPattern: { case ParseGlobPattern: {
const QString pattern = atts.value(QLatin1String(patternAttributeC)).toString(); const QString pattern = atts.value(QLatin1String(patternAttributeC)).toString();
unsigned weight = atts.value(QLatin1String(weightAttributeC)).toInt(); unsigned weight = atts.value(QLatin1String(weightAttributeC)).toInt();
const bool caseSensitive = atts.value(QLatin1String(caseSensitiveAttributeC)) == QLatin1String("true"); const bool caseSensitive = atts.value(QLatin1String(caseSensitiveAttributeC)) == "true"_L1;
if (weight == 0) if (weight == 0)
weight = MimeGlobPattern::DefaultWeight; weight = MimeGlobPattern::DefaultWeight;
@@ -261,7 +263,7 @@ bool MimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
break; break;
} }
case ParseError: case ParseError:
reader.raiseError(QLatin1String("Unexpected element <") + reader.name() + QLatin1Char('>')); reader.raiseError("Unexpected element <"_L1 + reader.name() + u'>');
break; break;
default: default:
break; break;