all repos — fluxbox @ 233a4d85f41e4c76c2e45b0e18ffc84a64251e4e

custom fork of the fluxbox windowmanager

added removeTrailingWhitespace
fluxgen fluxgen
commit

233a4d85f41e4c76c2e45b0e18ffc84a64251e4e

parent

ab2d5ca0c79ada652513e25d14430ffb439bd38b

2 files changed, 33 insertions(+), 19 deletions(-)

jump to
M src/FbTk/StringUtil.ccsrc/FbTk/StringUtil.cc

@@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: StringUtil.cc,v 1.7 2003/09/29 14:01:48 fluxgen Exp $ +// $Id: StringUtil.cc,v 1.8 2003/10/25 22:06:53 fluxgen Exp $ #include "StringUtil.hh"

@@ -38,9 +38,9 @@

namespace StringUtil { /** - Takes a pointer to string *s as an argument, - creates a new string n, copies s to n and - returns a pointer to n. + Takes a pointer to string *s as an argument, + creates a new string n, copies s to n and + returns a pointer to n. */ char *strdup(const char *s) { int l = strlen(s) + 1;

@@ -50,9 +50,9 @@ return n;

} /** - Tries to find a string in another and - ignoring the case of the characters - Returns 0 on success else pointer to str. + Tries to find a string in another and + ignoring the case of the characters + Returns 0 on success else pointer to str. */ const char *strcasestr(const char *str, const char *ptn) { const char *s2, *p2;

@@ -70,8 +70,8 @@ return 0;

} /** - if ~ then expand it to home of user - returns expanded filename + if ~ then expand it to home of user + returns expanded filename */ string expandFilename(const std::string &filename) { string retval;

@@ -89,7 +89,7 @@ return retval;

} /** -@return string from last "." to end of string + @return string from last "." to end of string */ string findExtension(const std::string &filename) { //get start of extension

@@ -101,14 +101,14 @@ return filename.substr(start_pos + 1);

} /** - Parses a string between "first" and "last" characters - and ignoring ok_chars as whitespaces. The value is - returned in "out". - Returns negative value on error and this value is the position - in the in-string where the error occured. - Returns positive value on success and this value is - for the position + 1 in the in-string where the "last"-char value - was found. + Parses a string between "first" and "last" characters + and ignoring ok_chars as whitespaces. The value is + returned in "out". + Returns negative value on error and this value is the position + in the in-string where the error occured. + Returns positive value on success and this value is + for the position + 1 in the in-string where the "last"-char value + was found. */ int getStringBetween(std::string& out, const char *instr, const char first, const char last, const char *ok_chars, bool allow_nesting) {

@@ -183,6 +183,19 @@ string::size_type first_pos = str.find_first_not_of(" \t");

if (first_pos != string::npos) str.erase(0, first_pos); return first_pos; +} + + +string::size_type removeTrailingWhitespace(std::string &str) { + // strip trailing whitespace + string::size_type first_pos = str.find_first_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); + } + } } }; // end namespace StringUtil
M src/FbTk/StringUtil.hhsrc/FbTk/StringUtil.hh

@@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -//$Id: StringUtil.hh,v 1.6 2003/09/29 14:01:48 fluxgen Exp $ +//$Id: StringUtil.hh,v 1.7 2003/10/25 22:06:53 fluxgen Exp $ #ifndef FBTK_STRINGUTIL_HH #define FBTK_STRINGUTIL_HH

@@ -57,6 +57,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); /// Breaks a string into tokens template <typename Container>