[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [ktexteditor] /: Bug 365124 - Regex capture groups for text fails beyond \9 (edit)
From: Christoph Cullmann <cullmann () kde ! org>
Date: 2016-09-08 17:39:10
Message-ID: E1bi3I6-0002lh-QG () code ! kde ! org
[Download RAW message or body]
Git commit a3c1bab8c301ae4af84a57b7d6bc2753bec40e7d by Christoph Cullmann.
Committed on 08/09/2016 at 17:38.
Pushed by cullmann into branch 'master'.
Bug 365124 - Regex capture groups for text fails beyond \9 (edit)
CHANGELOG: Support regular expressions replaces with captures > \9, e.g. \111
BUG: 365124
M +1 -1 autotests/src/searchbar_test.cpp
M +16 -3 src/search/kateregexpsearch.cpp
http://commits.kde.org/ktexteditor/a3c1bab8c301ae4af84a57b7d6bc2753bec40e7d
diff --git a/autotests/src/searchbar_test.cpp b/autotests/src/searchbar_test.cpp
index 207ee06..c5b8e69 100644
--- a/autotests/src/searchbar_test.cpp
+++ b/autotests/src/searchbar_test.cpp
@@ -636,7 +636,7 @@ void SearchBarTest::testReplaceManyCapturesBug365124()
bar.replaceAll();
- QCOMPARE(doc.text(), \
QString("one::two::three::four::five::six::seven::eight::nine::one0::one1::one2::one3\n"));
+ QCOMPARE(doc.text(), \
QString("one::two::three::four::five::six::seven::eight::nine::ten::eleven::twelve::thirteen\n"));
}
#include "moc_searchbar_test.cpp"
diff --git a/src/search/kateregexpsearch.cpp b/src/search/kateregexpsearch.cpp
index e82b605..1ba7abd 100644
--- a/src/search/kateregexpsearch.cpp
+++ b/src/search/kateregexpsearch.cpp
@@ -563,10 +563,23 @@ QVector<KTextEditor::Range> KateRegExpSearch::search(
case L'6':
case L'7':
case L'8':
- case L'9':
- out << ReplacementStream::cap(9 - (L'9' - text[input + \
1].unicode()));
- input += 2;
+ case L'9': {
+ // allow 1212124.... captures, see bug 365124 + \
testReplaceManyCapturesBug365124 + int capture = 9 - (L'9' - \
text[input + 1].unicode()); + int captureSize = 2;
+ while ((input + captureSize) < inputLen) {
+ const ushort nextDigit = text[input + captureSize].unicode();
+ if ((nextDigit >= L'0') && (nextDigit <= L'9')) {
+ capture = (10 * capture) + (9 - (L'9' - nextDigit));
+ ++captureSize;
+ continue;
+ }
+ break;
+ }
+ out << ReplacementStream::cap(capture);
+ input += captureSize;
break;
+ }
case L'E': // FALLTHROUGH
case L'L': // FALLTHROUGH
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic