diff --git a/src/FbTk/CommandRegistry.cc b/src/FbTk/CommandRegistry.cc index 1d16c754..fc40920b 100644 --- a/src/FbTk/CommandRegistry.cc +++ b/src/FbTk/CommandRegistry.cc @@ -53,6 +53,8 @@ Command *CommandRegistry::parseLine(const string &line, bool trusted) const { // parse args and command string command, args; StringUtil::getFirstWord(line, command, args); + StringUtil::removeFirstWhitespace(args); + StringUtil::removeTrailingWhitespace(args); // now we have parsed command and args command = StringUtil::toLower(command); @@ -63,6 +65,8 @@ BoolCommand *CommandRegistry::parseBoolLine(const string &line, bool trusted) co // parse args and command string command, args; StringUtil::getFirstWord(line, command, args); + StringUtil::removeFirstWhitespace(args); + StringUtil::removeTrailingWhitespace(args); // now we have parsed command and args command = StringUtil::toLower(command); diff --git a/src/FbTk/StringUtil.cc b/src/FbTk/StringUtil.cc index 9b4928bb..1bd9b8da 100644 --- a/src/FbTk/StringUtil.cc +++ b/src/FbTk/StringUtil.cc @@ -214,8 +214,7 @@ string basename(const string &filename) { string::size_type removeFirstWhitespace(string &str) { string::size_type first_pos = str.find_first_not_of(" \t"); - if (first_pos != string::npos) - str.erase(0, first_pos); + str.erase(0, first_pos); return first_pos; } @@ -223,13 +222,9 @@ string::size_type removeFirstWhitespace(string &str) { string::size_type removeTrailingWhitespace(string &str) { // strip trailing whitespace string::size_type first_pos = str.find_last_not_of(" \t"); - if (first_pos != string::npos) { - string::size_type last_pos = str.find_first_of(" \t", first_pos); - while (last_pos != string::npos) { - str.erase(last_pos); - last_pos = str.find_first_of(" \t", last_pos); - } - } + string::size_type last_pos = str.find_first_of(" \t", first_pos); + if (last_pos != string::npos) + str.erase(last_pos); return first_pos; } @@ -240,8 +235,6 @@ void getFirstWord(const std::string &in, std::string &word, std::string &rest) { if (second_pos != string::npos) { rest = word.substr(second_pos); word.erase(second_pos); - removeFirstWhitespace(rest); - removeTrailingWhitespace(rest); } } diff --git a/src/FbTk/StringUtil.hh b/src/FbTk/StringUtil.hh index 7f0cf54d..d3c131e2 100644 --- a/src/FbTk/StringUtil.hh +++ b/src/FbTk/StringUtil.hh @@ -64,7 +64,7 @@ std::string basename(const std::string &basename); std::string::size_type removeFirstWhitespace(std::string &str); std::string::size_type removeTrailingWhitespace(std::string &str); -/// removes the first part of a string and returns the two pieces +/// splits input at first non-leading whitespace and returns both parts void getFirstWord(const std::string &in, std::string &first, std::string &rest); /// Breaks a string into tokens