* @brief Splits a command string into arguments while respecting quotes and * escape characters. * @example * QStringList result = splitCommandCompat("cmd \"arg one\" 'arg two' * escaped\\ space"); * // Expected output: ["cmd", "arg one", "arg two", "escaped space"] * * @param command - The input command string to split into individual arguments. * @return QStringList - A list of parsed co
| 307 | * @return QStringList - A list of parsed command arguments. |
| 308 | */ |
| 309 | QStringList splitCommandCompat(const QString &command) { |
| 310 | QStringList result; |
| 311 | QString current; |
| 312 | bool inSingleQuote = false; |
| 313 | bool inDoubleQuote = false; |
| 314 | bool escaping = false; |
| 315 | for (QChar ch : command) { |
| 316 | if (escaping) { |
| 317 | current.append(ch); |
| 318 | escaping = false; |
| 319 | continue; |
| 320 | } |
| 321 | if (ch == '\\') { |
| 322 | escaping = true; |
| 323 | continue; |
| 324 | } |
| 325 | if (ch == '\'' && !inDoubleQuote) { |
| 326 | inSingleQuote = !inSingleQuote; |
| 327 | continue; |
| 328 | } |
| 329 | if (ch == '"' && !inSingleQuote) { |
| 330 | inDoubleQuote = !inDoubleQuote; |
| 331 | continue; |
| 332 | } |
| 333 | if (ch.isSpace() && !inSingleQuote && !inDoubleQuote) { |
| 334 | if (!current.isEmpty()) { |
| 335 | result.append(current); |
| 336 | current.clear(); |
| 337 | } |
| 338 | continue; |
| 339 | } |
| 340 | current.append(ch); |
| 341 | } |
| 342 | if (escaping) { |
| 343 | current.append('\\'); |
| 344 | } |
| 345 | if (!current.isEmpty()) { |
| 346 | result.append(current); |
| 347 | } |
| 348 | return result; |
| 349 | } |
| 350 | #endif |
| 351 | |
| 352 | } // namespace |
no outgoing calls
no test coverage detected