forked from goldendict/goldendict
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsecmdline.cc
53 lines (51 loc) · 1.04 KB
/
parsecmdline.cc
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
#include "parsecmdline.hh"
QStringList parseCommandLine( QString const & commandLine )
{
// Parse arguments. Handle quotes correctly.
QStringList args;
bool openQuote = false;
bool possibleDoubleQuote = false;
bool startNew = true;
for( QString::const_iterator c = commandLine.begin(),
e = commandLine.end(); c != e; )
{
if ( *c == '"' && !possibleDoubleQuote )
{
++c;
if ( !openQuote )
{
openQuote = true;
if ( startNew )
{
args.push_back( QString() );
startNew = false;
}
}
else
possibleDoubleQuote = true;
}
else
if ( possibleDoubleQuote && *c != '"' )
{
openQuote = false;
possibleDoubleQuote = false;
}
else
if ( *c == ' ' && !openQuote )
{
++c;
startNew = true;
}
else
{
if ( startNew )
{
args.push_back( QString() );
startNew = false;
}
args.last().push_back( *c++ );
possibleDoubleQuote = false;
}
}
return args;
}