Qt 4.8
Classes | Public Functions | Properties | List of all members
QByteArrayMatcher Class Reference

The QByteArrayMatcher class holds a sequence of bytes that can be quickly matched in a byte array. More...

#include <qbytearraymatcher.h>

Classes

struct  Data
 

Public Functions

int indexIn (const QByteArray &ba, int from=0) const
 Searches the byte array ba, from byte position from (default 0, i.e. More...
 
int indexIn (const char *str, int len, int from=0) const
 Searches the char string str, which has length len, from byte position from (default 0, i.e. More...
 
QByteArrayMatcheroperator= (const QByteArrayMatcher &other)
 Assigns the other byte array matcher to this byte array matcher. More...
 
QByteArray pattern () const
 Returns the byte array pattern that this byte array matcher will search for. More...
 
 QByteArrayMatcher ()
 Constructs an empty byte array matcher that won't match anything. More...
 
 QByteArrayMatcher (const QByteArray &pattern)
 Constructs a byte array matcher that will search for pattern. More...
 
 QByteArrayMatcher (const char *pattern, int length)
 Constructs a byte array matcher from pattern. More...
 
 QByteArrayMatcher (const QByteArrayMatcher &other)
 Copies the other byte array matcher to this byte array matcher. More...
 
void setPattern (const QByteArray &pattern)
 Sets the byte array that this byte array matcher will search for to pattern. More...
 
 ~QByteArrayMatcher ()
 Destroys the byte array matcher. More...
 

Properties

union {
   uint   dummy [256]
 
   Data   p
 
}; 
 
QByteArrayMatcherPrivate * d
 
QByteArray q_pattern
 

Detailed Description

The QByteArrayMatcher class holds a sequence of bytes that can be quickly matched in a byte array.

This class is useful when you have a sequence of bytes that you want to repeatedly match against some byte arrays (perhaps in a loop), or when you want to search for the same sequence of bytes multiple times in the same byte array. Using a matcher object and indexIn() is faster than matching a plain QByteArray with QByteArray::indexOf() if repeated matching takes place. This class offers no benefit if you are doing one-off byte array matches.

Create the QByteArrayMatcher with the QByteArray you want to search for. Then call indexIn() on the QByteArray that you want to search.

See also
QByteArray, QStringMatcher

Definition at line 55 of file qbytearraymatcher.h.

Constructors and Destructors

◆ QByteArrayMatcher() [1/4]

QByteArrayMatcher::QByteArrayMatcher ( )

Constructs an empty byte array matcher that won't match anything.

Call setPattern() to give it a pattern to match.

Definition at line 122 of file qbytearraymatcher.cpp.

123  : d(0)
124 {
125  p.p = 0;
126  p.l = 0;
127  qMemSet(p.q_skiptable, 0, sizeof(p.q_skiptable));
128 }
QByteArrayMatcherPrivate * d
void * qMemSet(void *dest, int c, size_t n)
Definition: qglobal.cpp:2509

◆ QByteArrayMatcher() [2/4]

QByteArrayMatcher::QByteArrayMatcher ( const QByteArray pattern)
explicit

Constructs a byte array matcher that will search for pattern.

Call indexIn() to perform a search.

Definition at line 147 of file qbytearraymatcher.cpp.

148  : d(0), q_pattern(pattern)
149 {
150  p.p = reinterpret_cast<const uchar *>(pattern.constData());
151  p.l = pattern.size();
153 }
static void bm_init_skiptable(const uchar *cc, int len, uchar *skiptable)
unsigned char uchar
Definition: qglobal.h:994
QByteArrayMatcherPrivate * d
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402

◆ QByteArrayMatcher() [3/4]

QByteArrayMatcher::QByteArrayMatcher ( const char *  pattern,
int  length 
)
explicit

Constructs a byte array matcher from pattern.

pattern has the given length. pattern must remain in scope, but the destructor does not delete pattern.

Definition at line 135 of file qbytearraymatcher.cpp.

136  : d(0)
137 {
138  p.p = reinterpret_cast<const uchar *>(pattern);
139  p.l = length;
141 }
static void bm_init_skiptable(const uchar *cc, int len, uchar *skiptable)
unsigned char uchar
Definition: qglobal.h:994
QByteArrayMatcherPrivate * d
QByteArray pattern() const
Returns the byte array pattern that this byte array matcher will search for.

◆ QByteArrayMatcher() [4/4]

QByteArrayMatcher::QByteArrayMatcher ( const QByteArrayMatcher other)

Copies the other byte array matcher to this byte array matcher.

Definition at line 158 of file qbytearraymatcher.cpp.

159  : d(0)
160 {
161  operator=(other);
162 }
QByteArrayMatcher & operator=(const QByteArrayMatcher &other)
Assigns the other byte array matcher to this byte array matcher.
QByteArrayMatcherPrivate * d

◆ ~QByteArrayMatcher()

QByteArrayMatcher::~QByteArrayMatcher ( )

Destroys the byte array matcher.

Definition at line 167 of file qbytearraymatcher.cpp.

168 {
169 }

Functions

◆ indexIn() [1/2]

int QByteArrayMatcher::indexIn ( const QByteArray ba,
int  from = 0 
) const

Searches the byte array ba, from byte position from (default 0, i.e.

from the first byte), for the byte array pattern() that was set in the constructor or in the most recent call to setPattern(). Returns the position where the pattern() matched in ba, or -1 if no match was found.

Definition at line 202 of file qbytearraymatcher.cpp.

Referenced by QByteArray::count(), QHttpNetworkReplyPrivate::parseHeader(), and QByteArray::replace().

203 {
204  if (from < 0)
205  from = 0;
206  return bm_find(reinterpret_cast<const uchar *>(ba.constData()), ba.size(), from,
207  p.p, p.l, p.q_skiptable);
208 }
static int bm_find(const uchar *cc, int l, int index, const uchar *puc, uint pl, const uchar *skiptable)
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402

◆ indexIn() [2/2]

int QByteArrayMatcher::indexIn ( const char *  str,
int  len,
int  from = 0 
) const

Searches the char string str, which has length len, from byte position from (default 0, i.e.

from the first byte), for the byte array pattern() that was set in the constructor or in the most recent call to setPattern(). Returns the position where the pattern() matched in str, or -1 if no match was found.

Definition at line 217 of file qbytearraymatcher.cpp.

218 {
219  if (from < 0)
220  from = 0;
221  return bm_find(reinterpret_cast<const uchar *>(str), len, from,
222  p.p, p.l, p.q_skiptable);
223 }
static int bm_find(const uchar *cc, int l, int index, const uchar *puc, uint pl, const uchar *skiptable)

◆ operator=()

QByteArrayMatcher & QByteArrayMatcher::operator= ( const QByteArrayMatcher other)

Assigns the other byte array matcher to this byte array matcher.

Definition at line 174 of file qbytearraymatcher.cpp.

Referenced by QByteArrayMatcher().

175 {
176  q_pattern = other.q_pattern;
177  memcpy(&p, &other.p, sizeof(p));
178  return *this;
179 }

◆ pattern()

QByteArray QByteArrayMatcher::pattern ( ) const
inline

Returns the byte array pattern that this byte array matcher will search for.

See also
setPattern()

Definition at line 70 of file qbytearraymatcher.h.

Referenced by QByteArrayMatcher(), and setPattern().

71  {
72  if (q_pattern.isNull())
73  return QByteArray(reinterpret_cast<const char*>(p.p), p.l);
74  return q_pattern;
75  }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool isNull() const
Returns true if this byte array is null; otherwise returns false.

◆ setPattern()

void QByteArrayMatcher::setPattern ( const QByteArray pattern)

Sets the byte array that this byte array matcher will search for to pattern.

See also
pattern(), indexIn()

Definition at line 187 of file qbytearraymatcher.cpp.

188 {
189  q_pattern = pattern;
190  p.p = reinterpret_cast<const uchar *>(pattern.constData());
191  p.l = pattern.size();
193 }
static void bm_init_skiptable(const uchar *cc, int len, uchar *skiptable)
unsigned char uchar
Definition: qglobal.h:994
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QByteArray pattern() const
Returns the byte array pattern that this byte array matcher will search for.

Properties

◆ @46

union { ... }

◆ d

QByteArrayMatcherPrivate* QByteArrayMatcher::d
private

Definition at line 78 of file qbytearraymatcher.h.

◆ dummy

uint QByteArrayMatcher::dummy[256]

Definition at line 91 of file qbytearraymatcher.h.

◆ p

Data QByteArrayMatcher::p

Definition at line 92 of file qbytearraymatcher.h.

Referenced by indexIn(), operator=(), QByteArrayMatcher(), and setPattern().

◆ q_pattern

QByteArray QByteArrayMatcher::q_pattern
private

Definition at line 79 of file qbytearraymatcher.h.

Referenced by operator=(), and setPattern().


The documentation for this class was generated from the following files: