Qt 4.8
Classes | Macros | Typedefs | Functions | Variables
qregexp.cpp File Reference
#include "qregexp.h"
#include "qalgorithms.h"
#include "qbitarray.h"
#include "qcache.h"
#include "qdatastream.h"
#include "qlist.h"
#include "qmap.h"
#include "qmutex.h"
#include "qstring.h"
#include "qstringlist.h"
#include "qstringmatcher.h"
#include "qvector.h"
#include "private/qfunctions_p.h"
#include <limits.h>

Go to the source code of this file.

Classes

struct  QRegExpAnchorAlternation
 
struct  QRegExpAtom
 
struct  QRegExpAutomatonState
 
class  QRegExpCharClass
 
struct  QRegExpCharClassRange
 
class  QRegExpEngine
 
class  QRegExpEngine::Box
 
struct  QRegExpEngineKey
 
struct  QRegExpLookahead
 
struct  QRegExpMatchState
 
struct  QRegExpPrivate
 

Macros

#define BadChar(ch)   ((ch).unicode() % NumBadChars)
 
#define RXERR_CATEGORY   QT_TRANSLATE_NOOP("QRegExp", "invalid category")
 
#define RXERR_CHARCLASS   QT_TRANSLATE_NOOP("QRegExp", "bad char class syntax")
 
#define RXERR_DISABLED   QT_TRANSLATE_NOOP("QRegExp", "disabled feature used")
 
#define RXERR_END   QT_TRANSLATE_NOOP("QRegExp", "unexpected end")
 
#define RXERR_INTERVAL   QT_TRANSLATE_NOOP("QRegExp", "invalid interval")
 
#define RXERR_LEFTDELIM   QT_TRANSLATE_NOOP("QRegExp", "missing left delim")
 
#define RXERR_LIMIT   QT_TRANSLATE_NOOP("QRegExp", "met internal limit")
 
#define RXERR_LOOKAHEAD   QT_TRANSLATE_NOOP("QRegExp", "bad lookahead syntax")
 
#define RXERR_LOOKBEHIND   QT_TRANSLATE_NOOP("QRegExp", "lookbehinds not supported, see QTBUG-2371")
 
#define RXERR_OCTAL   QT_TRANSLATE_NOOP("QRegExp", "invalid octal value")
 
#define RXERR_OK   QT_TRANSLATE_NOOP("QRegExp", "no error occurred")
 
#define RXERR_REPETITION   QT_TRANSLATE_NOOP("QRegExp", "bad repetition syntax")
 
#define YYREDO()
 

Typedefs

typedef QCache< QRegExpEngineKey, QRegExpEngineEngineCache
 

Functions

static int caretIndex (int offset, QRegExp::CaretMode caretMode)
 
static void derefEngine (QRegExpEngine *eng, const QRegExpEngineKey &key)
 
static void invalidateEngine (QRegExpPrivate *priv)
 
static bool isBetterCapture (int ncap, const int *begin1, const int *end1, const int *begin2, const int *end2)
 
static bool isWord (QChar ch)
 
static void mergeInto (QVector< int > *a, const QVector< int > &b)
 
Q_STATIC_GLOBAL_OPERATOR bool operator== (const QRegExpEngineKey &key1, const QRegExpEngineKey &key2)
 
static void prepareEngine (QRegExpPrivate *priv)
 
static void prepareEngine_helper (QRegExpPrivate *priv)
 
static void prepareEngineForMatch (QRegExpPrivate *priv, const QString &str)
 
 Q_DECLARE_TYPEINFO (QRegExpAutomatonState, Q_MOVABLE_TYPE)
 
 Q_DECLARE_TYPEINFO (QRegExpCharClassRange, Q_PRIMITIVE_TYPE)
 
 Q_DECLARE_TYPEINFO (QRegExpAtom, Q_PRIMITIVE_TYPE)
 
 Q_DECLARE_TYPEINFO (QRegExpAnchorAlternation, Q_PRIMITIVE_TYPE)
 
 Q_DECLARE_TYPEINFO (QRegExpCharClass, Q_MOVABLE_TYPE)
 
int qFindString (const QChar *haystack, int haystackLen, int from, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
 
uint qHash (const QRegExpEngineKey &key)
 
Q_CORE_EXPORT QString qt_regexp_toCanonical (const QString &pattern, QRegExp::PatternSyntax patternSyntax)
 
static QString wc2rx (const QString &wc_str, const bool enableEscaping)
 

Variables

const int EmptyCapture = INT_MAX
 
const int EOS = -1
 
const int InftyLen = INT_MAX
 
const int InftyRep = 1025
 
const int NoOccurrence = INT_MAX
 
const int NumBadChars = 64
 

Macro Definition Documentation

◆ BadChar

#define BadChar (   ch)    ((ch).unicode() % NumBadChars)

◆ RXERR_CATEGORY

#define RXERR_CATEGORY   QT_TRANSLATE_NOOP("QRegExp", "invalid category")

Definition at line 76 of file qregexp.cpp.

Referenced by QRegExpEngine::getEscape().

◆ RXERR_CHARCLASS

#define RXERR_CHARCLASS   QT_TRANSLATE_NOOP("QRegExp", "bad char class syntax")

Definition at line 67 of file qregexp.cpp.

Referenced by QRegExpEngine::getEscape(), and QRegExpEngine::getToken().

◆ RXERR_DISABLED

#define RXERR_DISABLED   QT_TRANSLATE_NOOP("QRegExp", "disabled feature used")

◆ RXERR_END

#define RXERR_END   QT_TRANSLATE_NOOP("QRegExp", "unexpected end")

◆ RXERR_INTERVAL

#define RXERR_INTERVAL   QT_TRANSLATE_NOOP("QRegExp", "invalid interval")

Definition at line 75 of file qregexp.cpp.

Referenced by QRegExpEngine::getToken().

◆ RXERR_LEFTDELIM

#define RXERR_LEFTDELIM   QT_TRANSLATE_NOOP("QRegExp", "missing left delim")

Definition at line 72 of file qregexp.cpp.

Referenced by QRegExpEngine::getToken(), and QRegExpEngine::QRegExpEngine().

◆ RXERR_LIMIT

#define RXERR_LIMIT   QT_TRANSLATE_NOOP("QRegExp", "met internal limit")

Definition at line 74 of file qregexp.cpp.

Referenced by QRegExpEngine::addLookahead(), and QRegExpEngine::createState().

◆ RXERR_LOOKAHEAD

#define RXERR_LOOKAHEAD   QT_TRANSLATE_NOOP("QRegExp", "bad lookahead syntax")

Definition at line 68 of file qregexp.cpp.

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

◆ RXERR_LOOKBEHIND

#define RXERR_LOOKBEHIND   QT_TRANSLATE_NOOP("QRegExp", "lookbehinds not supported, see QTBUG-2371")

Definition at line 69 of file qregexp.cpp.

Referenced by QRegExpEngine::getToken().

◆ RXERR_OCTAL

#define RXERR_OCTAL   QT_TRANSLATE_NOOP("QRegExp", "invalid octal value")

Definition at line 71 of file qregexp.cpp.

Referenced by QRegExpEngine::getEscape().

◆ RXERR_OK

#define RXERR_OK   QT_TRANSLATE_NOOP("QRegExp", "no error occurred")

Definition at line 65 of file qregexp.cpp.

Referenced by QRegExp::errorString().

◆ RXERR_REPETITION

#define RXERR_REPETITION   QT_TRANSLATE_NOOP("QRegExp", "bad repetition syntax")

◆ YYREDO

#define YYREDO ( )
Value:
yyIn = in, yyPos0 = pos0, yyPos = pos, yyLen = len, yyCh = ch, \
*yyCharClass = charClass, yyMinRep = 0, yyMaxRep = 0, yyTok = tok

Referenced by QRegExpEngine::parseFactor().

Typedef Documentation

◆ EngineCache

Definition at line 3677 of file qregexp.cpp.

Function Documentation

◆ caretIndex()

static int caretIndex ( int  offset,
QRegExp::CaretMode  caretMode 
)
static

Definition at line 858 of file qregexp.cpp.

Referenced by QRegExpMatchState::drain(), QRegExp::indexIn(), QRegExp::lastIndexIn(), and QRegExpMatchState::match().

859 {
860  if (caretMode == QRegExp::CaretAtZero) {
861  return 0;
862  } else if (caretMode == QRegExp::CaretAtOffset) {
863  return offset;
864  } else { // QRegExp::CaretWontMatch
865  return -1;
866  }
867 }

◆ derefEngine()

static void derefEngine ( QRegExpEngine eng,
const QRegExpEngineKey key 
)
static

Definition at line 3682 of file qregexp.cpp.

Referenced by invalidateEngine().

3683 {
3684  if (!eng->ref.deref()) {
3685 #if !defined(QT_NO_REGEXP_OPTIM)
3686  if (globalEngineCache()) {
3687  QMutexLocker locker(mutex());
3688  QT_TRY {
3689  globalEngineCache()->insert(key, eng, 4 + key.pattern.length() / 4);
3690  } QT_CATCH(const std::bad_alloc &) {
3691  // in case of an exception (e.g. oom), just delete the engine
3692  delete eng;
3693  }
3694  } else {
3695  delete eng;
3696  }
3697 #else
3698  Q_UNUSED(key);
3699  delete eng;
3700 #endif
3701  }
3702 }
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString pattern
Definition: qregexp.cpp:874
bool deref()
Atomically decrements the value of this QAtomicInt.
#define QT_CATCH(A)
Definition: qglobal.h:1537
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QAtomicInt ref
Definition: qregexp.cpp:1115
#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
#define QT_TRY
Definition: qglobal.h:1536

◆ invalidateEngine()

static void invalidateEngine ( QRegExpPrivate priv)
static

Definition at line 3742 of file qregexp.cpp.

Referenced by QRegExp::operator=(), QRegExp::setCaseSensitivity(), QRegExp::setPattern(), QRegExp::setPatternSyntax(), and QRegExp::~QRegExp().

3743 {
3744  if (priv->eng != 0) {
3745  derefEngine(priv->eng, priv->engineKey);
3746  priv->eng = 0;
3747  priv->matchState.drain();
3748  }
3749 }
QRegExpMatchState matchState
Definition: qregexp.cpp:3663
static void derefEngine(QRegExpEngine *eng, const QRegExpEngineKey &key)
Definition: qregexp.cpp:3682
QRegExpEngineKey engineKey
Definition: qregexp.cpp:3657
QRegExpEngine * eng
Definition: qregexp.cpp:3656

◆ isBetterCapture()

static bool isBetterCapture ( int  ncap,
const int *  begin1,
const int *  end1,
const int *  begin2,
const int *  end2 
)
static

Definition at line 1785 of file qregexp.cpp.

Referenced by QRegExpMatchState::matchHere().

1787 {
1788  for (int i = 0; i < ncap; i++) {
1789  int delta = begin2[i] - begin1[i]; // it has to start early...
1790  if (delta == 0)
1791  delta = end1[i] - end2[i]; // ...and end late
1792 
1793  if (delta != 0)
1794  return delta > 0;
1795  }
1796  return false;
1797 }

◆ isWord()

static bool isWord ( QChar  ch)
static

Definition at line 707 of file qregexp.cpp.

Referenced by QRegExpMatchState::testAnchor().

708 {
709  return ch.isLetterOrNumber() || ch.isMark() || ch == QLatin1Char('_');
710 }
bool isMark() const
Returns true if the character is a mark (Mark_* categories); otherwise returns false.
Definition: qchar.cpp:625
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
bool isLetterOrNumber() const
Returns true if the character is a letter or number (Letter_* or Number_* categories); otherwise retu...
Definition: qchar.cpp:681

◆ mergeInto()

static void mergeInto ( QVector< int > *  a,
const QVector< int > &  b 
)
static

Definition at line 716 of file qregexp.cpp.

Referenced by QRegExpEngine::addCatTransitions(), QRegExpEngine::addPlusTransitions(), QRegExpEngine::Box::cat(), and QRegExpEngine::Box::orx().

717 {
718  int asize = a->size();
719  int bsize = b.size();
720  if (asize == 0) {
721  *a = b;
722 #ifndef QT_NO_REGEXP_OPTIM
723  } else if (bsize == 1 && a->at(asize - 1) < b.at(0)) {
724  a->resize(asize + 1);
725  (*a)[asize] = b.at(0);
726 #endif
727  } else if (bsize >= 1) {
728  int csize = asize + bsize;
729  QVector<int> c(csize);
730  int i = 0, j = 0, k = 0;
731  while (i < asize) {
732  if (j < bsize) {
733  if (a->at(i) == b.at(j)) {
734  ++i;
735  --csize;
736  } else if (a->at(i) < b.at(j)) {
737  c[k++] = a->at(i++);
738  } else {
739  c[k++] = b.at(j++);
740  }
741  } else {
742  memcpy(c.data() + k, a->constData() + i, (asize - i) * sizeof(int));
743  break;
744  }
745  }
746  c.resize(csize);
747  if (j < bsize)
748  memcpy(c.data() + k, b.constData() + j, (bsize - j) * sizeof(int));
749  *a = c;
750  }
751 }
unsigned char c[8]
Definition: qnumeric_p.h:62
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ operator==()

Q_STATIC_GLOBAL_OPERATOR bool operator== ( const QRegExpEngineKey key1,
const QRegExpEngineKey key2 
)

Definition at line 889 of file qregexp.cpp.

890 {
891  return key1.pattern == key2.pattern && key1.patternSyntax == key2.patternSyntax
892  && key1.cs == key2.cs;
893 }
Qt::CaseSensitivity cs
Definition: qregexp.cpp:876
QRegExp::PatternSyntax patternSyntax
Definition: qregexp.cpp:875
QString pattern
Definition: qregexp.cpp:874

◆ prepareEngine()

static void prepareEngine ( QRegExpPrivate priv)
inlinestatic

Definition at line 3723 of file qregexp.cpp.

Referenced by QRegExp::captureCount(), QRegExp::capturedTexts(), QRegExp::isValid(), QRegExp::operator=(), prepareEngineForMatch(), and QRegExp::QRegExp().

3724 {
3725  if (priv->eng)
3726  return;
3727  prepareEngine_helper(priv);
3728 }
static void prepareEngine_helper(QRegExpPrivate *priv)
Definition: qregexp.cpp:3704
QRegExpEngine * eng
Definition: qregexp.cpp:3656

◆ prepareEngine_helper()

static void prepareEngine_helper ( QRegExpPrivate priv)
static

Definition at line 3704 of file qregexp.cpp.

Referenced by prepareEngine().

3705 {
3706  bool initMatchState = !priv->eng;
3707 #if !defined(QT_NO_REGEXP_OPTIM)
3708  if (!priv->eng && globalEngineCache()) {
3709  QMutexLocker locker(mutex());
3710  priv->eng = globalEngineCache()->take(priv->engineKey);
3711  if (priv->eng != 0)
3712  priv->eng->ref.ref();
3713  }
3714 #endif // QT_NO_REGEXP_OPTIM
3715 
3716  if (!priv->eng)
3717  priv->eng = new QRegExpEngine(priv->engineKey);
3718 
3719  if (initMatchState)
3720  priv->matchState.prepareForMatch(priv->eng);
3721 }
QRegExpMatchState matchState
Definition: qregexp.cpp:3663
bool ref()
Atomically increments the value of this QAtomicInt.
void prepareForMatch(QRegExpEngine *eng)
Definition: qregexp.cpp:1367
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QAtomicInt ref
Definition: qregexp.cpp:1115
QRegExpEngineKey engineKey
Definition: qregexp.cpp:3657
QRegExpEngine * eng
Definition: qregexp.cpp:3656

◆ prepareEngineForMatch()

static void prepareEngineForMatch ( QRegExpPrivate priv,
const QString str 
)
static

Definition at line 3730 of file qregexp.cpp.

Referenced by QRegExp::exactMatch(), QRegExp::indexIn(), and QRegExp::lastIndexIn().

3731 {
3732  prepareEngine(priv);
3733  priv->matchState.prepareForMatch(priv->eng);
3734 #ifndef QT_NO_REGEXP_CAPTURE
3735  priv->t = str;
3736  priv->capturedCache.clear();
3737 #else
3738  Q_UNUSED(str);
3739 #endif
3740 }
QStringList capturedCache
Definition: qregexp.cpp:3661
QRegExpMatchState matchState
Definition: qregexp.cpp:3663
void prepareForMatch(QRegExpEngine *eng)
Definition: qregexp.cpp:1367
void clear()
Removes all items from the list.
Definition: qlist.h:764
static void prepareEngine(QRegExpPrivate *priv)
Definition: qregexp.cpp:3723
QRegExpEngine * eng
Definition: qregexp.cpp:3656
#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

◆ Q_DECLARE_TYPEINFO() [1/5]

Q_DECLARE_TYPEINFO ( QRegExpAutomatonState  ,
Q_MOVABLE_TYPE   
)

◆ Q_DECLARE_TYPEINFO() [2/5]

Q_DECLARE_TYPEINFO ( QRegExpCharClassRange  ,
Q_PRIMITIVE_TYPE   
)

◆ Q_DECLARE_TYPEINFO() [3/5]

Q_DECLARE_TYPEINFO ( QRegExpAtom  ,
Q_PRIMITIVE_TYPE   
)

◆ Q_DECLARE_TYPEINFO() [4/5]

Q_DECLARE_TYPEINFO ( QRegExpAnchorAlternation  ,
Q_PRIMITIVE_TYPE   
)

◆ Q_DECLARE_TYPEINFO() [5/5]

Q_DECLARE_TYPEINFO ( QRegExpCharClass  ,
Q_MOVABLE_TYPE   
)

◆ qFindString()

int qFindString ( const QChar haystack,
int  haystackLen,
int  from,
const QChar needle,
int  needleLen,
Qt::CaseSensitivity  cs 
)

Definition at line 2753 of file qstring.cpp.

Referenced by QString::indexOf(), QStringRef::indexOf(), QRegExpMatchState::match(), qt_find_latin1_string(), and qt_string_count().

2756 {
2757  const int l = haystackLen;
2758  const int sl = needleLen;
2759  if (from < 0)
2760  from += l;
2761  if (uint(sl + from) > (uint)l)
2762  return -1;
2763  if (!sl)
2764  return from;
2765  if (!l)
2766  return -1;
2767 
2768  if (sl == 1)
2769  return findChar(haystack0, haystackLen, needle0[0], from, cs);
2770 
2771  /*
2772  We use the Boyer-Moore algorithm in cases where the overhead
2773  for the skip table should pay off, otherwise we use a simple
2774  hash function.
2775  */
2776  if (l > 500 && sl > 5)
2777  return qFindStringBoyerMoore(haystack0, haystackLen, from,
2778  needle0, needleLen, cs);
2779 
2780  /*
2781  We use some hashing for efficiency's sake. Instead of
2782  comparing strings, we compare the hash value of str with that
2783  of a part of this QString. Only if that matches, we call
2784  ucstrncmp() or ucstrnicmp().
2785  */
2786  const ushort *needle = (const ushort *)needle0;
2787  const ushort *haystack = (const ushort *)haystack0 + from;
2788  const ushort *end = (const ushort *)haystack0 + (l-sl);
2789  const int sl_minus_1 = sl-1;
2790  int hashNeedle = 0, hashHaystack = 0, idx;
2791 
2792  if (cs == Qt::CaseSensitive) {
2793  for (idx = 0; idx < sl; ++idx) {
2794  hashNeedle = ((hashNeedle<<1) + needle[idx]);
2795  hashHaystack = ((hashHaystack<<1) + haystack[idx]);
2796  }
2797  hashHaystack -= haystack[sl_minus_1];
2798 
2799  while (haystack <= end) {
2800  hashHaystack += haystack[sl_minus_1];
2801  if (hashHaystack == hashNeedle
2802  && ucstrncmp((const QChar *)needle, (const QChar *)haystack, sl) == 0)
2803  return haystack - (const ushort *)haystack0;
2804 
2805  REHASH(*haystack);
2806  ++haystack;
2807  }
2808  } else {
2809  const ushort *haystack_start = (const ushort *)haystack0;
2810  for (idx = 0; idx < sl; ++idx) {
2811  hashNeedle = (hashNeedle<<1) + foldCase(needle + idx, needle);
2812  hashHaystack = (hashHaystack<<1) + foldCase(haystack + idx, haystack_start);
2813  }
2814  hashHaystack -= foldCase(haystack + sl_minus_1, haystack_start);
2815 
2816  while (haystack <= end) {
2817  hashHaystack += foldCase(haystack + sl_minus_1, haystack_start);
2818  if (hashHaystack == hashNeedle && ucstrnicmp(needle, haystack, sl) == 0)
2819  return haystack - (const ushort *)haystack0;
2820 
2821  REHASH(foldCase(haystack, haystack_start));
2822  ++haystack;
2823  }
2824  }
2825  return -1;
2826 }
static int ucstrnicmp(const ushort *a, const ushort *b, int l)
Definition: qstring.cpp:221
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
static int ucstrncmp(const QChar *a, const QChar *b, int l)
Definition: qstring.cpp:201
unsigned int uint
Definition: qglobal.h:996
static uint foldCase(const ushort *ch, const ushort *start)
Definition: qchar.cpp:1380
static int findChar(const QChar *str, int len, QChar ch, int from, Qt::CaseSensitivity cs)
Returns the index position of the first occurrence of the character ch in the string given by str and...
Definition: qstring.cpp:333
int qFindStringBoyerMoore(const QChar *haystack, int haystackLen, int from, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
#define REHASH(a)
Definition: qstring.cpp:357
unsigned short ushort
Definition: qglobal.h:995
QFactoryLoader * l
static const KeyPair *const end

◆ qHash()

uint qHash ( const QRegExpEngineKey key)

Definition at line 3672 of file qregexp.cpp.

3673 {
3674  return qHash(key.pattern);
3675 }
QString pattern
Definition: qregexp.cpp:874
uint qHash(const QUrl &url)
Definition: qurl.h:285

◆ qt_regexp_toCanonical()

Q_CORE_EXPORT QString qt_regexp_toCanonical ( const QString pattern,
QRegExp::PatternSyntax  patternSyntax 
)
Warning
This function is not part of the public interface. convert the pattern string to the RegExp syntax.

This is also used by QScriptEngine::newRegExp to convert to a pattern that JavaScriptCore can understan

Definition at line 1323 of file qregexp.cpp.

Referenced by QScriptEnginePrivate::detachAllRegisteredScriptStrings(), QScriptEnginePrivate::newRegExp(), and QRegExpEngine::QRegExpEngine().

1324 {
1325  switch (patternSyntax) {
1326 #ifndef QT_NO_REGEXP_WILDCARD
1327  case QRegExp::Wildcard:
1328  return wc2rx(pattern, false);
1329  break;
1330  case QRegExp::WildcardUnix:
1331  return wc2rx(pattern, true);
1332  break;
1333 #endif
1334  case QRegExp::FixedString:
1335  return QRegExp::escape(pattern);
1336  break;
1338  default:
1339  return pattern;
1340  }
1341 }
static QString wc2rx(const QString &wc_str, const bool enableEscaping)
Definition: qregexp.cpp:761
static QString escape(const QString &str)
Returns the string str with every regexp special character escaped with a backslash.
Definition: qregexp.cpp:4392

◆ wc2rx()

static QString wc2rx ( const QString wc_str,
const bool  enableEscaping 
)
static

Definition at line 761 of file qregexp.cpp.

Referenced by qt_regexp_toCanonical().

762 {
763  const int wclen = wc_str.length();
764  QString rx;
765  int i = 0;
766  bool isEscaping = false; // the previous character is '\'
767  const QChar *wc = wc_str.unicode();
768 
769  while (i < wclen) {
770  const QChar c = wc[i++];
771  switch (c.unicode()) {
772  case '\\':
773  if (enableEscaping) {
774  if (isEscaping) {
775  rx += QLatin1String("\\\\");
776  } // we insert the \\ later if necessary
777  if (i == wclen) { // the end
778  rx += QLatin1String("\\\\");
779  }
780  } else {
781  rx += QLatin1String("\\\\");
782  }
783  isEscaping = true;
784  break;
785  case '*':
786  if (isEscaping) {
787  rx += QLatin1String("\\*");
788  isEscaping = false;
789  } else {
790  rx += QLatin1String(".*");
791  }
792  break;
793  case '?':
794  if (isEscaping) {
795  rx += QLatin1String("\\?");
796  isEscaping = false;
797  } else {
798  rx += QLatin1Char('.');
799  }
800 
801  break;
802  case '$':
803  case '(':
804  case ')':
805  case '+':
806  case '.':
807  case '^':
808  case '{':
809  case '|':
810  case '}':
811  if (isEscaping) {
812  isEscaping = false;
813  rx += QLatin1String("\\\\");
814  }
815  rx += QLatin1Char('\\');
816  rx += c;
817  break;
818  case '[':
819  if (isEscaping) {
820  isEscaping = false;
821  rx += QLatin1String("\\[");
822  } else {
823  rx += c;
824  if (wc[i] == QLatin1Char('^'))
825  rx += wc[i++];
826  if (i < wclen) {
827  if (rx[i] == QLatin1Char(']'))
828  rx += wc[i++];
829  while (i < wclen && wc[i] != QLatin1Char(']')) {
830  if (wc[i] == QLatin1Char('\\'))
831  rx += QLatin1Char('\\');
832  rx += wc[i++];
833  }
834  }
835  }
836  break;
837 
838  case ']':
839  if(isEscaping){
840  isEscaping = false;
841  rx += QLatin1String("\\");
842  }
843  rx += c;
844  break;
845 
846  default:
847  if(isEscaping){
848  isEscaping = false;
849  rx += QLatin1String("\\\\");
850  }
851  rx += c;
852  }
853  }
854  return rx;
855 }
unsigned char c[8]
Definition: qnumeric_p.h:62
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

Variable Documentation

◆ EmptyCapture

const int EmptyCapture = INT_MAX

◆ EOS

const int EOS = -1

◆ InftyLen

const int InftyLen = INT_MAX

◆ InftyRep

const int InftyRep = 1025

◆ NoOccurrence

const int NoOccurrence = INT_MAX

◆ NumBadChars

const int NumBadChars = 64