-
Notifications
You must be signed in to change notification settings - Fork 9
/
utils.cpp
40 lines (31 loc) · 949 Bytes
/
utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "utils.h"
#include <QDebug>
Utils::Utils() {
}
QStringList Utils::getArgumentList(const QString& args) {
bool str = false;
QStringList argumentList;
QString currentArg;
for (int i = 0; i < args.length(); ++i) {
currentArg.append(args.at(i));
if (args.at(i) == '"' || args.at(i) == '\'') {
if (str) {
argumentList.append(currentArg);
currentArg = "";
}
str = !str;
} else if (args.at(i) == ' ') {
if (str)
continue;
else {
currentArg.remove(currentArg.length() - 1, 1);
if (!currentArg.isEmpty())
argumentList.append(currentArg);
currentArg = "";
}
}
}
if (!currentArg.isEmpty())
argumentList.append(currentArg);
return argumentList;
}