File indexing completed on 2024-04-28 11:45:56
0001 /* 0002 SPDX-FileCopyrightText: 2008-2009 Erlend Hamberg <ehamberg@gmail.com> 0003 SPDX-FileCopyrightText: 2011 Svyatoslav Kuzmich <svatoslav1@gmail.com> 0004 SPDX-FileCopyrightText: 2012 Vegard Øye 0005 SPDX-FileCopyrightText: 2013 Simon St James <kdedevel@etotheipiplusone.com> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #ifndef KATEVI_COMMAND_RANGE_EXPRESSION_PARSER 0011 #define KATEVI_COMMAND_RANGE_EXPRESSION_PARSER 0012 0013 #include <ktexteditor/range.h> 0014 0015 namespace KateVi 0016 { 0017 class InputModeManager; 0018 0019 class CommandRangeExpressionParser 0020 { 0021 public: 0022 explicit CommandRangeExpressionParser(InputModeManager *vimanager); 0023 0024 /** 0025 * Attempt to parse any leading range expression (e.g. "%", "'<,'>", ".,+6" etc) in @c command and 0026 * return it as a Range. If parsing was successful, the range will be valid and the command with 0027 * the range stripped will be placed in @c destTransformedCommand. In some special cases, 0028 * the @c destTransformedCommand will be further re-written e.g. a command in the form of just a number 0029 * will be rewritten as "goto <number>". 0030 * 0031 * An invalid Range is returned if no leading range expression could be found. 0032 */ 0033 KTextEditor::Range parseRange(const QString &command, QString &destTransformedCommand) const; 0034 0035 /** 0036 * Attempts to find range expression for vi command 0037 * @returns range sub string of passed command or empty if not found 0038 */ 0039 static QString parseRangeString(const QString &command); 0040 0041 private: 0042 int calculatePosition(const QString &string) const; 0043 0044 static bool matchLineNumber(const QString &line, QList<int> &values); 0045 bool matchLastLine(const QString &line, QList<int> &values) const; 0046 bool matchThisLine(const QString &line, QList<int> &values) const; 0047 bool matchMark(const QString &line, QList<int> &values) const; 0048 bool matchForwardSearch(const QString &line, QList<int> &values) const; 0049 bool matchBackwardSearch(const QString &line, QList<int> &values) const; 0050 0051 private: 0052 InputModeManager *m_viInputModeManager; 0053 }; 0054 0055 } 0056 0057 #endif