summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoão Abecasis <joao@trolltech.com>2010-01-25 17:27:47 (GMT)
committerSamuli Piippo <samuli.piippo@digia.com>2011-06-09 10:05:00 (GMT)
commit02bf486331dc9cdcef46efaed0791c350111a3b3 (patch)
treee8ffcef680291f7a3553cfbce2768cfb1db77b74 /src
parent5cb86915503ff7b97bce1a09db27bea152269ed5 (diff)
downloadQt-02bf486331dc9cdcef46efaed0791c350111a3b3.zip
Qt-02bf486331dc9cdcef46efaed0791c350111a3b3.tar.gz
Qt-02bf486331dc9cdcef46efaed0791c350111a3b3.tar.bz2
QRegExp::pos() should return -1 for empty/non-matching captures
Instead, we were returning 0, even if this index did not belong to the match. Task-number: QTBUG-7049 Reviewed-by: Volker Hilsheimer Reviewed-by: Olivier Goffart (cherry picked from commit dadb99ea2c59d7d0f7a83134b7df5aaaaf80a995)
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qregexp.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp
index f3374ab..d69719d 100644
--- a/src/corelib/tools/qregexp.cpp
+++ b/src/corelib/tools/qregexp.cpp
@@ -1466,9 +1466,14 @@ void QRegExpMatchState::match(const QChar *str0, int len0, int pos0,
#ifndef QT_NO_REGEXP_CAPTURE
for (int i = 0; i < numCaptures; ++i) {
int j = eng->captureForOfficialCapture.at(i);
- int len = capEnd[j] - capBegin[j];
- *c++ = (len > 0) ? pos + capBegin[j] : 0;
- *c++ = len;
+ if (capBegin[j] != EmptyCapture) {
+ int len = capEnd[j] - capBegin[j];
+ *c++ = (len > 0) ? pos + capBegin[j] : 0;
+ *c++ = len;
+ } else {
+ *c++ = -1;
+ *c++ = -1;
+ }
}
#endif
} else {