-
Notifications
You must be signed in to change notification settings - Fork 0
/
argumentlist.cpp
65 lines (57 loc) · 1.17 KB
/
argumentlist.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <QCoreApplication>
#include "argumentlist.h"
/**
@author S. Alan Ezust [email protected]
@since qt 3.2.1
Obtain the command line arguments from the currently
running QApplication
*/
ArgumentList::ArgumentList()
{
if (qApp != nullptr) /* a global pointer to the current qApplication */
*this = qApp->arguments();
}
void ArgumentList::argsToStringlist(int argc, char * argv [])
{
for (int i=0; i < argc; ++i)
{
*this += QString::fromLocal8Bit(argv[i]);
}
}
bool ArgumentList::getSwitch (const QString &option)
{
QMutableStringListIterator itr(*this);
while (itr.hasNext())
{
if (option == itr.next())
{
itr.remove();
return true;
}
}
return false;
}
QString ArgumentList::getSwitchArg(const QString &option, const QString &defaultValue)
{
if (isEmpty())
return defaultValue;
QMutableStringListIterator itr(*this);
while (itr.hasNext())
{
if (option == itr.next())
{
itr.remove();
if (itr.hasNext())
{
QString retval = itr.next();
itr.remove();
return retval;
}
else
{
return QString();
}
}
}
return defaultValue;
}