55 #include "private/qfunctions_p.h" 65 #define RXERR_OK QT_TRANSLATE_NOOP("QRegExp", "no error occurred") 66 #define RXERR_DISABLED QT_TRANSLATE_NOOP("QRegExp", "disabled feature used") 67 #define RXERR_CHARCLASS QT_TRANSLATE_NOOP("QRegExp", "bad char class syntax") 68 #define RXERR_LOOKAHEAD QT_TRANSLATE_NOOP("QRegExp", "bad lookahead syntax") 69 #define RXERR_LOOKBEHIND QT_TRANSLATE_NOOP("QRegExp", "lookbehinds not supported, see QTBUG-2371") 70 #define RXERR_REPETITION QT_TRANSLATE_NOOP("QRegExp", "bad repetition syntax") 71 #define RXERR_OCTAL QT_TRANSLATE_NOOP("QRegExp", "invalid octal value") 72 #define RXERR_LEFTDELIM QT_TRANSLATE_NOOP("QRegExp", "missing left delim") 73 #define RXERR_END QT_TRANSLATE_NOOP("QRegExp", "unexpected end") 74 #define RXERR_LIMIT QT_TRANSLATE_NOOP("QRegExp", "met internal limit") 75 #define RXERR_INTERVAL QT_TRANSLATE_NOOP("QRegExp", "invalid interval") 76 #define RXERR_CATEGORY QT_TRANSLATE_NOOP("QRegExp", "invalid category") 694 #if defined(Q_OS_VXWORKS) && defined(EOS) 699 #define BadChar(ch) ((ch).unicode() % NumBadChars) 718 int asize = a->
size();
719 int bsize = b.
size();
722 #ifndef QT_NO_REGEXP_OPTIM 723 }
else if (bsize == 1 && a->
at(asize - 1) < b.
at(0)) {
725 (*a)[asize] = b.
at(0);
727 }
else if (bsize >= 1) {
728 int csize = asize + bsize;
730 int i = 0, j = 0, k = 0;
733 if (a->
at(i) == b.
at(j)) {
736 }
else if (a->
at(i) < b.
at(j)) {
742 memcpy(c.
data() + k, a->
constData() + i, (asize - i) *
sizeof(
int));
748 memcpy(c.
data() + k, b.
constData() + j, (bsize - j) *
sizeof(
int));
753 #ifndef QT_NO_REGEXP_WILDCARD 763 const int wclen = wc_str.
length();
766 bool isEscaping =
false;
773 if (enableEscaping) {
880 : pattern(pattern), patternSyntax(patternSyntax), cs(cs) {}
892 && key1.
cs == key2.
cs;
925 #ifndef QT_NO_REGEXP_BACKREF 936 void drain() { free(bigArray); bigArray = 0; captured = 0; }
938 void match(
const QChar *str,
int len,
int pos,
bool minimal,
941 bool testAnchor(
int i,
int a,
const int *capBegin);
952 #ifndef QT_NO_REGEXP_CAPTURE 961 #ifndef QT_NO_REGEXP_CAPTURE 963 : atom(a), match(m) { }
984 #ifndef QT_NO_REGEXP_CAPTURE 991 enum { NoCapture = -1, OfficialCapture = -2, UnofficialCapture = -3 };
1002 #ifndef QT_NO_REGEXP_ANCHOR_ALT 1016 #ifndef QT_NO_REGEXP_CCLASS 1032 void setNegative(
bool negative);
1033 void addCategories(
int cats);
1037 bool in(
QChar ch)
const;
1038 #ifndef QT_NO_REGEXP_OPTIM 1042 #if defined(QT_DEBUG) 1050 #ifndef QT_NO_REGEXP_OPTIM 1059 #ifndef QT_NO_REGEXP_OPTIM 1062 const QVector<int> &firstOccurrence()
const {
return occ1; }
1078 : cs(cs), greedyQuantifiers(greedyQuantifiers) {
setup(); }
1087 int createState(
QChar ch);
1089 #ifndef QT_NO_REGEXP_BACKREF 1090 int createState(
int bref);
1094 #ifndef QT_NO_REGEXP_CAPTURE 1098 #ifndef QT_NO_REGEXP_ANCHOR_ALT 1099 int anchorAlternation(
int a,
int b);
1100 int anchorConcatenation(
int a,
int b);
1102 int anchorAlternation(
int a,
int b) {
return a & b; }
1103 int anchorConcatenation(
int a,
int b) {
return a | b; }
1105 void addAnchors(
int from,
int to,
int a);
1107 #ifndef QT_NO_REGEXP_OPTIM 1108 void heuristicallyChooseHeuristic();
1111 #if defined(QT_DEBUG) 1118 enum { CharClassBit = 0x10000, BackRefBit = 0x20000 };
1119 enum { InitialState = 0, FinalState = 1 };
1122 int setupState(
int match);
1128 enum { MaxLookaheads = 13, MaxBackRefs = 14 };
1129 enum { Anchor_Dollar = 0x00000001, Anchor_Caret = 0x00000002, Anchor_Word = 0x00000004,
1130 Anchor_NonWord = 0x00000008, Anchor_FirstLookahead = 0x00000010,
1131 Anchor_BackRef1Empty = Anchor_FirstLookahead << MaxLookaheads,
1132 Anchor_BackRef0Empty = Anchor_BackRef1Empty >> 1,
1133 Anchor_Alternation = unsigned(Anchor_BackRef1Empty) << MaxBackRefs,
1135 Anchor_LookaheadMask = (Anchor_FirstLookahead - 1) ^
1136 ((Anchor_FirstLookahead << MaxLookaheads) - 1) };
1137 #ifndef QT_NO_REGEXP_CAPTURE 1138 int startAtom(
bool officialCapture);
1139 void finishAtom(
int atom,
bool needCapture);
1142 #ifndef QT_NO_REGEXP_LOOKAHEAD 1146 #ifndef QT_NO_REGEXP_OPTIM 1154 #ifndef QT_NO_REGEXP_CAPTURE 1162 #ifndef QT_NO_REGEXP_CCLASS 1165 #ifndef QT_NO_REGEXP_LOOKAHEAD 1168 #ifndef QT_NO_REGEXP_ANCHOR_ALT 1171 #ifndef QT_NO_REGEXP_OPTIM 1179 #ifndef QT_NO_REGEXP_BACKREF 1183 #ifndef QT_NO_REGEXP_OPTIM 1207 Box &operator=(
const Box &b);
1212 #ifndef QT_NO_REGEXP_BACKREF 1216 void cat(
const Box &b);
1217 void orx(
const Box &b);
1218 void plus(
int atom);
1220 void catAnchor(
int a);
1221 #ifndef QT_NO_REGEXP_OPTIM 1222 void setupHeuristics();
1225 #if defined(QT_DEBUG) 1230 void addAnchorsToEngine(
const Box &to)
const;
1239 #ifndef QT_NO_REGEXP_OPTIM 1249 #ifndef QT_NO_REGEXP_OPTIM 1256 void setupCategoriesRangeMap();
1263 Tok_Word, Tok_NonWord, Tok_Char = 0x10000, Tok_BackRef = 0x20000 };
1266 #ifndef QT_NO_REGEXP_INTERVAL 1267 int getRep(
int def);
1269 #ifndef QT_NO_REGEXP_LOOKAHEAD 1270 void skipChars(
int n);
1272 void error(
const char *msg);
1273 void startTokenizer(
const QChar *rx,
int len);
1289 int parse(
const QChar *rx,
int len);
1290 void parseAtom(
Box *box);
1291 void parseFactor(
Box *box);
1292 void parseTerm(
Box *box);
1293 void parseExpression(
Box *box);
1302 #ifndef QT_NO_REGEXP_LOOKAHEAD 1313 : eng(eng0), neg(neg0) { }
1325 switch (patternSyntax) {
1326 #ifndef QT_NO_REGEXP_WILDCARD 1328 return wc2rx(pattern,
false);
1331 return wc2rx(pattern,
true);
1353 #ifndef QT_NO_REGEXP_OPTIM 1362 #ifndef QT_NO_REGEXP_LOOKAHEAD 1373 int ns = eng->
s.
size();
1375 #ifndef QT_NO_REGEXP_OPTIM 1376 int newSlideTabSize =
qMax(eng->
minl + 1, 16);
1378 int newSlideTabSize = 0;
1381 int newCapturedSize = 2 + 2 * numCaptures;
1382 bigArray =
q_check_ptr((
int *)realloc(bigArray, ((3 + 4 * ncap) * ns + 4 * ncap + newSlideTabSize + newCapturedSize)*
sizeof(
int)));
1387 slideTabSize = newSlideTabSize;
1388 capturedSize = newCapturedSize;
1389 inNextStack = bigArray;
1390 memset(inNextStack, -1, ns *
sizeof(
int));
1391 curStack = inNextStack + ns;
1392 nextStack = inNextStack + 2 * ns;
1394 curCapBegin = inNextStack + 3 * ns;
1395 nextCapBegin = curCapBegin + ncap * ns;
1396 curCapEnd = curCapBegin + 2 * ncap * ns;
1397 nextCapEnd = curCapBegin + 3 * ncap * ns;
1399 tempCapBegin = curCapBegin + 4 * ncap * ns;
1400 tempCapEnd = tempCapBegin +
ncap;
1401 capBegin = tempCapBegin + 2 *
ncap;
1402 capEnd = tempCapBegin + 3 *
ncap;
1404 slideTab = tempCapBegin + 4 *
ncap;
1405 captured = slideTab + slideTabSize;
1406 memset(captured, -1, capturedSize*
sizeof(
int));
1417 bool matched =
false;
1420 #ifndef QT_NO_REGEXP_OPTIM 1421 if (eng->trivial && !oneTest) {
1422 pos =
qFindString(str0, len0, pos0, eng->goodStr.
unicode(), eng->goodStr.length(), eng->cs);
1423 matchLen = eng->goodStr.length();
1424 matched = (pos != -1);
1436 oneTestMatchedLen = 0;
1438 if (eng->valid && pos >= 0 && pos <= len) {
1439 #ifndef QT_NO_REGEXP_OPTIM 1441 matched = matchHere();
1443 if (pos <= len - eng->
minl) {
1444 if (eng->caretAnchored) {
1445 matched = matchHere();
1446 }
else if (eng->useGoodStringHeuristic) {
1447 matched = eng->goodStringMatch(*
this);
1449 matched = eng->badCharMatch(*
this);
1454 matched = oneTest ? matchHere() : eng->bruteMatch(*
this);
1464 int numCaptures = (capturedSize - 2) >> 1;
1465 #ifndef QT_NO_REGEXP_CAPTURE 1466 for (
int i = 0; i < numCaptures; ++i) {
1467 int j = eng->captureForOfficialCapture.at(i);
1469 int len = capEnd[j] - capBegin[j];
1470 *c++ = (len > 0) ? pos + capBegin[j] : 0;
1480 memset(captured, -1, capturedSize *
sizeof(
int));
1496 #ifndef QT_NO_REGEXP_CCLASS 1506 #ifndef QT_NO_REGEXP_BACKREF 1530 for (
int i = 0; i < from.
size(); i++)
1534 #ifndef QT_NO_REGEXP_CAPTURE 1537 for (
int i = 0; i < from.
size(); i++) {
1542 for (
int j = 0; j < to.
size(); j++) {
1553 #ifndef QT_NO_REGEXP_ANCHOR_ALT 1563 #ifndef QT_NO_REGEXP_OPTIM 1564 if (n > 0 &&
aa.
at(n - 1).
a == a &&
aa.
at(n - 1).
b == b)
1565 return Anchor_Alternation | (n - 1);
1570 return Anchor_Alternation | n;
1580 if ((b & Anchor_Alternation) != 0)
1601 #ifndef QT_NO_REGEXP_OPTIM 1634 int badCharScore = 0;
1638 badCharScore +=
minl;
1640 badCharScore +=
occ1.
at(i);
1642 badCharScore /=
minl;
1648 #if defined(QT_DEBUG) 1652 qDebug(
"Case %ssensitive engine",
cs ?
"" :
"in");
1654 for (i = 0; i <
s.
size(); i++) {
1656 #ifndef QT_NO_REGEXP_CAPTURE 1658 qDebug(
" in atom %d",
s[i].atom);
1662 qDebug(
" match character class %d", m ^ CharClassBit);
1663 #ifndef QT_NO_REGEXP_CCLASS 1666 qDebug(
" negative character class");
1669 qDebug(
" match back-reference %d", m ^ BackRefBit);
1670 }
else if (m >= 0x20 && m <= 0x7e) {
1671 qDebug(
" match 0x%.4x (%c)", m, m);
1673 qDebug(
" match 0x%.4x", m);
1675 for (j = 0; j <
s[i].outs.
size(); j++) {
1676 int next =
s[i].outs[j];
1679 qDebug(
" [reenter %d]",
s[i].reenter[next]);
1680 if (
s[i].anchors.
value(next) != 0)
1681 qDebug(
" [anchors 0x%.8x]",
s[i].anchors[next]);
1684 #ifndef QT_NO_REGEXP_CAPTURE 1686 qDebug(
" Atom Parent Capture");
1687 for (i = 0; i <
nf; i++) {
1689 qDebug(
" %6d %6d nil", i,
f[i].parent);
1691 int cap =
f[i].capture;
1693 qDebug(
" %6d %6d %6d %s", i,
f[i].parent,
f[i].capture,
1694 official ?
"official" :
"");
1699 #ifndef QT_NO_REGEXP_ANCHOR_ALT 1700 for (i = 0; i <
aa.
size(); i++)
1701 qDebug(
" Anchor alternation 0x%.8x: 0x%.8x 0x%.9x", i,
aa[i].a,
aa[i].b);
1709 #ifndef QT_NO_REGEXP_CAPTURE 1716 #ifndef QT_NO_REGEXP_OPTIM 1721 #ifndef QT_NO_REGEXP_BACKREF 1724 #ifndef QT_NO_REGEXP_OPTIM 1733 #ifndef QT_NO_REGEXP_CAPTURE 1738 return s.
size() - 1;
1741 #ifndef QT_NO_REGEXP_CAPTURE 1765 #ifndef QT_NO_REGEXP_LOOKAHEAD 1772 if (n == MaxLookaheads) {
1781 #ifndef QT_NO_REGEXP_CAPTURE 1788 for (
int i = 0; i <
ncap; i++) {
1789 int delta = begin2[i] - begin1[i];
1791 delta = end1[i] - end2[i];
1808 #ifndef QT_NO_REGEXP_ANCHOR_ALT 1810 return testAnchor(i, eng->aa.at(a ^ QRegExpEngine::Anchor_Alternation).a, capBegin)
1811 || testAnchor(i, eng->aa.at(a ^ QRegExpEngine::Anchor_Alternation).b, capBegin);
1815 if (pos + i != caretPos)
1822 #ifndef QT_NO_REGEXP_ESCAPE 1824 bool before =
false;
1827 before =
isWord(in[pos + i - 1]);
1829 after =
isWord(in[pos + i]);
1836 #ifndef QT_NO_REGEXP_LOOKAHEAD 1839 for (j = 0; j < ahead.
size(); j++) {
1843 matchState.
match(in + pos + i, len - pos - i, 0,
1844 true,
true, caretPos - pos - i);
1845 if ((matchState.
captured[0] == 0) == ahead[j]->neg)
1851 #ifndef QT_NO_REGEXP_CAPTURE 1852 #ifndef QT_NO_REGEXP_BACKREF 1853 for (j = 0; j < eng->nbrefs; j++) {
1855 int i = eng->captureForOfficialCapture.at(j);
1865 #ifndef QT_NO_REGEXP_OPTIM 1876 while ((k = matcher.indexIn(matchState.
in, matchState.
len, k)) != -1) {
1879 if (from > matchState.
pos)
1880 matchState.
pos = from;
1882 while (matchState.
pos <= to) {
1897 int lastPos = matchState.
len -
minl;
1904 for (i = 0; i <
minl; i++) {
1919 if (matchState.
pos > lastPos)
1925 if (matchState.
slideTab[slideHead] > 0) {
1928 matchState.
slideTab[slideHead] = 0;
1934 if (matchState.
pos == lastPos)
1944 }
else if (sk > 0) {
1945 int k = slideNext + minl - sk;
1951 slideHead = slideNext;
1959 while (matchState.
pos <= matchState.
len) {
1973 int ncur = 1, nnext = 0;
1978 oneTestMatchedLen = -1;
1981 int ncap = eng->ncap;
1982 #ifndef QT_NO_REGEXP_CAPTURE 1984 for (j = 0; j <
ncap; j++) {
1991 #ifndef QT_NO_REGEXP_BACKREF 1992 while ((ncur > 0 || !sleeping.isEmpty()) && i <= len - pos && !stop)
1994 while (ncur > 0 && i <= len - pos && !stop)
1997 int ch = (i < len - pos) ? in[pos + i].unicode() : 0;
1998 for (j = 0; j < ncur; j++) {
1999 int cur = curStack[j];
2002 for (k = 0; k < outs.
size(); k++) {
2003 int next = outs.
at(k);
2006 #if !defined(QT_NO_REGEXP_BACKREF) && !defined(QT_NO_REGEXP_CAPTURE) 2007 int needSomeSleep = 0;
2014 if (a != 0 && !testAnchor(i, a, curCapBegin + j * ncap))
2033 #ifndef QT_NO_REGEXP_CCLASS 2038 inside = cc.
in(
QChar(ch).toLower()) &&
2041 inside = cc.
in(
QChar(ch).toLower()) ||
2044 #if !defined(QT_NO_REGEXP_BACKREF) && !defined(QT_NO_REGEXP_CAPTURE) 2047 int ell = j * ncap + eng->captureForOfficialCapture.at(bref - 1);
2049 inside = bref <= ncap && curCapBegin[ell] !=
EmptyCapture;
2052 inside = (in[pos + curCapBegin[ell]] ==
QChar(ch));
2054 inside = (in[pos + curCapBegin[ell]].toLower()
2061 delta = i - curCapBegin[ell];
2063 delta = curCapEnd[ell] - curCapBegin[ell];
2065 inside = (delta <= len - (pos + i));
2066 if (inside && delta > 1) {
2070 if (in[pos + curCapBegin[ell] + n]
2077 QChar a = in[pos + curCapBegin[ell] + n];
2078 QChar b = in[pos + i + n];
2084 inside = (n == delta);
2086 needSomeSleep = delta - 1;
2097 #ifndef QT_NO_REGEXP_CAPTURE 2098 int *capBegin, *capEnd;
2104 if ((m = inNextStack[next]) == -1) {
2106 nextStack[m] = next;
2107 inNextStack[next] = m;
2108 #ifndef QT_NO_REGEXP_CAPTURE 2109 capBegin = nextCapBegin + m *
ncap;
2110 capEnd = nextCapEnd + m *
ncap;
2119 capBegin = tempCapBegin;
2120 capEnd = tempCapEnd;
2124 #ifndef QT_NO_REGEXP_CAPTURE 2129 memcpy(capBegin, curCapBegin + j * ncap, ncap *
sizeof(
int));
2130 memcpy(capEnd, curCapEnd + j * ncap, ncap *
sizeof(
int));
2151 for (
int ell = q + 1; ell < eng->nf; ell++) {
2152 if (b.
testBit(eng->f.at(ell).parent)) {
2154 cap = eng->f.at(ell).capture;
2161 p = eng->f.at(q).parent;
2180 cap = eng->f.at(p).capture;
2182 if (capBegin[cap] == i) {
2189 p = eng->f.at(p).parent;
2191 q = eng->f.at(q).parent;
2203 cap = eng->f.at(n).capture;
2208 n = eng->f.at(n).parent;
2215 if (capBegin == tempCapBegin &&
2217 nextCapEnd + m * ncap)) {
2218 memcpy(nextCapBegin + m * ncap, capBegin, ncap *
sizeof(
int));
2219 memcpy(nextCapEnd + m * ncap, capEnd, ncap *
sizeof(
int));
2222 #ifndef QT_NO_REGEXP_BACKREF 2229 if (needSomeSleep > 0) {
2231 zzZ[0] = i + needSomeSleep;
2234 memcpy(zzZ.
data() + 2, capBegin, ncap *
sizeof(int));
2235 memcpy(zzZ.
data() + 2 +
ncap, capEnd, ncap *
sizeof(int));
2237 inNextStack[nextStack[--nnext]] = -1;
2238 sleeping.append(zzZ);
2245 #ifndef QT_NO_REGEXP_CAPTURE 2251 memcpy(capBegin, nextCapBegin + m * ncap, ncap *
sizeof(
int));
2252 memcpy(capEnd, nextCapEnd + m * ncap, ncap *
sizeof(
int));
2254 #ifndef QT_NO_REGEXP_BACKREF 2259 while (j < sleeping.count()) {
2260 if (sleeping.at(j)[0] == i) {
2263 const int *capBegin = zzZ.
data() + 2;
2264 const int *capEnd = zzZ.
data() + 2 +
ncap;
2265 bool copyOver =
true;
2267 if ((m = inNextStack[next]) == -1) {
2269 nextStack[m] = next;
2270 inNextStack[next] = m;
2272 copyOver =
isBetterCapture(ncap, nextCapBegin + m * ncap, nextCapEnd + m * ncap,
2276 memcpy(nextCapBegin + m * ncap, capBegin, ncap *
sizeof(
int));
2277 memcpy(nextCapEnd + m * ncap, capEnd, ncap *
sizeof(
int));
2280 sleeping.removeAt(j);
2287 for (j = 0; j < nnext; j++)
2288 inNextStack[nextStack[j]] = -1;
2291 if (nnext == 1 && nextStack[0] == QRegExpEngine::FinalState
2292 #ifndef QT_NO_REGEXP_BACKREF
2293 && sleeping.isEmpty()
2298 qSwap(curStack, nextStack);
2299 #ifndef QT_NO_REGEXP_CAPTURE 2300 qSwap(curCapBegin, nextCapBegin);
2301 qSwap(curCapEnd, nextCapEnd);
2308 #ifndef QT_NO_REGEXP_BACKREF 2313 if (!sleeping.isEmpty())
2317 oneTestMatchedLen = i - 1;
2318 return (matchLen >= 0);
2321 #ifndef QT_NO_REGEXP_CCLASS 2326 #ifndef QT_NO_REGEXP_OPTIM 2336 #ifndef QT_NO_REGEXP_OPTIM 2352 #ifndef QT_NO_REGEXP_OPTIM 2360 #ifndef QT_NO_REGEXP_OPTIM 2372 r[m].len = to - from + 1;
2374 #ifndef QT_NO_REGEXP_OPTIM 2379 for (i = from % NumBadChars; i <= to %
NumBadChars; i++)
2384 for (i = from % NumBadChars; i <
NumBadChars; i++)
2395 #ifndef QT_NO_REGEXP_OPTIM 2400 if (
c != 0 && (
c & (1 << (
int)ch.
category())) != 0)
2404 int size =
r.
size();
2406 for (
int i = 0; i < size; ++i) {
2414 #if defined(QT_DEBUG) 2418 qDebug(
" %stive character class",
n ?
"nega" :
"posi");
2419 #ifndef QT_NO_REGEXP_CCLASS 2421 qDebug(
" categories 0x%.8x",
c);
2423 for (i = 0; i <
r.
size(); i++)
2424 qDebug(
" 0x%.4x through 0x%.4x",
r[i].from,
r[i].from +
r[i].len - 1);
2430 : eng(engine), skipanchors(0)
2431 #ifndef QT_NO_REGEXP_OPTIM
2432 , earlyStart(0), lateStart(0), maxl(0)
2435 #ifndef QT_NO_REGEXP_OPTIM 2449 #ifndef QT_NO_REGEXP_OPTIM 2467 #ifndef QT_NO_REGEXP_OPTIM 2482 #ifndef QT_NO_REGEXP_OPTIM 2489 #ifndef QT_NO_REGEXP_BACKREF 2497 #ifndef QT_NO_REGEXP_OPTIM 2511 for (
int i = 0; i < b.
ls.
size(); i++) {
2521 for (
int i = 0; i <
rs.
size(); i++) {
2532 #ifndef QT_NO_REGEXP_OPTIM 2588 #ifndef QT_NO_REGEXP_OPTIM 2607 #ifndef QT_NO_REGEXP_CAPTURE 2614 #ifndef QT_NO_REGEXP_OPTIM 2621 #ifndef QT_NO_REGEXP_OPTIM 2635 for (
int i = 0; i <
rs.
size(); i++) {
2644 #ifndef QT_NO_REGEXP_OPTIM 2675 #if defined(QT_DEBUG) 2679 qDebug(
"Box of at least %d character%s",
minl,
minl == 1 ?
"" :
"s");
2681 for (i = 0; i <
ls.
size(); i++) {
2687 qDebug(
" Right states:");
2688 for (i = 0; i <
rs.
size(); i++) {
2700 for (
int i = 0; i < to.
ls.
size(); i++) {
2701 for (
int j = 0; j <
rs.
size(); j++) {
2862 #ifndef QT_NO_REGEXP_ESCAPE 2863 const char tab[] =
"afnrtv";
2864 const char backTab[] =
"\a\f\n\r\t\v";
2871 if (prevCh ==
EOS) {
2876 #ifndef QT_NO_REGEXP_ESCAPE 2877 if ((prevCh & ~0xff) == 0) {
2878 const char *p = strchr(tab, prevCh);
2880 return Tok_Char | backTab[p - tab];
2885 #ifndef QT_NO_REGEXP_ESCAPE 2888 for (i = 0; i < 3; i++) {
2890 val = (val << 3) | (
yyCh -
'0');
2895 if ((val & ~0377) != 0)
2899 #ifndef QT_NO_REGEXP_ESCAPE 2903 #ifndef QT_NO_REGEXP_CCLASS 2928 #ifndef QT_NO_REGEXP_ESCAPE 2932 #ifndef QT_NO_REGEXP_CCLASS 3019 while (
yyCh !=
'}') {
3029 if (category ==
"M") {
3031 }
else if (category ==
"Mn") {
3033 }
else if (category ==
"Mc") {
3035 }
else if (category ==
"Me") {
3037 }
else if (category ==
"N") {
3039 }
else if (category ==
"Nd") {
3041 }
else if (category ==
"Nl") {
3043 }
else if (category ==
"No") {
3045 }
else if (category ==
"Z") {
3047 }
else if (category ==
"Zs") {
3049 }
else if (category ==
"Zl") {
3051 }
else if (category ==
"Zp") {
3053 }
else if (category ==
"C") {
3055 }
else if (category ==
"Cc") {
3057 }
else if (category ==
"Cf") {
3059 }
else if (category ==
"Cs") {
3061 }
else if (category ==
"Co") {
3063 }
else if (category ==
"Cn") {
3065 }
else if (category ==
"L") {
3067 }
else if (category ==
"Lu") {
3069 }
else if (category ==
"Ll") {
3071 }
else if (category ==
"Lt") {
3073 }
else if (category ==
"Lm") {
3075 }
else if (category ==
"Lo") {
3077 }
else if (category ==
"P") {
3079 }
else if (category ==
"Pc") {
3081 }
else if (category ==
"Pd") {
3083 }
else if (category ==
"Ps") {
3085 }
else if (category ==
"Pe") {
3087 }
else if (category ==
"Pi") {
3089 }
else if (category ==
"Pf") {
3091 }
else if (category ==
"Po") {
3093 }
else if (category ==
"S") {
3095 }
else if (category ==
"Sm") {
3097 }
else if (category ==
"Sc") {
3099 }
else if (category ==
"Sk") {
3101 }
else if (category ==
"So") {
3119 #ifndef QT_NO_REGEXP_ESCAPE 3122 for (i = 0; i < 4; i++) {
3124 if (low >=
'0' && low <=
'9')
3125 val = (val << 4) | (low -
'0');
3126 else if (low >=
'a' && low <=
'f')
3127 val = (val << 4) | (low -
'a' + 10);
3135 if (prevCh >=
'1' && prevCh <=
'9') {
3136 #ifndef QT_NO_REGEXP_BACKREF 3138 while (
yyCh >=
'0' &&
yyCh <=
'9') {
3139 val = (val * 10) + (
yyCh -
'0');
3151 #ifndef QT_NO_REGEXP_INTERVAL 3157 rep = 10 * rep +
yyCh -
'0';
3163 }
while (
yyCh >=
'0' &&
yyCh <=
'9');
3171 #ifndef QT_NO_REGEXP_LOOKAHEAD 3202 #ifndef QT_NO_REGEXP_CCLASS 3211 #ifndef QT_NO_REGEXP_CCLASS 3229 #ifndef QT_NO_REGEXP_LOOKAHEAD 3258 #ifndef QT_NO_REGEXP_CCLASS 3267 #ifndef QT_NO_REGEXP_CCLASS 3272 charPending =
false;
3273 rangePending =
false;
3275 if (
yyCh ==
'-' && charPending && !rangePending) {
3276 rangePending =
true;
3279 if (charPending && !rangePending) {
3281 charPending =
false;
3296 charPending =
false;
3297 rangePending =
false;
3299 }
else if ((tok &
Tok_Char) != 0) {
3302 charPending =
false;
3303 rangePending =
false;
3334 #ifndef QT_NO_REGEXP_INTERVAL 3366 #ifndef QT_NO_REGEXP_CAPTURE 3372 #ifndef QT_NO_REGEXP_CAPTURE 3379 rightBox.
set(anything);
3381 Box middleBox(
this);
3383 #ifndef QT_NO_REGEXP_CAPTURE 3386 #ifndef QT_NO_REGEXP_OPTIM 3393 #ifndef QT_NO_REGEXP_CAPTURE 3394 for (
int i = 0; i <
nf; ++i) {
3395 switch (
f[i].capture) {
3399 f[i].capture =
ncap;
3409 #ifndef QT_NO_REGEXP_BACKREF 3410 #ifndef QT_NO_REGEXP_OPTIM 3428 #ifndef QT_NO_REGEXP_OPTIM 3436 #ifndef QT_NO_REGEXP_ANCHOR_ALT
3449 int numStates =
s.
count();
3450 for (
int i = 0; i < numStates; ++i) {
3468 #ifndef QT_NO_REGEXP_LOOKAHEAD 3477 #ifndef QT_NO_REGEXP_OPTIM 3487 #ifndef QT_NO_REGEXP_LOOKAHEAD 3503 #ifndef QT_NO_REGEXP_ESCAPE 3525 #ifndef QT_NO_REGEXP_BACKREF 3538 #ifndef QT_NO_REGEXP_CAPTURE 3543 const int innerAtom = -1;
3546 #ifndef QT_NO_REGEXP_INTERVAL 3548 yyIn = in, yyPos0 = pos0, yyPos = pos, yyLen = len, yyCh = ch, \ 3549 *yyCharClass = charClass, yyMinRep = 0, yyMaxRep = 0, yyTok = tok 3564 #ifndef QT_NO_REGEXP_CAPTURE 3569 if (hasQuantifier) {
3570 #ifndef QT_NO_REGEXP_OPTIM 3574 box->
plus(innerAtom);
3575 #ifndef QT_NO_REGEXP_INTERVAL 3583 #ifndef QT_NO_REGEXP_INTERVAL 3591 for (i = 0; i < beta; i++) {
3595 leftBox.
cat(rightBox);
3599 for (i = 0; i < alpha; i++) {
3603 leftBox.
cat(rightBox);
3610 #ifndef QT_NO_REGEXP_INTERVAL 3615 #ifndef QT_NO_REGEXP_CAPTURE 3623 #ifndef QT_NO_REGEXP_OPTIM 3638 #ifndef QT_NO_REGEXP_OPTIM 3659 #ifndef QT_NO_REGEXP_CAPTURE 3668 : eng(0), engineKey(key), minimal(false) {}
3671 #if !defined(QT_NO_REGEXP_OPTIM) 3680 #endif // QT_NO_REGEXP_OPTIM 3685 #if !defined(QT_NO_REGEXP_OPTIM) 3686 if (globalEngineCache()) {
3689 globalEngineCache()->insert(key, eng, 4 + key.
pattern.
length() / 4);
3690 }
QT_CATCH(
const std::bad_alloc &) {
3706 bool initMatchState = !priv->
eng;
3707 #if !defined(QT_NO_REGEXP_OPTIM) 3708 if (!priv->
eng && globalEngineCache()) {
3710 priv->
eng = globalEngineCache()->take(priv->
engineKey);
3714 #endif // QT_NO_REGEXP_OPTIM 3734 #ifndef QT_NO_REGEXP_CAPTURE 3744 if (priv->
eng != 0) {
3861 priv->eng = otherEng;
3864 #ifndef QT_NO_REGEXP_CAPTURE 3869 priv->matchState.prepareForMatch(
priv->eng);
3927 return priv->engineKey.pattern.isEmpty();
3945 if (
priv->engineKey.pattern.isEmpty()) {
3949 return priv->eng->isValid();
3962 return priv->engineKey.pattern;
3973 if (
priv->engineKey.pattern != pattern) {
3975 priv->engineKey.pattern = pattern;
3987 return priv->engineKey.cs;
4000 if ((
bool)cs != (
bool)
priv->engineKey.cs) {
4014 return priv->engineKey.patternSyntax;
4034 if (syntax !=
priv->engineKey.patternSyntax) {
4036 priv->engineKey.patternSyntax = syntax;
4048 return priv->minimal;
4070 priv->minimal = minimal;
4098 if (
priv->matchState.captured[1] == str.
length()) {
4101 priv->matchState.captured[0] = 0;
4102 priv->matchState.captured[1] =
priv->matchState.oneTestMatchedLen;
4143 return priv->matchState.captured[0];
4172 if (offset < 0 || offset > str.
length()) {
4173 memset(
priv->matchState.captured, -1,
priv->matchState.capturedSize*
sizeof(
int));
4177 while (offset >= 0) {
4180 if (
priv->matchState.captured[0] == offset)
4195 return priv->matchState.captured[1];
4198 #ifndef QT_NO_REGEXP_CAPTURE 4200 #ifndef QT_NO_DEPRECATED 4226 return priv->eng->captureCount();
4269 if (
priv->capturedCache.isEmpty()) {
4271 const int *captured =
priv->matchState.captured;
4272 int n =
priv->matchState.capturedSize;
4274 for (
int i = 0; i < n; i += 2) {
4276 if (captured[i + 1] == 0)
4278 else if (captured[i] >= 0)
4279 m =
priv->t.mid(captured[i], captured[i + 1]);
4280 priv->capturedCache.append(m);
4284 return priv->capturedCache;
4292 return const_cast<const QRegExp *
>(
this)->capturedTexts();
4312 return capturedTexts().value(nth);
4320 return const_cast<const QRegExp *
>(
this)->cap(nth);
4339 if (nth < 0 || nth >=
priv->matchState.capturedSize / 2)
4342 return priv->matchState.captured[2 * nth];
4350 return const_cast<const QRegExp *
>(
this)->pos(nth);
4364 return priv->eng->errorString();
4395 const int count = str.
count();
4398 for (
int i = 0; i < count; i++) {
4414 quoted.
append(backslash);
4510 #ifndef QT_NO_DATASTREAM 4545 in >> pattern >> cs >> patternSyntax >> isMinimal;
4554 #endif // QT_NO_DATASTREAM
Box(QRegExpEngine *engine)
Q_DECLARE_TYPEINFO(QRegExpAutomatonState, Q_MOVABLE_TYPE)
~QRegExp()
Destroys the regular expression and cleans up its internal data.
int parse(const QChar *rx, int len)
void setBit(int i)
Sets the bit at index position i to 1.
QString cap(int nth=0) const
Returns the text captured by the nth subexpression.
void setPatternSyntax(PatternSyntax syntax)
Sets the syntax mode for the regular expression.
QRegExpCharClass & operator=(const QRegExpCharClass &cc)
#define QT_END_NAMESPACE
This macro expands to.
The QMutex class provides access serialization between threads.
QStringList capturedCache
int lastIndexIn(const QString &str, int offset=-1, CaretMode caretMode=CaretAtZero) const
Attempts to find a match backwards in str from position offset.
void addRange(ushort from, ushort to)
QHash< QByteArray, QPair< int, int > > categoriesRangeMap
const QChar at(int i) const
Returns the character at the given index position in the string.
The QRegExp class provides pattern matching using regular expressions.
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QVector< T > & fill(const T &t, int size=-1)
Assigns value to all items in the vector.
The QAtomicInt class provides platform-independent atomic operations on integers. ...
bool goodStringMatch(QRegExpMatchState &matchState) const
int count(const T &t) const
Returns the number of occurrences of value in the vector.
QByteArray & append(char c)
Appends the character ch to this byte array.
void addPlusTransitions(const QVector< int > &from, const QVector< int > &to, int atom)
QString errorString() const
Returns a text string that explains why a regexp pattern is invalid the case being; otherwise returns...
uint qHash(const QRegExpEngineKey &key)
void addSingleton(ushort ch)
QCache< QRegExpEngineKey, QRegExpEngine > EngineCache
int anchorAlternation(int a, int b)
The QByteArray class provides an array of bytes.
int length() const
Returns the number of characters in this string.
QVector< int > captureForOfficialCapture
void error(const char *msg)
void setPattern(const QString &pattern)
Sets the pattern string to pattern.
bool badCharMatch(QRegExpMatchState &matchState) const
void heuristicallyChooseHeuristic()
static void mergeInto(QVector< int > *a, const QVector< int > &b)
QRegExpCharClass(const QRegExpCharClass &cc)
QRegExp & operator=(const QRegExp &rx)
Copies the regular expression rx and returns a reference to the copy.
Box & operator=(const Box &b)
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
static bool match(const uchar *found, const char *target, uint len)
int pos(int nth=0) const
Returns the position of the nth captured text in the searched string.
int matchedLength() const
Returns the length of the last matched string, or -1 if there was no match.
QT_DEPRECATED int numCaptures() const
Returns the number of captures contained in the regular expression.
QRegExpLookahead(QRegExpEngine *eng0, bool neg0)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qBinaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
QRegExpMatchState matchState
long ASN1_INTEGER_get ASN1_INTEGER * a
QRegExpPrivate(const QRegExpEngineKey &key)
bool ref()
Atomically increments the value of this QAtomicInt.
void parseExpression(Box *box)
The QString class provides a Unicode character string.
QRegExp::PatternSyntax patternSyntax
Q_STATIC_GLOBAL_OPERATOR bool operator==(const QRegExpEngineKey &key1, const QRegExpEngineKey &key2)
The QHash class is a template class that provides a hash-table-based dictionary.
bool testBit(int i) const
Returns true if the bit at index position i is 1; otherwise returns false.
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
static int caretIndex(int offset, QRegExp::CaretMode caretMode)
Qt::CaseSensitivity caseSensitivity() const
Returns Qt::CaseSensitive if the regexp is matched case sensitively; otherwise returns Qt::CaseInsens...
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
static void prepareEngine_helper(QRegExpPrivate *priv)
The QChar class provides a 16-bit Unicode character.
const T value(const Key &key) const
Returns the value associated with the key.
The QStringMatcher class holds a sequence of characters that can be quickly matched in a Unicode stri...
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Category category() const
Returns the character's category.
static bool isWord(QChar ch)
void resize(int size)
Sets the size of the vector to size.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
QMap< Key, T > & unite(const QMap< Key, T > &other)
Inserts all the items in the other map into this map.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
int anchorConcatenation(int a, int b)
bool isValid() const
Returns true if the regular expression is valid; otherwise returns false.
Q_CORE_EXPORT void qDebug(const char *,...)
const QRegExpEngine * eng
void reserve(int size)
Attempts to allocate memory for at least size characters.
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
void setMinimal(bool minimal)
Enables or disables minimal matching.
static QString wc2rx(const QString &wc_str, const bool enableEscaping)
int addLookahead(QRegExpEngine *eng, bool negative)
#define QT_BEGIN_NAMESPACE
This macro expands to.
void setNegative(bool negative)
int setupState(int match)
int indexIn(const QString &str, int offset=0, CaretMode caretMode=CaretAtZero) const
Attempts to find a match in str from position offset (0 by default).
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
const QChar * unicode() const
Returns a '\0'-terminated Unicode representation of the string.
QStringList capturedTexts() const
Returns a list of the captured text strings.
int qFindString(const QChar *haystack, int haystackLen, int from, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
T value(int i) const
Returns the value at index position i in the vector.
void prepareForMatch(QRegExpEngine *eng)
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
const T value(const Key &key) const
Returns the value associated with the key key.
static unsigned int getChar(const QChar *str, int &i, const int len)
static bool isBetterCapture(int ncap, const int *begin1, const int *end1, const int *begin2, const int *end2)
Q_CORE_EXPORT QString qt_regexp_toCanonical(const QString &pattern, QRegExp::PatternSyntax patternSyntax)
#define Q_STATIC_GLOBAL_OPERATOR
bool deref()
Atomically decrements the value of this QAtomicInt.
The QStringList class provides a list of strings.
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
void append(const T &t)
Inserts value at the end of the vector.
static int getEscape(const QChar *uc, int *pos, int len, int maxNumber=999)
void parseFactor(Box *box)
void clear()
Removes all items from the list.
QRegExp()
Constructs an empty regexp.
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the map.
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
void qSwap(T &value1, T &value2)
void addAnchors(int from, int to, int a)
const T & at(int i) const
Returns the item at index position i in the vector.
QVector< QRegExpCharClassRange > r
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
The QBitArray class provides an array of bits.
void setupCategoriesRangeMap()
QVector< QRegExpAnchorAlternation > aa
void addCatTransitions(const QVector< int > &from, const QVector< int > &to)
bool useGoodStringHeuristic
bool isEmpty() const
Returns true if the pattern string is empty; otherwise returns false.
QString pattern() const
Returns the pattern string of the regular expression.
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map...
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
static void prepareEngine(QRegExpPrivate *priv)
QVector< QRegExpCharClass > cl
PatternSyntax patternSyntax() const
Returns the syntax used by the regular expression.
QString & append(QChar c)
PatternSyntax
The syntax used to interpret the meaning of the pattern.
static void derefEngine(QRegExpEngine *eng, const QRegExpEngineKey &key)
QRegExpEngine(Qt::CaseSensitivity cs, bool greedyQuantifiers)
QVector< QRegExpLookahead * > ahead
void clear()
Clears the contents of the string and makes it empty.
QList< QVector< int > > sleeping
int captureCount() const
Returns the number of captures contained in the regular expression.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
static void prepareEngineForMatch(QRegExpPrivate *priv, const QString &str)
void finishAtom(int atom, bool needCapture)
int startAtom(bool officialCapture)
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
QRegExpEngineKey(const QString &pattern, QRegExp::PatternSyntax patternSyntax, Qt::CaseSensitivity cs)
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
#define st(var, type, card)
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
QScopedPointer< QRegExpCharClass > yyCharClass
bool isEmpty() const
Returns true if the map contains no items; otherwise returns false.
if(void) toggleToolbarShown
void addCategories(int cats)
bool contains(const Key &key) const
Returns true if the map contains an item with key key; otherwise returns false.
static QString dump(const QByteArray &)
bool contains(const T &t) const
Returns true if the vector contains an occurrence of value; otherwise returns false.
char toLatin1() const
Returns the Latin-1 character equivalent to the QChar, or 0.
QDataStream & operator<<(QDataStream &out, const QRegExp ®Exp)
Writes the regular expression regExp to stream out.
bool exactMatch(const QString &str) const
Returns true if str is matched exactly by this regular expression; otherwise returns false...
QMap< int, int > lanchors
bool operator==(const QRegExp &rx) const
Returns true if this regular expression is equal to rx; otherwise returns false.
iterator erase(iterator it)
Removes the (key, value) pair pointed to by the iterator pos from the map, and returns an iterator to...
bool isMark() const
Returns true if the character is a mark (Mark_* categories); otherwise returns false.
CaretMode
The CaretMode enum defines the different meanings of the caret (^) in a regular expression.
T * data()
Returns a pointer to the data stored in the vector.
void setCaseSensitivity(Qt::CaseSensitivity cs)
Sets case sensitive matching to cs.
QRegExpEngineKey engineKey
The QDataStream class provides serialization of binary data to a QIODevice.
QRegExpAutomatonState(int a, int m)
const QString & errorString() const
const T * constData() const
Returns a const pointer to the data stored in the vector.
int createState(QChar ch)
bool testAnchor(int i, int a, const int *capBegin)
QVector< QRegExpAutomatonState > s
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
QDataStream & operator>>(QDataStream &in, QRegExp ®Exp)
Reads a regular expression from stream in into regExp.
QChar toLower() const
Returns the lowercase equivalent if the character is uppercase or titlecase; otherwise returns the ch...
int size() const
Returns the number of items in the vector.
const QVector< int > & firstOccurrence() const
void startTokenizer(const QChar *rx, int len)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
void addAnchorsToEngine(const Box &to) const
static void invalidateEngine(QRegExpPrivate *priv)
void match(const QChar *str, int len, int pos, bool minimal, bool oneTest, int caretIndex)
QMap< int, int > ranchors
bool isLetterOrNumber() const
Returns true if the character is a letter or number (Letter_* or Number_* categories); otherwise retu...
The QList class is a template class that provides lists.
static QString escape(const QString &str)
Returns the string str with every regexp special character escaped with a backslash.
bool isMinimal() const
Returns true if minimal (non-greedy) matching is enabled; otherwise returns false.