#include "support/lstrings.h"
+#include <climits>
#include <iostream>
#include <sstream>
#include <vector>
namespace {
-void splitArg(vector<string> & args, string const & str, unsigned int max)
+// Extracts arguments from str into args. Arguments are delimted by
+// whitespace or by double quotes.
+// We extract at most max + 1 arguments, treating args[max] as
+// continuing to eol.
+void splitArg(vector<string> & args, string const & str,
+ unsigned int max = UINT_MAX)
{
istringstream is(str);
while (is) {
is >> c;
if (is) {
if (c == '"')
+ // get quote delimited argument
getline(is, s, '"');
else {
+ // get whitespace delimited argument
is.putback(c);
is >> s;
}
string FuncRequest::getArg(unsigned int i) const
{
vector<string> args;
- splitArg(args, to_utf8(argument_), string::npos);
+ splitArg(args, to_utf8(argument_));
return i < args.size() ? args[i] : string();
}