KTextEditor

command.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Erlend Hamberg <ehamberg@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include <vimode/command.h>
8#include <vimode/keyparser.h>
9
10using namespace KateVi;
11
12Command::Command(const QString &pattern, bool (NormalViMode::*commandMethod)(), unsigned int flags)
13 : m_pattern(KeyParser::self()->encodeKeySequence(pattern))
14 , m_flags(flags)
15 , m_ptr2commandMethod(commandMethod)
16{
17}
18
19Command::~Command() = default;
20
21bool Command::execute(NormalViMode *mode) const
22{
23 return (mode->*m_ptr2commandMethod)();
24}
25
26bool Command::matches(const QString &pattern) const
27{
28 if (!(m_flags & REGEX_PATTERN)) {
29 return m_pattern.startsWith(pattern);
30 } else {
31 // compile once, void costly isValid check, good enough to have set the pattern.
32 if (m_patternRegex.pattern().isEmpty()) {
34 }
35 const auto match = m_patternRegex.match(pattern, 0, QRegularExpression::PartialPreferFirstMatch);
36 // Partial matching could lead to a complete match, in that case hasPartialMatch() will return false, and hasMatch() will return true
37 return match.hasPartialMatch() || match.hasMatch();
38 }
39}
40
41bool Command::matchesExact(const QString &pattern) const
42{
43 if (!(m_flags & REGEX_PATTERN)) {
44 return (m_pattern == pattern);
45 } else {
46 // compile once, void costly isValid check, good enough to have set the pattern.
47 if (m_patternAnchoredRegex.pattern().isEmpty()) {
49 }
50 return m_patternAnchoredRegex.match(pattern).hasMatch();
51 }
52}
for encoding keypresses w/ modifiers into an internal QChar representation and back again to a descri...
Definition keyparser.h:28
Commands for the vi normal mode.
KCOREADDONS_EXPORT Result match(QStringView pattern, QStringView str)
QRegularExpressionMatch match(QStringView subjectView, qsizetype offset, MatchType matchType, MatchOptions matchOptions) const const
QString anchoredPattern(QStringView expression)
QString pattern() const const
bool hasMatch() const const
bool isEmpty() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:17:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.