1/*
2 SPDX-FileCopyrightText: 2008-2009 Erlend Hamberg <ehamberg@gmail.com>
3 SPDX-FileCopyrightText: 2011 Svyatoslav Kuzmich <svatoslav1@gmail.com>
4 SPDX-FileCopyrightText: 2012 Vegard Øye
5 SPDX-FileCopyrightText: 2013 Simon St James <kdedevel@etotheipiplusone.com>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#ifndef KATE_COMMAND_RANGE_EXPRESSION_PARSER_INCLUDED
11#define KATE_COMMAND_RANGE_EXPRESSION_PARSER_INCLUDED
12
13#include <ktexteditor/range.h>
14
15#include <QRegularExpression>
16
17namespace KTextEditor
18{
19class ViewPrivate;
20}
21
22class CommandRangeExpressionParser
23{
24public:
25 CommandRangeExpressionParser();
26 /**
27 * Attempt to parse any leading range expression (e.g. "%", "'<,'>", ".,+6" etc) in @c command and
28 * return it as a Range. If parsing was successful, the range will be valid, the string
29 * making up the range expression will be placed in @c destRangeExpression, and the command with
30 * the range stripped will be placed in @c destTransformedCommand. In some special cases,
31 * the @c destTransformedCommand will be further re-written e.g. a command in the form of just a number
32 * will be rewritten as "goto <number>".
33 *
34 * An invalid Range is returned if no leading range expression could be found.
35 */
36 static KTextEditor::Range
37 parseRangeExpression(const QString &command, KTextEditor::ViewPrivate *view, QString &destRangeExpression, QString &destTransformedCommand);
38
39private:
40 KTextEditor::Range
41 parseRangeExpression(const QString &command, QString &destRangeExpression, QString &destTransformedCommand, KTextEditor::ViewPrivate *view);
42 int calculatePosition(const QString &string, KTextEditor::ViewPrivate *view);
43 QString m_line;
44 QString m_lastLine;
45 QString m_thisLine;
46 QString m_mark;
47 QString m_forwardSearch;
48 QString m_forwardSearch2;
49 QString m_backwardSearch;
50 QString m_backwardSearch2;
51 QString m_base;
52 QString m_offset;
53 QString m_position;
54 QRegularExpression m_cmdRangeRegex;
55};
56
57#endif
58

source code of ktexteditor/src/utils/katecommandrangeexpressionparser.h