command args: trim leading/trailing whitespace

When certain commands in tasksh (such as 'review N') contain whitespace,
such as:

    review '1     '

The whitespace would tokenise into the command arg vector, effectively
treating the whitespace as a literal component.

In the case of the 'review' command, this is undesirable.  Therefore,
strip out all leading/trailing whitespace from the command args vector.

Fixes GH issue #43
This commit is contained in:
Thomas Adam 2018-06-17 23:01:21 +01:00
parent 68d8a9acac
commit d70e1894a4

View file

@ -113,7 +113,13 @@ static int commandLoop (bool autoClear)
}
else if (command != "")
{
auto args = split (command, ' ');
std::vector<std::string> args;
std::string n;
for (const auto& s : split (command, ' '))
{
if ((n = trim(s)) != "")
args.push_back(n);
}
// Dispatch command.
if (args[0] == "<EOF>") status = -1;