swift
Loading...
Searching...
No Matches
simplecommandparser.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_MISC_SIMPLECOMMANDPARSER_H
7#define SWIFT_MISC_SIMPLECOMMANDPARSER_H
8
9#include <QString>
10#include <QStringList>
11
13
14namespace swift::misc
15{
17
21 {
22 public:
24 CSimpleCommandParser(const QStringList &knownCommands);
25
27 bool isKnownCommand() const { return m_knownCommand; }
28
30 void parse(const QString &commandLine);
31
33 bool matchesCommand(const QString &checkCommand, const QString &alias1 = "", const QString &alias2 = "");
34
36 bool commandStartsWith(const QString &startPattern) const;
37
39 bool commandEndsWith(const QString &endPattern) const;
40
42 const QString &part(int index) const;
43
46 QString partAndRemainingStringAfter(int index) const;
47
49 int countParts() const;
50
52 bool hasPart(int index) const;
53
55 int countPartsWithoutCommand() const;
56
58 bool isInt(int index) const;
59
61 bool isDouble(int index) const;
62
64 int toInt(int index, int def = -1) const;
65
67 bool toBool(int index, bool def = false) const;
68
70 double toDouble(int index, double def = -1.0) const;
71
73 bool matchesPart(int index, const QString &toMatch, Qt::CaseSensitivity cs = Qt::CaseInsensitive) const;
74
77 {
80
83
85 static bool less(const CommandHtmlHelp &a, const CommandHtmlHelp &b) { return a.command < b.command; }
86 };
87
89 static void registerCommand(const CommandHtmlHelp &command);
90
92 static bool registered(const QString &helpContext);
93
95 static QString commandsHtmlHelp();
96
97 private:
98 QString m_originalLine;
99 QString m_cleanedLine;
100 QString m_commandPart;
101 QStringList m_splitParts;
102 QStringList m_knownCommands;
103 bool m_knownCommand = false;
104
105 static QList<CommandHtmlHelp> s_commands;
106 static QSet<QString> s_registered;
107
109 void setCheckedCommandList(const QStringList &commands);
110
112 static QString removeLeadingDot(const QString &candidate);
113
115 static QString formatCommand(const QString &command);
116
118 static bool isCommand(const QString &candidate);
119 };
120} // namespace swift::misc
121
122#endif // SWIFT_MISC_SIMPLECOMMANDPARSER_H
CSimpleCommandParser(const QStringList &knownCommands)
Constructor.
bool isKnownCommand() const
Known command?
Free functions in swift::misc.
CaseSensitivity
CommandHtmlHelp(const QString &command, const QString &help)
Constructor.
static bool less(const CommandHtmlHelp &a, const CommandHtmlHelp &b)
Compare by command.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.