2017-02-19 22:59:39 +00:00
|
|
|
#ifndef LAUNCHERARGUMENTTOKENIZER_HXX
|
|
|
|
#define LAUNCHERARGUMENTTOKENIZER_HXX
|
|
|
|
|
2018-06-25 22:06:20 +00:00
|
|
|
#include <set>
|
|
|
|
|
2017-02-19 22:59:39 +00:00
|
|
|
#include <QString>
|
|
|
|
#include <QList>
|
2017-12-15 15:42:36 +00:00
|
|
|
#include <QObject>
|
|
|
|
#include <QJSValue>
|
2017-02-19 22:59:39 +00:00
|
|
|
|
2017-12-15 15:42:36 +00:00
|
|
|
class ArgumentToken
|
2017-02-19 22:59:39 +00:00
|
|
|
{
|
2017-12-15 15:42:36 +00:00
|
|
|
public:
|
|
|
|
explicit ArgumentToken(QString k, QString v = QString()) : arg(k), value(v) {}
|
|
|
|
|
|
|
|
QString arg;
|
|
|
|
QString value;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LauncherArgumentTokenizer : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
Q_PROPERTY(QString argString READ argString WRITE setArgString NOTIFY argStringChanged)
|
|
|
|
Q_PROPERTY(QVariantList tokens READ tokens NOTIFY argStringChanged)
|
2018-06-03 08:07:21 +00:00
|
|
|
|
|
|
|
Q_PROPERTY(bool valid READ isValid NOTIFY argStringChanged)
|
2018-06-25 22:06:20 +00:00
|
|
|
Q_PROPERTY(bool havePositionalArgs READ havePositionalArgs NOTIFY argStringChanged)
|
|
|
|
Q_PROPERTY(bool haveUnsupportedArgs READ haveUnsupportedArgs NOTIFY argStringChanged)
|
2018-06-03 08:07:21 +00:00
|
|
|
|
2017-02-19 22:59:39 +00:00
|
|
|
public:
|
|
|
|
LauncherArgumentTokenizer();
|
|
|
|
|
2017-12-15 15:42:36 +00:00
|
|
|
|
|
|
|
QString argString() const
|
2017-02-19 22:59:39 +00:00
|
|
|
{
|
2017-12-15 15:42:36 +00:00
|
|
|
return m_argString;
|
|
|
|
}
|
2017-02-19 22:59:39 +00:00
|
|
|
|
2017-12-15 15:42:36 +00:00
|
|
|
QVariantList tokens() const;
|
2017-02-19 22:59:39 +00:00
|
|
|
|
2018-06-03 08:07:21 +00:00
|
|
|
bool isValid() const;
|
|
|
|
|
2018-06-25 22:06:20 +00:00
|
|
|
bool haveUnsupportedArgs() const;
|
|
|
|
bool havePositionalArgs() const;
|
2017-12-15 15:42:36 +00:00
|
|
|
public slots:
|
|
|
|
void setArgString(QString argString);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void argStringChanged(QString argString);
|
2017-02-19 22:59:39 +00:00
|
|
|
|
|
|
|
private:
|
2018-06-25 22:06:20 +00:00
|
|
|
bool haveArgsIn(const std::set<std::string> &args) const;
|
|
|
|
|
2018-06-03 08:07:21 +00:00
|
|
|
void tokenize(QString in);
|
|
|
|
|
2017-02-19 22:59:39 +00:00
|
|
|
enum State {
|
|
|
|
Start = 0,
|
|
|
|
Key,
|
|
|
|
Value,
|
|
|
|
Quoted,
|
|
|
|
Comment
|
|
|
|
};
|
|
|
|
|
2018-06-03 08:07:21 +00:00
|
|
|
std::vector<ArgumentToken> m_tokens;
|
2017-12-15 15:42:36 +00:00
|
|
|
QString m_argString;
|
2018-06-03 08:07:21 +00:00
|
|
|
bool m_valid = false;
|
2017-12-15 15:42:36 +00:00
|
|
|
};
|
2017-02-19 22:59:39 +00:00
|
|
|
|
|
|
|
#endif // LAUNCHERARGUMENTTOKENIZER_HXX
|