forked from qt-creator/qt-creator
Update mime database from Qt
qtbase/c1e1d133c47f6cbeee045dcec0dfe7c68d5bef34 mimetypes/: port to qsizetype Change-Id: I4ec76cc3af25efdadd31cb6d58235f0a55bf321a Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -735,7 +735,7 @@ QList<MimeType> MimeDatabase::mimeTypesForFileName(const QString &fileName) cons
|
||||
QString MimeDatabase::suffixForFileName(const QString &fileName) const
|
||||
{
|
||||
QMutexLocker locker(&d->mutex);
|
||||
const int suffixLength = d->findByFileName(fileName).m_knownSuffixLength;
|
||||
const qsizetype suffixLength = d->findByFileName(fileName).m_knownSuffixLength;
|
||||
return fileName.right(suffixLength);
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,8 @@ namespace Utils {
|
||||
Handles glob weights, and preferring longer matches over shorter matches.
|
||||
*/
|
||||
|
||||
void MimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const QString &pattern, int knownSuffixLength)
|
||||
void MimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const QString &pattern,
|
||||
qsizetype knownSuffixLength)
|
||||
{
|
||||
if (m_allMatchingMimeTypes.contains(mimeType))
|
||||
return;
|
||||
@@ -59,11 +60,11 @@ void MimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const QS
|
||||
|
||||
MimeGlobPattern::PatternType MimeGlobPattern::detectPatternType(const QString &pattern) const
|
||||
{
|
||||
const int patternLength = pattern.size();
|
||||
const qsizetype patternLength = pattern.size();
|
||||
if (!patternLength)
|
||||
return OtherPattern;
|
||||
|
||||
const int starCount = pattern.count(u'*');
|
||||
const qsizetype starCount = pattern.count(u'*');
|
||||
const bool hasSquareBracket = pattern.indexOf(u'[') != -1;
|
||||
const bool hasQuestionMark = pattern.indexOf(u'?') != -1;
|
||||
|
||||
@@ -108,10 +109,10 @@ bool MimeGlobPattern::matchFileName(const QString &inputFileName) const
|
||||
const QString fileName = m_caseSensitivity == Qt::CaseInsensitive
|
||||
? inputFileName.toLower() : inputFileName;
|
||||
|
||||
const int patternLength = m_pattern.size();
|
||||
const qsizetype patternLength = m_pattern.size();
|
||||
if (!patternLength)
|
||||
return false;
|
||||
const int fileNameLength = fileName.size();
|
||||
const qsizetype fileNameLength = fileName.size();
|
||||
|
||||
switch (m_patternType) {
|
||||
case SuffixPattern: {
|
||||
@@ -224,16 +225,12 @@ void MimeGlobPatternList::match(MimeGlobMatchResult &result,
|
||||
const QString &fileName,
|
||||
const QSet<QString> &ignoreMimeTypes) const
|
||||
{
|
||||
|
||||
MimeGlobPatternList::const_iterator it = this->constBegin();
|
||||
const MimeGlobPatternList::const_iterator endIt = this->constEnd();
|
||||
for (; it != endIt; ++it) {
|
||||
const MimeGlobPattern &glob = *it;
|
||||
for (const MimeGlobPattern &glob : *this) {
|
||||
if (ignoreMimeTypes.contains(glob.mimeType()))
|
||||
continue;
|
||||
if (glob.matchFileName(fileName)) {
|
||||
const QString pattern = glob.pattern();
|
||||
const int suffixLen = isSimplePattern(pattern) ? pattern.size() - 2 : 0;
|
||||
const qsizetype suffixLen = isSimplePattern(pattern) ? pattern.size() - strlen("*.") : 0;
|
||||
result.addMatch(glob.mimeType(), glob.weight(), pattern, suffixLen);
|
||||
}
|
||||
}
|
||||
@@ -248,9 +245,9 @@ void MimeAllGlobPatterns::matchingGlobs(const QString &fileName,
|
||||
|
||||
// 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)
|
||||
const int lastDot = fileName.lastIndexOf(u'.');
|
||||
const qsizetype lastDot = fileName.lastIndexOf(u'.');
|
||||
if (lastDot != -1) { // if no '.', skip the extension lookup
|
||||
const int ext_len = fileName.length() - lastDot - 1;
|
||||
const qsizetype ext_len = fileName.length() - lastDot - 1;
|
||||
const QString simpleExtension = fileName.right(ext_len).toLower();
|
||||
// (toLower because fast patterns are always case-insensitive and saved as lowercase)
|
||||
|
||||
|
@@ -21,13 +21,14 @@ namespace Utils {
|
||||
|
||||
struct MimeGlobMatchResult
|
||||
{
|
||||
void addMatch(const QString &mimeType, int weight, const QString &pattern, int knownSuffixLength = 0);
|
||||
void addMatch(const QString &mimeType, int weight, const QString &pattern,
|
||||
qsizetype knownSuffixLength = 0);
|
||||
|
||||
QStringList m_matchingMimeTypes; // only those with highest weight
|
||||
QStringList m_allMatchingMimeTypes;
|
||||
int m_weight = 0;
|
||||
int m_matchingPatternLength = 0;
|
||||
int m_knownSuffixLength = 0;
|
||||
qsizetype m_matchingPatternLength = 0;
|
||||
qsizetype m_knownSuffixLength = 0;
|
||||
};
|
||||
|
||||
class MimeGlobPattern
|
||||
|
@@ -73,12 +73,12 @@ bool MimeMagicRule::operator==(const MimeMagicRule &other) const
|
||||
}
|
||||
|
||||
// Used by both providers
|
||||
bool MimeMagicRule::matchSubstring(const char *dataPtr, int dataSize, int rangeStart, int rangeLength,
|
||||
int valueLength, const char *valueData, const char *mask)
|
||||
bool MimeMagicRule::matchSubstring(const char *dataPtr, qsizetype dataSize, int rangeStart, int rangeLength,
|
||||
qsizetype valueLength, const char *valueData, const char *mask)
|
||||
{
|
||||
// Size of searched data.
|
||||
// Example: value="ABC", rangeLength=3 -> we need 3+3-1=5 bytes (ABCxx,xABCx,xxABC would match)
|
||||
const int dataNeeded = qMin(rangeLength + valueLength - 1, dataSize - rangeStart);
|
||||
const qsizetype dataNeeded = qMin(rangeLength + valueLength - 1, dataSize - rangeStart);
|
||||
|
||||
if (!mask) {
|
||||
// callgrind says QByteArray::indexOf is much slower, since our strings are typically too
|
||||
@@ -102,7 +102,7 @@ bool MimeMagicRule::matchSubstring(const char *dataPtr, int dataSize, int rangeS
|
||||
// deviceSize is 4, so dataNeeded was max'ed to 4.
|
||||
// maxStartPos = 4 - 3 + 1 = 2, and indeed
|
||||
// we need to check for a match a positions 0 and 1 (ABCx and xABC).
|
||||
const int maxStartPos = dataNeeded - valueLength + 1;
|
||||
const qsizetype maxStartPos = dataNeeded - valueLength + 1;
|
||||
for (int i = 0; i < maxStartPos; ++i) {
|
||||
const char *d = readDataBase + i;
|
||||
bool valid = true;
|
||||
@@ -235,7 +235,7 @@ MimeMagicRule::MimeMagicRule(const QString &type,
|
||||
*errorString = "Type "_L1 + type + " is not supported"_L1;
|
||||
|
||||
// Parse for offset as "1" or "1:10"
|
||||
const int colonIndex = offsets.indexOf(u':');
|
||||
const qsizetype colonIndex = offsets.indexOf(u':');
|
||||
const QStringView startPosStr
|
||||
= QStringView(offsets).mid(0, colonIndex); // \ These decay to returning 'offsets'
|
||||
const QStringView endPosStr = QStringView(offsets)
|
||||
|
@@ -75,7 +75,9 @@ public:
|
||||
static Type type(const QByteArray &type);
|
||||
static QByteArray typeName(Type type);
|
||||
|
||||
static bool matchSubstring(const char *dataPtr, int dataSize, int rangeStart, int rangeLength, int valueLength, const char *valueData, const char *mask);
|
||||
static bool matchSubstring(const char *dataPtr, qsizetype dataSize, int rangeStart,
|
||||
int rangeLength, qsizetype valueLength, const char *valueData,
|
||||
const char *mask);
|
||||
|
||||
private:
|
||||
// added for Qt Creator
|
||||
|
@@ -273,7 +273,7 @@ bool MimeBinaryProvider::matchSuffixTree(MimeGlobMatchResult &result,
|
||||
int numEntries,
|
||||
int firstOffset,
|
||||
const QString &fileName,
|
||||
int charPos,
|
||||
qsizetype charPos,
|
||||
bool caseSensitiveCheck)
|
||||
{
|
||||
QChar fileChar = fileName[charPos];
|
||||
@@ -330,7 +330,7 @@ bool MimeBinaryProvider::matchSuffixTree(MimeGlobMatchResult &result,
|
||||
bool MimeBinaryProvider::matchMagicRule(MimeBinaryProvider::CacheFile *cacheFile, int numMatchlets, int firstOffset, const QByteArray &data)
|
||||
{
|
||||
const char *dataPtr = data.constData();
|
||||
const int dataSize = data.size();
|
||||
const qsizetype dataSize = data.size();
|
||||
for (int matchlet = 0; matchlet < numMatchlets; ++matchlet) {
|
||||
const int off = firstOffset + matchlet * 32;
|
||||
const int rangeStart = cacheFile->getUint32(off);
|
||||
|
@@ -105,7 +105,7 @@ private:
|
||||
int numEntries,
|
||||
int firstOffset,
|
||||
const QString &fileName,
|
||||
int charPos,
|
||||
qsizetype charPos,
|
||||
bool caseSensitiveCheck);
|
||||
bool matchMagicRule(CacheFile *cacheFile, int numMatchlets, int firstOffset, const QByteArray &data);
|
||||
QLatin1StringView iconForMime(CacheFile *cacheFile, int posListOffset, const QByteArray &inputMime);
|
||||
|
Reference in New Issue
Block a user