MCPcopy Create free account
hub / github.com/IJHack/QtPass / splitCommandCompat

Function splitCommandCompat

src/pass.cpp:309–349  ·  view source on GitHub ↗

* @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

Source from the content-addressed store, hash-verified

307 * @return QStringList - A list of parsed command arguments.
308 */
309QStringList 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

Callers 1

resolveGpgconfCommandMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected