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
qmimemagicrule_p.h
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#ifndef QMIMEMAGICRULE_P_H
6#define QMIMEMAGICRULE_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/private/qglobal_p.h>
20
22
23#include <QtCore/qbytearray.h>
24#include <QtCore/qscopedpointer.h>
25#include <QtCore/qlist.h>
26
27QT_BEGIN_NAMESPACE
28
29class QMimeMagicRule
30{
31public:
32 enum Type { Invalid = 0, String, Host16, Host32, Big16, Big32, Little16, Little32, Byte };
33
34 QMimeMagicRule(const QString &typeStr, const QByteArray &value, const QString &offsets,
35 const QByteArray &mask, QString *errorString);
36
37 void swap(QMimeMagicRule &other) noexcept
38 {
39 qSwap(m_type, other.m_type);
40 qSwap(m_value, other.m_value);
41 qSwap(m_startPos, other.m_startPos);
42 qSwap(m_endPos, other.m_endPos);
43 qSwap(m_mask, other.m_mask);
44 qSwap(m_pattern, other.m_pattern);
45 qSwap(m_number, other.m_number);
46 qSwap(m_numberMask, other.m_numberMask);
47 qSwap(m_matchFunction, other.m_matchFunction);
48 }
49
50 bool operator==(const QMimeMagicRule &other) const;
51
52 Type type() const { return m_type; }
53 QByteArray value() const { return m_value; }
54 int startPos() const { return m_startPos; }
55 int endPos() const { return m_endPos; }
56 QByteArray mask() const;
57
58 bool isValid() const { return m_matchFunction != nullptr; }
59
60 bool matches(const QByteArray &data) const;
61
62 QList<QMimeMagicRule> m_subMatches;
63
64 static Type type(const QByteArray &type);
65 static QByteArray typeName(Type type);
66
67 static bool matchSubstring(const char *dataPtr, qsizetype dataSize, int rangeStart,
68 int rangeLength, qsizetype valueLength, const char *valueData,
69 const char *mask);
70
71private:
72 Type m_type;
73 QByteArray m_value;
74 int m_startPos;
75 int m_endPos;
76 QByteArray m_mask;
77
78 QByteArray m_pattern;
79 quint32 m_number;
80 quint32 m_numberMask;
81
82 typedef bool (QMimeMagicRule::*MatchFunction)(const QByteArray &data) const;
83 MatchFunction m_matchFunction;
84
85private:
86 // match functions
87 bool matchString(const QByteArray &data) const;
88 template <typename T>
89 bool matchNumber(const QByteArray &data) const;
90};
91Q_DECLARE_SHARED(QMimeMagicRule)
92
93QT_END_NAMESPACE
94
95#endif // QMIMEMAGICRULE_H
QT_REQUIRE_CONFIG(mimetype)
static QByteArray makePattern(const QByteArray &value)
static constexpr auto magicRuleTypes