StringUtil::removeFirst/TrailingWhitespace didn't truncate a string that was only whitespace
This commit is contained in:
parent
254fb289f3
commit
d90befb430
3 changed files with 9 additions and 12 deletions
|
@ -53,6 +53,8 @@ Command *CommandRegistry::parseLine(const string &line, bool trusted) const {
|
||||||
// parse args and command
|
// parse args and command
|
||||||
string command, args;
|
string command, args;
|
||||||
StringUtil::getFirstWord(line, command, args);
|
StringUtil::getFirstWord(line, command, args);
|
||||||
|
StringUtil::removeFirstWhitespace(args);
|
||||||
|
StringUtil::removeTrailingWhitespace(args);
|
||||||
|
|
||||||
// now we have parsed command and args
|
// now we have parsed command and args
|
||||||
command = StringUtil::toLower(command);
|
command = StringUtil::toLower(command);
|
||||||
|
@ -63,6 +65,8 @@ BoolCommand *CommandRegistry::parseBoolLine(const string &line, bool trusted) co
|
||||||
// parse args and command
|
// parse args and command
|
||||||
string command, args;
|
string command, args;
|
||||||
StringUtil::getFirstWord(line, command, args);
|
StringUtil::getFirstWord(line, command, args);
|
||||||
|
StringUtil::removeFirstWhitespace(args);
|
||||||
|
StringUtil::removeTrailingWhitespace(args);
|
||||||
|
|
||||||
// now we have parsed command and args
|
// now we have parsed command and args
|
||||||
command = StringUtil::toLower(command);
|
command = StringUtil::toLower(command);
|
||||||
|
|
|
@ -214,8 +214,7 @@ string basename(const string &filename) {
|
||||||
|
|
||||||
string::size_type removeFirstWhitespace(string &str) {
|
string::size_type removeFirstWhitespace(string &str) {
|
||||||
string::size_type first_pos = str.find_first_not_of(" \t");
|
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;
|
return first_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,13 +222,9 @@ string::size_type removeFirstWhitespace(string &str) {
|
||||||
string::size_type removeTrailingWhitespace(string &str) {
|
string::size_type removeTrailingWhitespace(string &str) {
|
||||||
// strip trailing whitespace
|
// strip trailing whitespace
|
||||||
string::size_type first_pos = str.find_last_not_of(" \t");
|
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);
|
||||||
string::size_type last_pos = str.find_first_of(" \t", first_pos);
|
if (last_pos != string::npos)
|
||||||
while (last_pos != string::npos) {
|
str.erase(last_pos);
|
||||||
str.erase(last_pos);
|
|
||||||
last_pos = str.find_first_of(" \t", last_pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return first_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) {
|
if (second_pos != string::npos) {
|
||||||
rest = word.substr(second_pos);
|
rest = word.substr(second_pos);
|
||||||
word.erase(second_pos);
|
word.erase(second_pos);
|
||||||
removeFirstWhitespace(rest);
|
|
||||||
removeTrailingWhitespace(rest);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ std::string basename(const std::string &basename);
|
||||||
std::string::size_type removeFirstWhitespace(std::string &str);
|
std::string::size_type removeFirstWhitespace(std::string &str);
|
||||||
std::string::size_type removeTrailingWhitespace(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);
|
void getFirstWord(const std::string &in, std::string &first, std::string &rest);
|
||||||
|
|
||||||
/// Breaks a string into tokens
|
/// Breaks a string into tokens
|
||||||
|
|
Loading…
Reference in a new issue