KTextEditor

variable.cpp
1 /* SPDX-License-Identifier: LGPL-2.0-or-later
2 
3  Copyright (C) 2019 Dominik Haumann <[email protected]>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "variable.h"
22 
23 namespace KTextEditor
24 {
25 Variable::Variable(const QString &name, const QString &description, Variable::ExpandFunction func, bool isPrefixMatch)
26  : m_name(name)
27  , m_description(description)
28  , m_function(std::move(func))
29  , m_isPrefixMatch(isPrefixMatch)
30 {
31 }
32 
33 bool Variable::isValid() const
34 {
35  return (!m_name.isEmpty()) && (m_function != nullptr);
36 }
37 
39 {
40  return m_isPrefixMatch;
41 }
42 
44 {
45  return m_name;
46 }
47 
49 {
50  return m_description;
51 }
52 
54 {
55  return isValid() ? m_function(prefix, view) : QString();
56 }
57 
58 }
bool isValid() const
Returns true, if the name is non-empty and the function provided in the constructor is not a nullptr...
Definition: variable.cpp:33
bool isPrefixMatch() const
Returns whether this Variable represents an exact match (false) or a prefix match (true)...
Definition: variable.cpp:38
QString description() const
Returns the description that was provided in the constructor.
Definition: variable.cpp:48
bool isEmpty() const const
QString evaluate(const QStringView &prefix, KTextEditor::View *view) const
Expands the Variable to its value.
Definition: variable.cpp:53
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
QString name() const
Returns the name that was provided in the constructor.
Definition: variable.cpp:43
std::function< QString(const QStringView &text, KTextEditor::View *view)> ExpandFunction
Function that is called to expand a variable in text.
Definition: variable.h:56
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:155
Variable()=default
Constructs an invalid Variable, see isValid().
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 7 2020 22:55:47 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.