5#define QT_NO_CAST_FROM_ASCII
10#include <QtCore/QList>
12#include <QtCore/QDebug>
15#include <private/qoffsetstringarray_p.h>
16#include <private/qtools_p.h>
52 return m_type ==
other.m_type &&
53 m_value ==
other.m_value &&
54 m_startPos ==
other.m_startPos &&
55 m_endPos ==
other.m_endPos &&
56 m_mask ==
other.m_mask &&
57 m_pattern ==
other.m_pattern &&
58 m_number ==
other.m_number &&
59 m_numberMask ==
other.m_numberMask &&
60 m_matchFunction ==
other.m_matchFunction;
65 qsizetype valueLength,
const char *valueData,
const char *
mask)
75 for (
int i = rangeStart;
i < rangeStart + rangeLength; ++
i) {
79 if (memcmp(valueData, dataPtr +
i, valueLength) == 0) {
88 const char *readDataBase = dataPtr + rangeStart;
93 const qsizetype maxStartPos = dataNeeded - valueLength + 1;
94 for (
int i = 0;
i < maxStartPos; ++
i) {
95 const char *
d = readDataBase +
i;
97 for (
int idx = 0; idx < valueLength; ++idx) {
98 if (((*
d++) &
mask[idx]) != (valueData[idx] &
mask[idx])) {
115 const int rangeLength = m_endPos - m_startPos + 1;
122 const T
value(m_number);
123 const T
mask(m_numberMask);
128 const char *
p =
data.constData() + m_startPos;
129 const char *
e =
data.constData() +
qMin(
data.size() -
int(
sizeof(T)), m_endPos);
130 for ( ;
p <=
e; ++
p) {
143 const char *
p =
value.constData();
144 const char *
e =
p +
value.size();
145 for ( ;
p <
e; ++
p) {
146 if (*
p ==
'\\' && ++
p <
e) {
149 for (
int i = 0;
i < 2 &&
p + 1 <
e; ++
i) {
160 c = (
c << 3) + *(++
p) -
'0';
162 c = (
c << 3) + *(++
p) -
'0';
165 }
else if (*
p ==
'n') {
167 }
else if (*
p ==
'r') {
169 }
else if (*
p ==
't') {
199 *errorString =
"Type "_L1 +
type +
" is not supported"_L1;
226 *errorString =
"Invalid magic rule value \""_L1 +
QLatin1StringView(m_value) + u
'"';
240 *errorString =
"Invalid magic rule mask \""_L1 +
QLatin1StringView(m_mask) + u
'"';
248 *errorString =
"Invalid magic rule mask size \""_L1 +
QLatin1StringView(m_mask) + u
'"';
253 m_mask.
fill(
char(-1), m_pattern.
size());
256 m_matchFunction = &QMimeMagicRule::matchString;
259 if (m_number <=
quint8(-1)) {
260 if (m_numberMask == 0)
261 m_numberMask =
quint8(-1);
262 m_matchFunction = &QMimeMagicRule::matchNumber<quint8>;
268 m_number = m_type ==
Little16 ? qFromLittleEndian<quint16>(m_number) : qFromBigEndian<quint16>(m_number);
269 if (m_numberMask != 0)
270 m_numberMask = m_type ==
Little16 ? qFromLittleEndian<quint16>(m_numberMask) : qFromBigEndian<quint16>(m_numberMask);
275 if (m_numberMask == 0)
277 m_matchFunction = &QMimeMagicRule::matchNumber<quint16>;
282 m_number = m_type ==
Little32 ? qFromLittleEndian<quint32>(m_number) : qFromBigEndian<quint32>(m_number);
283 if (m_numberMask != 0)
284 m_numberMask = m_type ==
Little32 ? qFromLittleEndian<quint32>(m_numberMask) : qFromBigEndian<quint32>(m_numberMask);
287 if (m_numberMask == 0)
289 m_matchFunction = &QMimeMagicRule::matchNumber<quint32>;
308 const bool ok = m_matchFunction && (this->*m_matchFunction)(
data);
320 if ((*it).matches(
data)) {
uint toUInt(bool *ok=nullptr, int base=10) const
Returns the byte array converted to an {unsigned int} using base base, which is ten by default.
QByteArray & fill(char c, qsizetype size=-1)
Sets every byte in the byte array to ch.
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
static QByteArray fromHex(const QByteArray &hexEncoded)
Returns a decoded copy of the hex encoded array hexEncoded.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
bool startsWith(QByteArrayView bv) const
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
void squeeze()
Releases any memory not required to store the array's data.
QByteArray toHex(char separator='\0') const
Returns a hex encoded copy of the byte array.
static QByteArray fromRawData(const char *data, qsizetype size)
Constructs a QByteArray that uses the first size bytes of the data array.
bool isEmpty() const noexcept
static QByteArray typeName(Type type)
QList< QMimeMagicRule > m_subMatches
static bool matchSubstring(const char *dataPtr, qsizetype dataSize, int rangeStart, int rangeLength, qsizetype valueLength, const char *valueData, const char *mask)
bool matches(const QByteArray &data) const
bool operator==(const QMimeMagicRule &other) const
QMimeMagicRule(const QString &typeStr, const QByteArray &value, const QString &offsets, const QByteArray &mask, QString *errorString)
static bool parseNumber(QStringView n, int *target, QString *errorMessage)
constexpr QStringView mid(qsizetype pos, qsizetype n=-1) const noexcept
Returns the substring of length length starting at position start in this object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QSet< QString >::iterator it
Combined button and popup list for selecting options.
constexpr bool isOctalDigit(char32_t c) noexcept
constexpr int fromHex(char32_t c) noexcept
constexpr Initialization Uninitialized
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static QByteArray makePattern(const QByteArray &value)
static constexpr auto magicRuleTypes
constexpr const T & qMin(const T &a, const T &b)
constexpr auto qOffsetStringArray(const char(&...strings)[Nx]) noexcept
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLfloat GLfloat GLfloat GLfloat h
GLuint GLsizei const GLuint const GLintptr * offsets
#define QStringLiteral(str)