Changeset View
Changeset View
Standalone View
Standalone View
src/utils/katesedcmd.cpp
Show All 25 Lines | |||||
26 | #include "kateview.h" | 26 | #include "kateview.h" | ||
27 | #include "kateglobal.h" | 27 | #include "kateglobal.h" | ||
28 | #include "katecmd.h" | 28 | #include "katecmd.h" | ||
29 | #include "katepartdebug.h" | 29 | #include "katepartdebug.h" | ||
30 | 30 | | |||
31 | #include <KLocalizedString> | 31 | #include <KLocalizedString> | ||
32 | 32 | | |||
33 | #include <QDir> | 33 | #include <QDir> | ||
34 | #include <QRegExp> | 34 | #include <QRegularExpression> | ||
35 | #include <QUrl> | 35 | #include <QUrl> | ||
36 | 36 | | |||
37 | KateCommands::SedReplace *KateCommands::SedReplace::m_instance = nullptr; | 37 | KateCommands::SedReplace *KateCommands::SedReplace::m_instance = nullptr; | ||
38 | 38 | | |||
39 | static int backslashString(const QString &haystack, const QString &needle, int index) | 39 | static int backslashString(const QString &haystack, const QString &needle, int index) | ||
40 | { | 40 | { | ||
41 | int len = haystack.length(); | 41 | int len = haystack.length(); | ||
42 | int searchlen = needle.length(); | 42 | int searchlen = needle.length(); | ||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Line(s) | |||||
150 | { | 150 | { | ||
151 | qCDebug(LOG_KTE) << "Interactive sedreplace is only currently supported with Vi mode plus Vi emulated command bar."; | 151 | qCDebug(LOG_KTE) << "Interactive sedreplace is only currently supported with Vi mode plus Vi emulated command bar."; | ||
152 | return false; | 152 | return false; | ||
153 | } | 153 | } | ||
154 | 154 | | |||
155 | bool KateCommands::SedReplace::parse(const QString &sedReplaceString, QString &destDelim, int &destFindBeginPos, int &destFindEndPos, int &destReplaceBeginPos, int &destReplaceEndPos) | 155 | bool KateCommands::SedReplace::parse(const QString &sedReplaceString, QString &destDelim, int &destFindBeginPos, int &destFindEndPos, int &destReplaceBeginPos, int &destReplaceEndPos) | ||
156 | { | 156 | { | ||
157 | // valid delimiters are all non-word, non-space characters plus '_' | 157 | // valid delimiters are all non-word, non-space characters plus '_' | ||
158 | QRegExp delim(QLatin1String("^s\\s*([^\\w\\s]|_)")); | 158 | QRegularExpression delim(QLatin1String("^s\\s*([^\\w\\s]|_)")); | ||
159 | if (delim.indexIn(sedReplaceString) < 0) { | 159 | auto match = delim.match(sedReplaceString); | ||
160 | if (!match.hasMatch()) { | ||||
160 | return false; | 161 | return false; | ||
161 | } | 162 | } | ||
162 | 163 | | |||
163 | QString d = delim.cap(1); | 164 | const QString d = match.captured(1); | ||
mwolff: here and below: capturedRef? | |||||
Can do, but some lines later, its converted to a QString anyways, so we don't gain anything :-) dhaumann: Can do, but some lines later, its converted to a QString anyways, so we don't gain anything :-) | |||||
164 | qCDebug(LOG_KTE) << "SedReplace: delimiter is '" << d << "'"; | 165 | qCDebug(LOG_KTE) << "SedReplace: delimiter is '" << d << "'"; | ||
165 | 166 | | |||
166 | QRegExp splitter(QStringLiteral("^s\\s*") + d + QLatin1String("((?:[^\\\\\\") + d + QLatin1String("]|\\\\.)*)\\") | 167 | QRegularExpression splitter(QStringLiteral("^s\\s*") + d + QLatin1String("((?:[^\\\\\\") + d + QLatin1String("]|\\\\.)*)\\") | ||
167 | + d + QLatin1String("((?:[^\\\\\\") + d + QLatin1String("]|\\\\.)*)(\\") + d + QLatin1String("[igc]{0,3})?$")); | 168 | + d + QLatin1String("((?:[^\\\\\\") + d + QLatin1String("]|\\\\.)*)(\\") + d + QLatin1String("[igc]{0,3})?$")); | ||
168 | if (splitter.indexIn(sedReplaceString) < 0) { | 169 | match = splitter.match(sedReplaceString); | ||
170 | if (!match.hasMatch()) { | ||||
169 | return false; | 171 | return false; | ||
170 | } | 172 | } | ||
171 | 173 | | |||
172 | const QString find = splitter.cap(1); | 174 | const QString find = match.captured(1); | ||
173 | const QString replace = splitter.cap(2); | 175 | const QString replace = match.captured(2); | ||
174 | 176 | | |||
175 | destDelim = d; | 177 | destDelim = d; | ||
176 | destFindBeginPos = splitter.pos(1); | 178 | destFindBeginPos = match.capturedStart(1); | ||
177 | destFindEndPos = splitter.pos(1) + find.length() - 1; | 179 | destFindEndPos = match.capturedStart(1) + find.length() - 1; | ||
178 | destReplaceBeginPos = splitter.pos(2); | 180 | destReplaceBeginPos = match.capturedStart(2); | ||
179 | destReplaceEndPos = splitter.pos(2) + replace.length() - 1; | 181 | destReplaceEndPos = match.capturedStart(2) + replace.length() - 1; | ||
180 | 182 | | |||
181 | return true; | 183 | return true; | ||
182 | } | 184 | } | ||
183 | 185 | | |||
184 | KateCommands::SedReplace::InteractiveSedReplacer::InteractiveSedReplacer(KTextEditor::DocumentPrivate *doc, const QString &findPattern, const QString &replacePattern, bool caseSensitive, bool onlyOnePerLine, int startLine, int endLine) | 186 | KateCommands::SedReplace::InteractiveSedReplacer::InteractiveSedReplacer(KTextEditor::DocumentPrivate *doc, const QString &findPattern, const QString &replacePattern, bool caseSensitive, bool onlyOnePerLine, int startLine, int endLine) | ||
185 | : m_findPattern(findPattern), | 187 | : m_findPattern(findPattern), | ||
186 | m_replacePattern(replacePattern), | 188 | m_replacePattern(replacePattern), | ||
187 | m_onlyOnePerLine(onlyOnePerLine), | 189 | m_onlyOnePerLine(onlyOnePerLine), | ||
▲ Show 20 Lines • Show All 115 Lines • Show Last 20 Lines |
here and below: capturedRef?