29 #include <QStringList> 30 #include <QtCore/QDir> 60 static const uchar iqm[] = {
61 0x00, 0x00, 0x00, 0x00, 0x40, 0x03, 0x00, 0x50,
62 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
65 return (c <
sizeof(iqm) * 8) && (iqm[c / 8] & (1 << (c & 7)));
74 static const uchar iqm[] = {
75 0xff, 0xff, 0xff, 0xff, 0x41, 0x13, 0x00, 0x78,
76 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x10
79 return (c <
sizeof(iqm) * 8) && (iqm[c / 8] & (1 << (c & 7)));
84 return c ==
' ' || c ==
'\t';
92 const QLatin1Char bs(
'\\'), dq(
'\"');
96 if (args.indexOf(QLatin1Char(
'%')) >= 0) {
105 if (!args.isEmpty() && args[0].unicode() ==
'@')
108 for (
int p = 0; p < args.length(); p++) {
109 ushort c = args[p].unicode();
112 }
else if (c ==
'"') {
113 while (++p < args.length() && args[p].unicode() !=
'"')
127 const int length = args.length();
135 bool inquote =
false;
139 while (p < length && args[p] == bs) {
143 if (p < length && args[p] == dq) {
144 if (bslashes % 2 == 0) {
147 if (p + 1 < length && args[p + 1] == dq) {
165 while (--bslashes >= 0)
168 if (p == length || (!inquote &&
isWhiteSpace(args[p].unicode()))) {
191 const QLatin1Char bs(
'\\'), dq(
'\"');
193 bool inquote = _inquote;
195 for (
int p = 0; p < arg.length(); p++) {
198 }
else if (arg[p] == dq) {
203 for (; bslashes; bslashes--)
204 ret.append(QLatin1String(
"\\\\"));
205 ret.append(QLatin1String(
"\\^\""));
211 for (; bslashes; bslashes--)
220 if (!inquote && !_inquote)
222 for (; bslashes; bslashes--)
223 ret.append(QLatin1String(
"\\\\"));
225 if (inquote && _inquote)
227 }
else if (inquote != _inquote) {
236 return QString::fromLatin1(
"\"\"");
240 if (arg.endsWith(QLatin1Char(
'\\')))
243 for (
int x = arg.length() - 1; x >= 0; --x)
250 ret.replace(QRegExp(QLatin1String(
"(\\\\*)\"")), QLatin1String(
"\\1\\1\\^\""));
static bool isSpecialChar(ushort c)
QStringList splitArgs(const QString &cmd, Options flags=NoOptions, Errors *err=0)
Splits cmd according to system shell word splitting and quoting rules.
The AbortOnMeta flag was set and an unhandled shell meta character was encoutered.
static bool isWhiteSpace(ushort c)
Errors
Status codes from splitArgs()
QString quoteArg(const QString &arg)
Quotes arg according to system shell rules.
Indicates a parsing error, like an unterminated quoted string.
QString quoteArgInternal(const QString &arg, bool _inquote)
static bool isMetaChar(ushort c)
Put the parser into full shell mode and bail out if a too complex construct is encoutered.