MCPcopy Create free account
hub / github.com/RetroShare/RetroShare / string_parse_arguments

Function string_parse_arguments

retroshare-gui/src/util/stringutil.cpp:256–306  ·  view source on GitHub ↗

Parses a series of command line arguments from str . If str * was unable to be parsed, ok is set to false. */

Source from the content-addressed store, hash-verified

254/** Parses a series of command line arguments from <b>str</b>. If <b>str</b>
255 * was unable to be parsed, <b>ok</b> is set to false. */
256QStringList
257string_parse_arguments(const QString &str, bool *ok)
258{
259 QStringList args;
260 int i, len;
261 bool tmp_ok;
262
263 i = 0;
264 len = str.length();
265 while (i < len && str[i].isSpace())
266 i++; /* Skip initial whitespace */
267 while (i < len) {
268 QString arg;
269
270 if (str[i] == '\"') {
271 /* The value is wrapped in quotes */
272 arg.append(str[i]);
273 while (++i < len) {
274 arg.append(str[i]);
275 if (str[i] == '\\') {
276 if (++i == len)
277 goto error;
278 arg.append(str[i]);
279 } else if (str[i] == '\"') {
280 i++;
281 break;
282 }
283 }
284 arg = string_unescape(arg, &tmp_ok);
285 if (!tmp_ok)
286 goto error;
287 args << arg;
288 } else {
289 /* The value was not wrapped in quotes */
290 while (i < len && !str[i].isSpace())
291 arg.append(str[i++]);
292 args << arg;
293 }
294 while (i < len && str[i].isSpace())
295 i++;
296 }
297
298 if (ok)
299 *ok = true;
300 return args;
301
302error:
303 if (ok)
304 *ok = false;
305 return QStringList();
306}
307
308/** Formats the list of command line arguments in <b>args</b> as a string.
309 * Arguments that contain ' ', '\', or '"' tokens will be escaped and

Callers

nothing calls this directly

Calls 2

string_unescapeFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected