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 | |
4 | #define QT_NO_CAST_FROM_ASCII |
5 | |
6 | #include "qmimemagicrulematcher_p.h" |
7 | |
8 | #include "qmimetype_p.h" |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | /*! |
13 | \internal |
14 | \class QMimeMagicRuleMatcher |
15 | \inmodule QtCore |
16 | |
17 | \brief The QMimeMagicRuleMatcher class checks a number of rules based on operator "or". |
18 | |
19 | It is used for rules parsed from XML files. |
20 | |
21 | \sa QMimeType, QMimeDatabase, MagicRule, MagicStringRule, MagicByteRule, GlobPattern |
22 | \sa QMimeTypeParserBase, MimeTypeParser |
23 | */ |
24 | |
25 | QMimeMagicRuleMatcher::QMimeMagicRuleMatcher(const QString &mime, unsigned thePriority) : |
26 | m_list(), |
27 | m_priority(thePriority), |
28 | m_mimetype(mime) |
29 | { |
30 | } |
31 | |
32 | bool QMimeMagicRuleMatcher::operator==(const QMimeMagicRuleMatcher &other) const |
33 | { |
34 | return m_list == other.m_list && |
35 | m_priority == other.m_priority; |
36 | } |
37 | |
38 | void QMimeMagicRuleMatcher::addRule(const QMimeMagicRule &rule) |
39 | { |
40 | m_list.append(t: rule); |
41 | } |
42 | |
43 | void QMimeMagicRuleMatcher::addRules(const QList<QMimeMagicRule> &rules) |
44 | { |
45 | m_list.append(l: rules); |
46 | } |
47 | |
48 | QList<QMimeMagicRule> QMimeMagicRuleMatcher::magicRules() const |
49 | { |
50 | return m_list; |
51 | } |
52 | |
53 | // Check for a match on contents of a file |
54 | bool QMimeMagicRuleMatcher::matches(const QByteArray &data) const |
55 | { |
56 | for (const QMimeMagicRule &magicRule : m_list) { |
57 | if (magicRule.matches(data)) |
58 | return true; |
59 | } |
60 | |
61 | return false; |
62 | } |
63 | |
64 | // Return a priority value from 1..100 |
65 | unsigned QMimeMagicRuleMatcher::priority() const |
66 | { |
67 | return m_priority; |
68 | } |
69 | |
70 | QT_END_NAMESPACE |
71 |