aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/StringUtil.cc
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/FbTk/StringUtil.cc
parent254fb289f318eaedbfe8e3dff4454afd0f66e868 (diff)
downloadfluxbox-d90befb43007274c03fb1783b3236072120e78e1.zip
fluxbox-d90befb43007274c03fb1783b3236072120e78e1.tar.bz2
StringUtil::removeFirst/TrailingWhitespace didn't truncate a string that was only whitespace
Diffstat (limited to 'src/FbTk/StringUtil.cc')
-rw-r--r--src/FbTk/StringUtil.cc15
1 files changed, 4 insertions, 11 deletions
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