From aa8db3531b1f38fa00a5e254579e5a9b47b38217 Mon Sep 17 00:00:00 2001 From: Christian Wieninger Date: Sun, 15 Apr 2007 11:31:21 +0000 Subject: added StringTrim --- tools.cpp | 13 +++++++++++++ tools.h | 1 + 2 files changed, 14 insertions(+) diff --git a/tools.cpp b/tools.cpp index 677ce02..fff3483 100644 --- a/tools.cpp +++ b/tools.cpp @@ -108,4 +108,17 @@ string StringEscapeAndBreak( string const& input ) return StringReplace( plainBuilder.str(), "\n", "
" ); } +string StringTrim(string const& str) +{ + string res = str; + string::size_type pos = res.find_last_not_of(' '); + if(pos != string::npos) { + res.erase(pos + 1); + pos = res.find_first_not_of(' '); + if(pos != string::npos) res.erase(0, pos); + } + else res.erase(res.begin(), res.end()); + return res; +} + } // namespace vdrlive diff --git a/tools.h b/tools.h index fdba13d..0779e8f 100644 --- a/tools.h +++ b/tools.h @@ -29,6 +29,7 @@ std::string StringRepeat(int times, const std::string& input); std::string StringWordTruncate(const std::string& input, size_t maxLen, bool& truncated); std::string StringEscapeAndBreak( std::string const& input ); std::string StringFormatBreak(std::string const& input); +std::string StringTrim(const std::string& str); struct bad_lexical_cast: std::runtime_error { -- cgit v1.2.3