Changeset View
Changeset View
Standalone View
Standalone View
src/search/kateplaintextsearch.cpp
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 56 | if (m_wholeWords) { | |||
---|---|---|---|---|---|
60 | return KateRegExpSearch(m_document, m_caseSensitivity).search(workPattern, inputRange, backwards).at(0); | 60 | return KateRegExpSearch(m_document, m_caseSensitivity).search(workPattern, inputRange, backwards).at(0); | ||
61 | } | 61 | } | ||
62 | 62 | | |||
63 | if (text.isEmpty() || !inputRange.isValid() || (inputRange.start() == inputRange.end())) { | 63 | if (text.isEmpty() || !inputRange.isValid() || (inputRange.start() == inputRange.end())) { | ||
64 | return KTextEditor::Range::invalid(); | 64 | return KTextEditor::Range::invalid(); | ||
65 | } | 65 | } | ||
66 | 66 | | |||
67 | // split multi-line needle into single lines | 67 | // split multi-line needle into single lines | ||
68 | const QStringList needleLines = text.split(QLatin1Char('\n')); | 68 | const auto needleLines = text.splitRef(QLatin1Char('\n')); | ||
69 | 69 | | |||
70 | if (needleLines.count() > 1) { | 70 | if (needleLines.count() > 1) { | ||
71 | // multi-line plaintext search (both forwards or backwards) | 71 | // multi-line plaintext search (both forwards or backwards) | ||
72 | const int forMin = inputRange.start().line(); // first line in range | 72 | const int forMin = inputRange.start().line(); // first line in range | ||
73 | const int forMax = inputRange.end().line() + 1 - needleLines.count(); // last line in range | 73 | const int forMax = inputRange.end().line() + 1 - needleLines.count(); // last line in range | ||
74 | const int forInit = backwards ? forMax : forMin; | 74 | const int forInit = backwards ? forMax : forMin; | ||
75 | const int forInc = backwards ? -1 : +1; | 75 | const int forInc = backwards ? -1 : +1; | ||
76 | 76 | | |||
77 | for (int j = forInit; (forMin <= j) && (j <= forMax); j += forInc) { | 77 | for (int j = forInit; (forMin <= j) && (j <= forMax); j += forInc) { | ||
78 | // try to match all lines | 78 | // try to match all lines | ||
79 | const int startCol = m_document->lineLength(j) - needleLines[0].length(); | 79 | const int startCol = m_document->lineLength(j) - needleLines[0].length(); | ||
80 | for (int k = 0; k < needleLines.count(); k++) { | 80 | for (int k = 0; k < needleLines.count(); k++) { | ||
81 | // which lines to compare | 81 | // which lines to compare | ||
82 | const QString &needleLine = needleLines[k]; | 82 | const QStringRef &needleLine = needleLines[k]; | ||
83 | const QString &hayLine = m_document->line(j + k); | 83 | const QString &hayLine = m_document->line(j + k); | ||
84 | 84 | | |||
85 | // position specific comparison (first, middle, last) | 85 | // position specific comparison (first, middle, last) | ||
86 | if (k == 0) { | 86 | if (k == 0) { | ||
87 | // first line | 87 | // first line | ||
88 | if (forMin == j && startCol < inputRange.start().column()) { | 88 | if (forMin == j && startCol < inputRange.start().column()) { | ||
89 | break; | 89 | break; | ||
90 | } | 90 | } | ||
▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines |