1 | /* |
---|---|
2 | SPDX-FileCopyrightText: 2019 Dominik Haumann <dhaumann@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #include "variable.h" |
8 | |
9 | namespace KTextEditor |
10 | { |
11 | Variable::Variable(const QString &name, const QString &description, Variable::ExpandFunction func, bool isPrefixMatch) |
12 | : m_name(name) |
13 | , m_description(description) |
14 | , m_function(std::move(func)) |
15 | , m_isPrefixMatch(isPrefixMatch) |
16 | { |
17 | } |
18 | |
19 | bool Variable::isValid() const |
20 | { |
21 | return (!m_name.isEmpty()) && (m_function != nullptr); |
22 | } |
23 | |
24 | bool Variable::isPrefixMatch() const |
25 | { |
26 | return m_isPrefixMatch; |
27 | } |
28 | |
29 | QString Variable::name() const |
30 | { |
31 | return m_name; |
32 | } |
33 | |
34 | QString Variable::description() const |
35 | { |
36 | return m_description; |
37 | } |
38 | |
39 | QString Variable::evaluate(const QStringView &prefix, KTextEditor::View *view) const |
40 | { |
41 | return isValid() ? m_function(prefix, view) : QString(); |
42 | } |
43 | |
44 | } |
45 |