all repos — fluxbox @ d90befb43007274c03fb1783b3236072120e78e1

custom fork of the fluxbox windowmanager

StringUtil::removeFirst/TrailingWhitespace didn't truncate a string that was only whitespace
markt markt
commit

d90befb43007274c03fb1783b3236072120e78e1

parent

254fb289f318eaedbfe8e3dff4454afd0f66e868

3 files changed, 9 insertions(+), 12 deletions(-)

jump to
M src/FbTk/CommandRegistry.ccsrc/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) 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);
M src/FbTk/StringUtil.ccsrc/FbTk/StringUtil.cc

@@ -214,8 +214,7 @@ }

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 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 @@ string::size_type second_pos = word.find_first_of(" \t", first_pos);

if (second_pos != string::npos) { rest = word.substr(second_pos); word.erase(second_pos); - removeFirstWhitespace(rest); - removeTrailingWhitespace(rest); } }
M src/FbTk/StringUtil.hhsrc/FbTk/StringUtil.hh

@@ -64,7 +64,7 @@ /// removes the first whitespace characters of the string

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