50 int l =
qMin(len, 255);
51 memset(skiptable, l, 256*
sizeof(
uchar));
58 const uchar *skiptable)
61 return index > l ? -1 :
index;
62 const uint pl_minus_one = pl - 1;
64 register const uchar *current = cc + index + pl_minus_one;
66 while (current < end) {
67 uint skip = skiptable[*current];
71 if (*(current - skip) != puc[pl_minus_one - skip])
75 if (skip > pl_minus_one)
76 return (current - cc) - skip + 1;
80 if (skiptable[*(current - skip)] == pl)
85 if (current > end - skip)
177 memcpy(&
p, &other.
p,
sizeof(
p));
221 return bm_find(reinterpret_cast<const uchar *>(str), len, from,
238 static int findChar(
const char *str,
int len,
char ch,
int from)
243 from =
qMax(from + len, 0);
245 const uchar *n = s + from - 1;
246 const uchar *e = s + len;
257 const char *haystack,
int haystackLen,
int haystackOffset,
258 const char *needle,
int needleLen)
260 uchar skiptable[256];
262 if (haystackOffset < 0)
264 return bm_find((
const uchar *)haystack, haystackLen, haystackOffset,
265 (
const uchar *)needle, needleLen, skiptable);
269 if (sl_minus_1 < sizeof(uint) * CHAR_BIT) \ 270 hashHaystack -= (a) << sl_minus_1; \ 276 const char *haystack0,
int haystackLen,
int from,
277 const char *needle,
int needleLen)
279 const int l = haystackLen;
280 const int sl = needleLen;
291 return findChar(haystack0, haystackLen, needle[0], from);
298 if (l > 500 && sl > 5)
307 const char *haystack = haystack0 + from;
308 const char *
end = haystack0 + (l - sl);
309 const uint sl_minus_1 = sl - 1;
310 uint hashNeedle = 0, hashHaystack = 0;
312 for (idx = 0; idx < sl; ++idx) {
313 hashNeedle = ((hashNeedle<<1) + needle[idx]);
314 hashHaystack = ((hashHaystack<<1) + haystack[idx]);
316 hashHaystack -= *(haystack + sl_minus_1);
318 while (haystack <= end) {
319 hashHaystack += *(haystack + sl_minus_1);
320 if (hashHaystack == hashNeedle && *needle == *haystack
321 && memcmp(needle, haystack, sl) == 0)
322 return haystack - haystack0;
~QByteArrayMatcher()
Destroys the byte array matcher.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
static int bm_find(const uchar *cc, int l, int index, const uchar *puc, uint pl, const uchar *skiptable)
#define QT_END_NAMESPACE
This macro expands to.
The QByteArray class provides an array of bytes.
void setPattern(const QByteArray &pattern)
Sets the byte array that this byte array matcher will search for to pattern.
QByteArrayMatcher & operator=(const QByteArrayMatcher &other)
Assigns the other byte array matcher to this byte array matcher.
static int findChar(const char *str, int len, char ch, int from)
static void bm_init_skiptable(const uchar *cc, int len, uchar *skiptable)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
QByteArrayMatcher()
Constructs an empty byte array matcher that won't match anything.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QByteArrayMatcherPrivate * d
static int qFindByteArrayBoyerMoore(const char *haystack, int haystackLen, int haystackOffset, const char *needle, int needleLen)
The QByteArrayMatcher class holds a sequence of bytes that can be quickly matched in a byte array...
int length() const
Same as size().
const char * constData() const
Returns a pointer to the data stored in the byte array.
void * qMemSet(void *dest, int c, size_t n)
int qFindByteArray(const char *haystack0, int haystackLen, int from, const char *needle, int needleLen)
int size() const
Returns the number of bytes in this byte array.
QByteArray pattern() const
Returns the byte array pattern that this byte array matcher will search for.
static const KeyPair *const end
int indexIn(const QByteArray &ba, int from=0) const
Searches the byte array ba, from byte position from (default 0, i.e.