Changeset View
Changeset View
Standalone View
Standalone View
src/utils/katesedcmd.cpp
Show First 20 Lines • Show All 179 Lines • ▼ Show 20 Line(s) | |||||
180 | } | 180 | } | ||
181 | 181 | | |||
182 | KateCommands::SedReplace::InteractiveSedReplacer::InteractiveSedReplacer(KTextEditor::DocumentPrivate *doc, const QString &findPattern, const QString &replacePattern, bool caseSensitive, bool onlyOnePerLine, int startLine, int endLine) | 182 | KateCommands::SedReplace::InteractiveSedReplacer::InteractiveSedReplacer(KTextEditor::DocumentPrivate *doc, const QString &findPattern, const QString &replacePattern, bool caseSensitive, bool onlyOnePerLine, int startLine, int endLine) | ||
183 | : m_findPattern(findPattern) | 183 | : m_findPattern(findPattern) | ||
184 | , m_replacePattern(replacePattern) | 184 | , m_replacePattern(replacePattern) | ||
185 | , m_onlyOnePerLine(onlyOnePerLine) | 185 | , m_onlyOnePerLine(onlyOnePerLine) | ||
186 | , m_endLine(endLine) | 186 | , m_endLine(endLine) | ||
187 | , m_doc(doc) | 187 | , m_doc(doc) | ||
188 | , m_regExpSearch(doc, caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive) | 188 | , m_regExpSearch(doc) | ||
189 | , m_caseSensitive(caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive) | ||||
189 | , m_numReplacementsDone(0) | 190 | , m_numReplacementsDone(0) | ||
190 | , m_numLinesTouched(0) | 191 | , m_numLinesTouched(0) | ||
191 | , m_lastChangedLineNum(-1) | 192 | , m_lastChangedLineNum(-1) | ||
192 | { | 193 | { | ||
193 | m_currentSearchPos = KTextEditor::Cursor(startLine, 0); | 194 | m_currentSearchPos = KTextEditor::Cursor(startLine, 0); | ||
194 | } | 195 | } | ||
195 | 196 | | |||
196 | KTextEditor::Range KateCommands::SedReplace::InteractiveSedReplacer::currentMatch() | 197 | KTextEditor::Range KateCommands::SedReplace::InteractiveSedReplacer::currentMatch() | ||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Line(s) | |||||
274 | } | 275 | } | ||
275 | 276 | | |||
276 | const QVector<KTextEditor::Range> KateCommands::SedReplace::InteractiveSedReplacer::fullCurrentMatch() | 277 | const QVector<KTextEditor::Range> KateCommands::SedReplace::InteractiveSedReplacer::fullCurrentMatch() | ||
277 | { | 278 | { | ||
278 | if (m_currentSearchPos > m_doc->documentEnd()) { | 279 | if (m_currentSearchPos > m_doc->documentEnd()) { | ||
279 | return QVector<KTextEditor::Range>(); | 280 | return QVector<KTextEditor::Range>(); | ||
280 | } | 281 | } | ||
281 | 282 | | |||
282 | return m_regExpSearch.search(m_findPattern, KTextEditor::Range(m_currentSearchPos, m_doc->documentEnd())); | 283 | QRegularExpression::PatternOptions options; | ||
284 | if (m_caseSensitive == Qt::CaseInsensitive) { | ||||
285 | options |= (QRegularExpression::CaseInsensitiveOption); | ||||
286 | } | ||||
287 | return m_regExpSearch.search(m_findPattern, KTextEditor::Range(m_currentSearchPos, m_doc->documentEnd()), false /* search backwards */, options); | ||||
283 | } | 288 | } | ||
284 | 289 | | |||
285 | QString KateCommands::SedReplace::InteractiveSedReplacer::replacementTextForCurrentMatch() | 290 | QString KateCommands::SedReplace::InteractiveSedReplacer::replacementTextForCurrentMatch() | ||
286 | { | 291 | { | ||
287 | const QVector<KTextEditor::Range> captureRanges = fullCurrentMatch(); | 292 | const QVector<KTextEditor::Range> captureRanges = fullCurrentMatch(); | ||
288 | QStringList captureTexts; | 293 | QStringList captureTexts; | ||
289 | for (KTextEditor::Range captureRange : captureRanges) { | 294 | for (KTextEditor::Range captureRange : captureRanges) { | ||
290 | captureTexts << m_doc->text(captureRange); | 295 | captureTexts << m_doc->text(captureRange); | ||
291 | } | 296 | } | ||
292 | const QString replacementText = m_regExpSearch.buildReplacement(m_replacePattern, captureTexts, 0); | 297 | const QString replacementText = m_regExpSearch.buildReplacement(m_replacePattern, captureTexts, 0); | ||
293 | return replacementText; | 298 | return replacementText; | ||
294 | } | 299 | } |