summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormarkt <markt>2007-12-14 20:05:14 (GMT)
committermarkt <markt>2007-12-14 20:05:14 (GMT)
commitd90befb43007274c03fb1783b3236072120e78e1 (patch)
treeab8adc830da61a6dc0ea56fee0e463634427650d /src
parent254fb289f318eaedbfe8e3dff4454afd0f66e868 (diff)
downloadfluxbox_lack-d90befb43007274c03fb1783b3236072120e78e1.zip
fluxbox_lack-d90befb43007274c03fb1783b3236072120e78e1.tar.bz2
StringUtil::removeFirst/TrailingWhitespace didn't truncate a string that was only whitespace
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/CommandRegistry.cc4
-rw-r--r--src/FbTk/StringUtil.cc15
-rw-r--r--src/FbTk/StringUtil.hh2
3 files changed, 9 insertions, 12 deletions
diff --git a/src/FbTk/CommandRegistry.cc b/src/FbTk/CommandRegistry.cc
index 1d16c75..fc40920 100644
--- a/src/FbTk/CommandRegistry.cc
+++ b/src/FbTk/CommandRegistry.cc
@@ -53,6 +53,8 @@ Command *CommandRegistry::parseLine(const string &line, bool trusted) const {
53 // parse args and command 53 // parse args and command
54 string command, args; 54 string command, args;
55 StringUtil::getFirstWord(line, command, args); 55 StringUtil::getFirstWord(line, command, args);
56 StringUtil::removeFirstWhitespace(args);
57 StringUtil::removeTrailingWhitespace(args);
56 58
57 // now we have parsed command and args 59 // now we have parsed command and args
58 command = StringUtil::toLower(command); 60 command = StringUtil::toLower(command);
@@ -63,6 +65,8 @@ BoolCommand *CommandRegistry::parseBoolLine(const string &line, bool trusted) co
63 // parse args and command 65 // parse args and command
64 string command, args; 66 string command, args;
65 StringUtil::getFirstWord(line, command, args); 67 StringUtil::getFirstWord(line, command, args);
68 StringUtil::removeFirstWhitespace(args);
69 StringUtil::removeTrailingWhitespace(args);
66 70
67 // now we have parsed command and args 71 // now we have parsed command and args
68 command = StringUtil::toLower(command); 72 command = StringUtil::toLower(command);
diff --git a/src/FbTk/StringUtil.cc b/src/FbTk/StringUtil.cc
index 9b4928b..1bd9b8d 100644
--- a/src/FbTk/StringUtil.cc
+++ b/src/FbTk/StringUtil.cc
@@ -214,8 +214,7 @@ string basename(const string &filename) {
214 214
215string::size_type removeFirstWhitespace(string &str) { 215string::size_type removeFirstWhitespace(string &str) {
216 string::size_type first_pos = str.find_first_not_of(" \t"); 216 string::size_type first_pos = str.find_first_not_of(" \t");
217 if (first_pos != string::npos) 217 str.erase(0, first_pos);
218 str.erase(0, first_pos);
219 return first_pos; 218 return first_pos;
220} 219}
221 220
@@ -223,13 +222,9 @@ string::size_type removeFirstWhitespace(string &str) {
223string::size_type removeTrailingWhitespace(string &str) { 222string::size_type removeTrailingWhitespace(string &str) {
224 // strip trailing whitespace 223 // strip trailing whitespace
225 string::size_type first_pos = str.find_last_not_of(" \t"); 224 string::size_type first_pos = str.find_last_not_of(" \t");
226 if (first_pos != string::npos) { 225 string::size_type last_pos = str.find_first_of(" \t", first_pos);
227 string::size_type last_pos = str.find_first_of(" \t", first_pos); 226 if (last_pos != string::npos)
228 while (last_pos != string::npos) { 227 str.erase(last_pos);
229 str.erase(last_pos);
230 last_pos = str.find_first_of(" \t", last_pos);
231 }
232 }
233 return first_pos; 228 return first_pos;
234} 229}
235 230
@@ -240,8 +235,6 @@ void getFirstWord(const std::string &in, std::string &word, std::string &rest) {
240 if (second_pos != string::npos) { 235 if (second_pos != string::npos) {
241 rest = word.substr(second_pos); 236 rest = word.substr(second_pos);
242 word.erase(second_pos); 237 word.erase(second_pos);
243 removeFirstWhitespace(rest);
244 removeTrailingWhitespace(rest);
245 } 238 }
246} 239}
247 240
diff --git a/src/FbTk/StringUtil.hh b/src/FbTk/StringUtil.hh
index 7f0cf54..d3c131e 100644
--- a/src/FbTk/StringUtil.hh
+++ b/src/FbTk/StringUtil.hh
@@ -64,7 +64,7 @@ std::string basename(const std::string &basename);
64std::string::size_type removeFirstWhitespace(std::string &str); 64std::string::size_type removeFirstWhitespace(std::string &str);
65std::string::size_type removeTrailingWhitespace(std::string &str); 65std::string::size_type removeTrailingWhitespace(std::string &str);
66 66
67/// removes the first part of a string and returns the two pieces 67/// splits input at first non-leading whitespace and returns both parts
68void getFirstWord(const std::string &in, std::string &first, std::string &rest); 68void getFirstWord(const std::string &in, std::string &first, std::string &rest);
69 69
70/// Breaks a string into tokens 70/// Breaks a string into tokens