Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qmimemagicrulematcher.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
define
QT_NO_CAST_FROM_ASCII
6
7
#
include
"qmimemagicrulematcher_p.h"
8
9
#
include
"qmimetype_p.h"
10
11
QT_BEGIN_NAMESPACE
12
13
/*!
14
\internal
15
\class QMimeMagicRuleMatcher
16
\inmodule QtCore
17
18
\brief The QMimeMagicRuleMatcher class checks a number of rules based on operator "or".
19
20
It is used for rules parsed from XML files.
21
22
\sa QMimeType, QMimeDatabase, MagicRule, MagicStringRule, MagicByteRule, GlobPattern
23
\sa QMimeTypeParserBase, MimeTypeParser
24
*/
25
26
QMimeMagicRuleMatcher::QMimeMagicRuleMatcher(
const
QString &mime,
unsigned
thePriority) :
27
m_list(),
28
m_priority(thePriority),
29
m_mimetype(mime)
30
{
31
}
32
33
bool
QMimeMagicRuleMatcher::operator==(
const
QMimeMagicRuleMatcher &other)
const
34
{
35
return
m_list == other.m_list &&
36
m_priority == other.m_priority;
37
}
38
39
void
QMimeMagicRuleMatcher::addRule(
const
QMimeMagicRule &rule)
40
{
41
m_list.append(rule);
42
}
43
44
void
QMimeMagicRuleMatcher::addRules(
const
QList<QMimeMagicRule> &rules)
45
{
46
m_list.append(rules);
47
}
48
49
QList<QMimeMagicRule> QMimeMagicRuleMatcher::magicRules()
const
50
{
51
return
m_list;
52
}
53
54
// Check for a match on contents of a file
55
bool
QMimeMagicRuleMatcher::matches(
const
QByteArray &data)
const
56
{
57
for
(
const
QMimeMagicRule &magicRule : m_list) {
58
if
(magicRule.matches(data))
59
return
true
;
60
}
61
62
return
false
;
63
}
64
65
// Return a priority value from 1..100
66
unsigned
QMimeMagicRuleMatcher::priority()
const
67
{
68
return
m_priority;
69
}
70
71
QT_END_NAMESPACE
QPlatformGraphicsBufferHelper
\inmodule QtGui
qtbase
src
corelib
mimetypes
qmimemagicrulematcher.cpp
Generated on
for Qt by
1.14.0