5#define QT_NO_CAST_FROM_ASCII
10#include <QtCore/QList>
11#include <QtCore/QDebug>
14#include <private/qoffsetstringarray_p.h>
15#include <private/qtools_p.h>
37 for (
int i = String;
i <=
Byte; ++
i) {
51 return m_type ==
other.m_type &&
52 m_value ==
other.m_value &&
53 m_startPos ==
other.m_startPos &&
54 m_endPos ==
other.m_endPos &&
55 m_mask ==
other.m_mask &&
56 m_pattern ==
other.m_pattern &&
57 m_number ==
other.m_number &&
58 m_numberMask ==
other.m_numberMask &&
59 m_matchFunction ==
other.m_matchFunction;
64 qsizetype valueLength,
const char *valueData,
const char *
mask)
74 for (
int i = rangeStart;
i < rangeStart + rangeLength; ++
i) {
78 if (memcmp(valueData, dataPtr +
i, valueLength) == 0) {
87 const char *readDataBase = dataPtr + rangeStart;
92 const qsizetype maxStartPos = dataNeeded - valueLength + 1;
93 for (
int i = 0;
i < maxStartPos; ++
i) {
94 const char *
d = readDataBase +
i;
96 for (
int idx = 0; idx < valueLength; ++idx) {
97 if (((*
d++) &
mask[idx]) != (valueData[idx] &
mask[idx])) {
114 const int rangeLength = m_endPos - m_startPos + 1;
121 const T
value(m_number);
122 const T
mask(m_numberMask);
127 const char *
p =
data.constData() + m_startPos;
128 const char *e =
data.constData() +
qMin(
data.size() -
int(
sizeof(T)), m_endPos);
129 for ( ;
p <= e; ++
p) {
142 const char *
p =
value.constData();
143 const char *e =
p +
value.size();
144 for ( ;
p < e; ++
p) {
145 if (*
p ==
'\\' && ++
p < e) {
148 for (
int i = 0;
i < 2 &&
p + 1 < e; ++
i) {
159 c = (
c << 3) + *(++
p) -
'0';
161 c = (
c << 3) + *(++
p) -
'0';
164 }
else if (*
p ==
'n') {
166 }
else if (*
p ==
'r') {
168 }
else if (*
p ==
't') {
198 *errorString =
"Type "_L1 +
type +
" is not supported"_L1;
225 *errorString =
"Invalid magic rule value \""_L1 +
QLatin1StringView(m_value) + u
'"';
239 *errorString =
"Invalid magic rule mask \""_L1 +
QLatin1StringView(m_mask) + u
'"';
247 *errorString =
"Invalid magic rule mask size \""_L1 +
QLatin1StringView(m_mask) + u
'"';
252 m_mask.
fill(
char(-1), m_pattern.
size());
255 m_matchFunction = &QMimeMagicRule::matchString;
258 if (m_number <=
quint8(-1)) {
259 if (m_numberMask == 0)
260 m_numberMask =
quint8(-1);
261 m_matchFunction = &QMimeMagicRule::matchNumber<quint8>;
267 m_number = m_type ==
Little16 ? qFromLittleEndian<quint16>(m_number) : qFromBigEndian<quint16>(m_number);
268 if (m_numberMask != 0)
269 m_numberMask = m_type ==
Little16 ? qFromLittleEndian<quint16>(m_numberMask) : qFromBigEndian<quint16>(m_numberMask);
274 if (m_numberMask == 0)
276 m_matchFunction = &QMimeMagicRule::matchNumber<quint16>;
281 m_number = m_type ==
Little32 ? qFromLittleEndian<quint32>(m_number) : qFromBigEndian<quint32>(m_number);
282 if (m_numberMask != 0)
283 m_numberMask = m_type ==
Little32 ? qFromLittleEndian<quint32>(m_numberMask) : qFromBigEndian<quint32>(m_numberMask);
286 if (m_numberMask == 0)
288 m_matchFunction = &QMimeMagicRule::matchNumber<quint32>;
298 if (m_type == String) {
307 const bool ok = m_matchFunction && (this->*m_matchFunction)(
data);
319 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
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)