Qt 4.8
Public Functions | Private Functions | Properties | List of all members
QRegExpEngine::Box Class Reference

Public Functions

 Box (QRegExpEngine *engine)
 
 Box (const Box &b)
 
void cat (const Box &b)
 
void catAnchor (int a)
 
void clear ()
 
void dump () const
 
Boxoperator= (const Box &b)
 
void opt ()
 
void orx (const Box &b)
 
void plus (int atom)
 
void set (QChar ch)
 
void set (const QRegExpCharClass &cc)
 
void set (int bref)
 
void setupHeuristics ()
 

Private Functions

void addAnchorsToEngine (const Box &to) const
 

Properties

int earlyStart
 
QRegExpEngineeng
 
QMap< int, int > lanchors
 
int lateStart
 
QString leftStr
 
QVector< int > ls
 
int maxl
 
int minl
 
QVector< int > occ1
 
QMap< int, int > ranchors
 
QString rightStr
 
QVector< int > rs
 
int skipanchors
 
QString str
 

Detailed Description

Definition at line 1201 of file qregexp.cpp.

Constructors and Destructors

◆ Box() [1/2]

QRegExpEngine::Box::Box ( QRegExpEngine engine)

Definition at line 2429 of file qregexp.cpp.

2430  : eng(engine), skipanchors(0)
2431 #ifndef QT_NO_REGEXP_OPTIM
2432  , earlyStart(0), lateStart(0), maxl(0)
2433 #endif
2434 {
2435 #ifndef QT_NO_REGEXP_OPTIM
2437 #endif
2438  minl = 0;
2439 }
QVector< T > & fill(const T &t, int size=-1)
Assigns value to all items in the vector.
Definition: qvector.h:665
const int NumBadChars
Definition: qregexp.cpp:698
QVector< int > occ1
Definition: qregexp.cpp:1250
const int NoOccurrence
Definition: qregexp.cpp:701
QRegExpEngine * eng
Definition: qregexp.cpp:1232

◆ Box() [2/2]

QRegExpEngine::Box::Box ( const Box b)
inline

Definition at line 1205 of file qregexp.cpp.

1205 { operator=(b); }
Box & operator=(const Box &b)
Definition: qregexp.cpp:2441

Functions

◆ addAnchorsToEngine()

void QRegExpEngine::Box::addAnchorsToEngine ( const Box to) const
private

Definition at line 2698 of file qregexp.cpp.

Referenced by cat(), and plus().

2699 {
2700  for (int i = 0; i < to.ls.size(); i++) {
2701  for (int j = 0; j < rs.size(); j++) {
2702  int a = eng->anchorConcatenation(ranchors.value(rs.at(j), 0),
2703  to.lanchors.value(to.ls.at(i), 0));
2704  eng->addAnchors(rs[j], to.ls[i], a);
2705  }
2706  }
2707 }
long ASN1_INTEGER_get ASN1_INTEGER * a
int anchorConcatenation(int a, int b)
Definition: qregexp.cpp:1576
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
void addAnchors(int from, int to, int a)
Definition: qregexp.cpp:1593
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QRegExpEngine * eng
Definition: qregexp.cpp:1232
QVector< int > rs
Definition: qregexp.cpp:1234
QMap< int, int > ranchors
Definition: qregexp.cpp:1236

◆ cat()

void QRegExpEngine::Box::cat ( const Box b)

Definition at line 2504 of file qregexp.cpp.

Referenced by QRegExpEngine::parse(), QRegExpEngine::parseFactor(), and QRegExpEngine::parseTerm().

2505 {
2506  eng->addCatTransitions(rs, b.ls);
2507  addAnchorsToEngine(b);
2508  if (minl == 0) {
2509  lanchors.unite(b.lanchors);
2510  if (skipanchors != 0) {
2511  for (int i = 0; i < b.ls.size(); i++) {
2512  int a = eng->anchorConcatenation(lanchors.value(b.ls.at(i), 0), skipanchors);
2513  lanchors.insert(b.ls.at(i), a);
2514  }
2515  }
2516  mergeInto(&ls, b.ls);
2517  }
2518  if (b.minl == 0) {
2519  ranchors.unite(b.ranchors);
2520  if (b.skipanchors != 0) {
2521  for (int i = 0; i < rs.size(); i++) {
2522  int a = eng->anchorConcatenation(ranchors.value(rs.at(i), 0), b.skipanchors);
2523  ranchors.insert(rs.at(i), a);
2524  }
2525  }
2526  mergeInto(&rs, b.rs);
2527  } else {
2528  ranchors = b.ranchors;
2529  rs = b.rs;
2530  }
2531 
2532 #ifndef QT_NO_REGEXP_OPTIM
2533  if (maxl != InftyLen) {
2534  if (rightStr.length() + b.leftStr.length() >
2535  qMax(str.length(), b.str.length())) {
2537  lateStart = maxl - rightStr.length();
2538  str = rightStr + b.leftStr;
2539  } else if (b.str.length() > str.length()) {
2540  earlyStart = minl + b.earlyStart;
2541  lateStart = maxl + b.lateStart;
2542  str = b.str;
2543  }
2544  }
2545 
2546  if (leftStr.length() == maxl)
2547  leftStr += b.leftStr;
2548 
2549  if (b.rightStr.length() == b.maxl) {
2550  rightStr += b.rightStr;
2551  } else {
2552  rightStr = b.rightStr;
2553  }
2554 
2555  if (maxl == InftyLen || b.maxl == InftyLen) {
2556  maxl = InftyLen;
2557  } else {
2558  maxl += b.maxl;
2559  }
2560 
2561  for (int i = 0; i < NumBadChars; i++) {
2562  if (b.occ1.at(i) != NoOccurrence && minl + b.occ1.at(i) < occ1.at(i))
2563  occ1[i] = minl + b.occ1.at(i);
2564  }
2565 #endif
2566 
2567  minl += b.minl;
2568  if (minl == 0)
2569  skipanchors = eng->anchorConcatenation(skipanchors, b.skipanchors);
2570  else
2571  skipanchors = 0;
2572 }
const int NumBadChars
Definition: qregexp.cpp:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
static void mergeInto(QVector< int > *a, const QVector< int > &b)
Definition: qregexp.cpp:716
long ASN1_INTEGER_get ASN1_INTEGER * a
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QMap< Key, T > & unite(const QMap< Key, T > &other)
Inserts all the items in the other map into this map.
Definition: qmap.h:625
QVector< int > ls
Definition: qregexp.cpp:1233
int anchorConcatenation(int a, int b)
Definition: qregexp.cpp:1576
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
void addCatTransitions(const QVector< int > &from, const QVector< int > &to)
Definition: qregexp.cpp:1528
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
if(void) toggleToolbarShown
QMap< int, int > lanchors
Definition: qregexp.cpp:1235
QVector< int > occ1
Definition: qregexp.cpp:1250
const int NoOccurrence
Definition: qregexp.cpp:701
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
void addAnchorsToEngine(const Box &to) const
Definition: qregexp.cpp:2698
QRegExpEngine * eng
Definition: qregexp.cpp:1232
QVector< int > rs
Definition: qregexp.cpp:1234
QMap< int, int > ranchors
Definition: qregexp.cpp:1236
const int InftyLen
Definition: qregexp.cpp:703

◆ catAnchor()

void QRegExpEngine::Box::catAnchor ( int  a)

Definition at line 2632 of file qregexp.cpp.

Referenced by QRegExpEngine::parseAtom().

2633 {
2634  if (a != 0) {
2635  for (int i = 0; i < rs.size(); i++) {
2636  a = eng->anchorConcatenation(ranchors.value(rs.at(i), 0), a);
2637  ranchors.insert(rs.at(i), a);
2638  }
2639  if (minl == 0)
2641  }
2642 }
long ASN1_INTEGER_get ASN1_INTEGER * a
int anchorConcatenation(int a, int b)
Definition: qregexp.cpp:1576
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QRegExpEngine * eng
Definition: qregexp.cpp:1232
QVector< int > rs
Definition: qregexp.cpp:1234
QMap< int, int > ranchors
Definition: qregexp.cpp:1236

◆ clear()

void QRegExpEngine::Box::clear ( )
inline

Definition at line 1209 of file qregexp.cpp.

Referenced by QRegExpEngine::parseFactor().

1209 { operator=(Box(eng)); }
Box(QRegExpEngine *engine)
Definition: qregexp.cpp:2429
Box & operator=(const Box &b)
Definition: qregexp.cpp:2441
QRegExpEngine * eng
Definition: qregexp.cpp:1232

◆ dump()

void QRegExpEngine::Box::dump ( ) const

Definition at line 2676 of file qregexp.cpp.

2677 {
2678  int i;
2679  qDebug("Box of at least %d character%s", minl, minl == 1 ? "" : "s");
2680  qDebug(" Left states:");
2681  for (i = 0; i < ls.size(); i++) {
2682  if (lanchors.value(ls[i], 0) == 0)
2683  qDebug(" %d", ls[i]);
2684  else
2685  qDebug(" %d [anchors 0x%.8x]", ls[i], lanchors[ls[i]]);
2686  }
2687  qDebug(" Right states:");
2688  for (i = 0; i < rs.size(); i++) {
2689  if (ranchors.value(rs[i], 0) == 0)
2690  qDebug(" %d", rs[i]);
2691  else
2692  qDebug(" %d [anchors 0x%.8x]", rs[i], ranchors[rs[i]]);
2693  }
2694  qDebug(" Skip anchors: 0x%.8x", skipanchors);
2695 }
QVector< int > ls
Definition: qregexp.cpp:1233
Q_CORE_EXPORT void qDebug(const char *,...)
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
QMap< int, int > lanchors
Definition: qregexp.cpp:1235
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QVector< int > rs
Definition: qregexp.cpp:1234
QMap< int, int > ranchors
Definition: qregexp.cpp:1236

◆ operator=()

QRegExpEngine::Box & QRegExpEngine::Box::operator= ( const Box b)

Definition at line 2441 of file qregexp.cpp.

Referenced by QRegExp::QRegExp().

2442 {
2443  eng = b.eng;
2444  ls = b.ls;
2445  rs = b.rs;
2446  lanchors = b.lanchors;
2447  ranchors = b.ranchors;
2448  skipanchors = b.skipanchors;
2449 #ifndef QT_NO_REGEXP_OPTIM
2450  earlyStart = b.earlyStart;
2451  lateStart = b.lateStart;
2452  str = b.str;
2453  leftStr = b.leftStr;
2454  rightStr = b.rightStr;
2455  maxl = b.maxl;
2456  occ1 = b.occ1;
2457 #endif
2458  minl = b.minl;
2459  return *this;
2460 }
QVector< int > ls
Definition: qregexp.cpp:1233
QMap< int, int > lanchors
Definition: qregexp.cpp:1235
QVector< int > occ1
Definition: qregexp.cpp:1250
QRegExpEngine * eng
Definition: qregexp.cpp:1232
QVector< int > rs
Definition: qregexp.cpp:1234
QMap< int, int > ranchors
Definition: qregexp.cpp:1236

◆ opt()

void QRegExpEngine::Box::opt ( )

Definition at line 2619 of file qregexp.cpp.

Referenced by QRegExpEngine::parseFactor().

2620 {
2621 #ifndef QT_NO_REGEXP_OPTIM
2622  earlyStart = 0;
2623  lateStart = 0;
2624  str = QString();
2625  leftStr = QString();
2626  rightStr = QString();
2627 #endif
2628  skipanchors = 0;
2629  minl = 0;
2630 }
The QString class provides a Unicode character string.
Definition: qstring.h:83

◆ orx()

void QRegExpEngine::Box::orx ( const Box b)

Definition at line 2574 of file qregexp.cpp.

Referenced by QRegExpEngine::parseExpression().

2575 {
2576  mergeInto(&ls, b.ls);
2577  lanchors.unite(b.lanchors);
2578  mergeInto(&rs, b.rs);
2579  ranchors.unite(b.ranchors);
2580 
2581  if (b.minl == 0) {
2582  if (minl == 0)
2583  skipanchors = eng->anchorAlternation(skipanchors, b.skipanchors);
2584  else
2585  skipanchors = b.skipanchors;
2586  }
2587 
2588 #ifndef QT_NO_REGEXP_OPTIM
2589  for (int i = 0; i < NumBadChars; i++) {
2590  if (occ1.at(i) > b.occ1.at(i))
2591  occ1[i] = b.occ1.at(i);
2592  }
2593  earlyStart = 0;
2594  lateStart = 0;
2595  str = QString();
2596  leftStr = QString();
2597  rightStr = QString();
2598  if (b.maxl > maxl)
2599  maxl = b.maxl;
2600 #endif
2601  if (b.minl < minl)
2602  minl = b.minl;
2603 }
const int NumBadChars
Definition: qregexp.cpp:698
int anchorAlternation(int a, int b)
Definition: qregexp.cpp:1557
static void mergeInto(QVector< int > *a, const QVector< int > &b)
Definition: qregexp.cpp:716
The QString class provides a Unicode character string.
Definition: qstring.h:83
QMap< Key, T > & unite(const QMap< Key, T > &other)
Inserts all the items in the other map into this map.
Definition: qmap.h:625
QVector< int > ls
Definition: qregexp.cpp:1233
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QMap< int, int > lanchors
Definition: qregexp.cpp:1235
QVector< int > occ1
Definition: qregexp.cpp:1250
QRegExpEngine * eng
Definition: qregexp.cpp:1232
QVector< int > rs
Definition: qregexp.cpp:1234
QMap< int, int > ranchors
Definition: qregexp.cpp:1236

◆ plus()

void QRegExpEngine::Box::plus ( int  atom)

Definition at line 2605 of file qregexp.cpp.

Referenced by QRegExpEngine::parseFactor().

2606 {
2607 #ifndef QT_NO_REGEXP_CAPTURE
2608  eng->addPlusTransitions(rs, ls, atom);
2609 #else
2610  Q_UNUSED(atom);
2612 #endif
2613  addAnchorsToEngine(*this);
2614 #ifndef QT_NO_REGEXP_OPTIM
2615  maxl = InftyLen;
2616 #endif
2617 }
void addPlusTransitions(const QVector< int > &from, const QVector< int > &to, int atom)
Definition: qregexp.cpp:1535
QVector< int > ls
Definition: qregexp.cpp:1233
void addCatTransitions(const QVector< int > &from, const QVector< int > &to)
Definition: qregexp.cpp:1528
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
void addAnchorsToEngine(const Box &to) const
Definition: qregexp.cpp:2698
QRegExpEngine * eng
Definition: qregexp.cpp:1232
QVector< int > rs
Definition: qregexp.cpp:1234
const int InftyLen
Definition: qregexp.cpp:703

◆ set() [1/3]

void QRegExpEngine::Box::set ( QChar  ch)

Definition at line 2462 of file qregexp.cpp.

Referenced by QRegExpEngine::parse(), and QRegExpEngine::parseAtom().

2463 {
2464  ls.resize(1);
2465  ls[0] = eng->createState(ch);
2466  rs = ls;
2467 #ifndef QT_NO_REGEXP_OPTIM
2468  str = ch;
2469  leftStr = ch;
2470  rightStr = ch;
2471  maxl = 1;
2472  occ1[BadChar(ch)] = 0;
2473 #endif
2474  minl = 1;
2475 }
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
QVector< int > ls
Definition: qregexp.cpp:1233
#define BadChar(ch)
Definition: qregexp.cpp:699
QVector< int > occ1
Definition: qregexp.cpp:1250
int createState(QChar ch)
Definition: qregexp.cpp:1489
QRegExpEngine * eng
Definition: qregexp.cpp:1232
QVector< int > rs
Definition: qregexp.cpp:1234

◆ set() [2/3]

void QRegExpEngine::Box::set ( const QRegExpCharClass cc)

Definition at line 2477 of file qregexp.cpp.

2478 {
2479  ls.resize(1);
2480  ls[0] = eng->createState(cc);
2481  rs = ls;
2482 #ifndef QT_NO_REGEXP_OPTIM
2483  maxl = 1;
2484  occ1 = cc.firstOccurrence();
2485 #endif
2486  minl = 1;
2487 }
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
QVector< int > ls
Definition: qregexp.cpp:1233
QVector< int > occ1
Definition: qregexp.cpp:1250
int createState(QChar ch)
Definition: qregexp.cpp:1489
const QVector< int > & firstOccurrence() const
Definition: qregexp.cpp:1039
QRegExpEngine * eng
Definition: qregexp.cpp:1232
QVector< int > rs
Definition: qregexp.cpp:1234

◆ set() [3/3]

void QRegExpEngine::Box::set ( int  bref)

Definition at line 2490 of file qregexp.cpp.

2491 {
2492  ls.resize(1);
2493  ls[0] = eng->createState(bref);
2494  rs = ls;
2495  if (bref >= 1 && bref <= MaxBackRefs)
2497 #ifndef QT_NO_REGEXP_OPTIM
2498  maxl = InftyLen;
2499 #endif
2500  minl = 0;
2501 }
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
QVector< int > ls
Definition: qregexp.cpp:1233
int createState(QChar ch)
Definition: qregexp.cpp:1489
QRegExpEngine * eng
Definition: qregexp.cpp:1232
QVector< int > rs
Definition: qregexp.cpp:1234
const int InftyLen
Definition: qregexp.cpp:703

◆ setupHeuristics()

void QRegExpEngine::Box::setupHeuristics ( )

Definition at line 2645 of file qregexp.cpp.

Referenced by QRegExpEngine::parse().

2646 {
2649  eng->goodStr = eng->cs ? str : str.toLower();
2650 
2651  eng->minl = minl;
2652  if (eng->cs) {
2653  /*
2654  A regular expression such as 112|1 has occ1['2'] = 2 and minl =
2655  1 at this point. An entry of occ1 has to be at most minl or
2656  infinity for the rest of the algorithm to go well.
2657 
2658  We waited until here before normalizing these cases (instead of
2659  doing it in Box::orx()) because sometimes things improve by
2660  themselves. Consider for example (112|1)34.
2661  */
2662  for (int i = 0; i < NumBadChars; i++) {
2663  if (occ1.at(i) != NoOccurrence && occ1.at(i) >= minl)
2664  occ1[i] = minl;
2665  }
2666  eng->occ1 = occ1;
2667  } else {
2668  eng->occ1.fill(0, NumBadChars);
2669  }
2670 
2672 }
QString goodStr
Definition: qregexp.cpp:1188
QVector< T > & fill(const T &t, int size=-1)
Assigns value to all items in the vector.
Definition: qvector.h:665
const int NumBadChars
Definition: qregexp.cpp:698
Qt::CaseSensitivity cs
Definition: qregexp.cpp:1176
void heuristicallyChooseHeuristic()
Definition: qregexp.cpp:1616
QVector< int > occ1
Definition: qregexp.cpp:1191
int goodEarlyStart
Definition: qregexp.cpp:1186
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
QVector< int > occ1
Definition: qregexp.cpp:1250
const int NoOccurrence
Definition: qregexp.cpp:701
QRegExpEngine * eng
Definition: qregexp.cpp:1232

Properties

◆ earlyStart

int QRegExpEngine::Box::earlyStart
private

Definition at line 1240 of file qregexp.cpp.

Referenced by cat(), operator=(), opt(), orx(), and setupHeuristics().

◆ eng

QRegExpEngine* QRegExpEngine::Box::eng
private

◆ lanchors

QMap<int, int> QRegExpEngine::Box::lanchors
private

Definition at line 1235 of file qregexp.cpp.

Referenced by addAnchorsToEngine(), cat(), dump(), operator=(), and orx().

◆ lateStart

int QRegExpEngine::Box::lateStart
private

Definition at line 1241 of file qregexp.cpp.

Referenced by cat(), operator=(), opt(), orx(), and setupHeuristics().

◆ leftStr

QString QRegExpEngine::Box::leftStr
private

Definition at line 1243 of file qregexp.cpp.

Referenced by cat(), operator=(), opt(), orx(), and set().

◆ ls

QVector<int> QRegExpEngine::Box::ls
private

Definition at line 1233 of file qregexp.cpp.

Referenced by addAnchorsToEngine(), cat(), dump(), operator=(), orx(), plus(), and set().

◆ maxl

int QRegExpEngine::Box::maxl
private

Definition at line 1245 of file qregexp.cpp.

Referenced by cat(), operator=(), orx(), plus(), and set().

◆ minl

int QRegExpEngine::Box::minl
private

Definition at line 1248 of file qregexp.cpp.

Referenced by Box(), cat(), catAnchor(), dump(), operator=(), opt(), orx(), set(), and setupHeuristics().

◆ occ1

QVector<int> QRegExpEngine::Box::occ1
private

Definition at line 1250 of file qregexp.cpp.

Referenced by Box(), cat(), operator=(), orx(), set(), and setupHeuristics().

◆ ranchors

QMap<int, int> QRegExpEngine::Box::ranchors
private

Definition at line 1236 of file qregexp.cpp.

Referenced by addAnchorsToEngine(), cat(), catAnchor(), dump(), operator=(), and orx().

◆ rightStr

QString QRegExpEngine::Box::rightStr
private

Definition at line 1244 of file qregexp.cpp.

Referenced by cat(), operator=(), opt(), orx(), and set().

◆ rs

QVector<int> QRegExpEngine::Box::rs
private

Definition at line 1234 of file qregexp.cpp.

Referenced by addAnchorsToEngine(), cat(), catAnchor(), dump(), operator=(), orx(), plus(), and set().

◆ skipanchors

int QRegExpEngine::Box::skipanchors
private

Definition at line 1237 of file qregexp.cpp.

Referenced by cat(), catAnchor(), dump(), operator=(), opt(), orx(), and set().

◆ str

QString QRegExpEngine::Box::str
private

Definition at line 1242 of file qregexp.cpp.

Referenced by cat(), operator=(), opt(), orx(), prepareEngineForMatch(), set(), and setupHeuristics().


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