| 11 | namespace { |
| 12 | |
| 13 | void parseArgList(const QString& s, QVariantMap& map) { |
| 14 | QStringList ret; |
| 15 | bool hadEscape = false; |
| 16 | bool inSingleQuote = false; |
| 17 | bool inDoubleQuote = false; |
| 18 | QString currentArg; |
| 19 | foreach (const QChar c, s) { |
| 20 | if (hadEscape) { |
| 21 | currentArg += c; |
| 22 | hadEscape = false; |
| 23 | } else { |
| 24 | if (c=='\\') { |
| 25 | hadEscape = true; |
| 26 | } else if (c=='"') { |
| 27 | if (inDoubleQuote) { |
| 28 | inDoubleQuote=false; |
| 29 | ret.push_back(currentArg); |
| 30 | currentArg = ""; |
| 31 | } else if (inSingleQuote) { |
| 32 | currentArg += c; |
| 33 | } else { |
| 34 | inDoubleQuote = true; |
| 35 | } |
| 36 | } else if (c=='\'') { |
| 37 | if (inSingleQuote) { |
| 38 | inSingleQuote=false; |
| 39 | ret.push_back(currentArg); |
| 40 | currentArg = ""; |
| 41 | } else if (inDoubleQuote) { |
| 42 | currentArg += c; |
| 43 | } else { |
| 44 | inSingleQuote = true; |
| 45 | } |
| 46 | } else if (!inSingleQuote && !inDoubleQuote && c==' ') { |
| 47 | if (currentArg.size() > 0) { |
| 48 | ret.push_back(currentArg); |
| 49 | currentArg = ""; |
| 50 | } |
| 51 | } else { |
| 52 | currentArg += c; |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | if (currentArg.size() > 0) { |
| 57 | ret.push_back(currentArg); |
| 58 | } |
| 59 | |
| 60 | QString flag; |
| 61 | for (auto& arg : ret) { |
| 62 | if (arg.startsWith("-")) { |
| 63 | if (!flag.isEmpty()) { |
| 64 | // Must be a boolean switch |
| 65 | map[flag] = true; |
| 66 | } |
| 67 | flag = arg; |
| 68 | } else if (!flag.isEmpty()) { |
| 69 | // Flag with arg |
| 70 | map[flag] = arg; |
no test coverage detected