diff options
author | lado <herrlado@gmail.com> | 2011-11-06 15:07:08 +0100 |
---|---|---|
committer | lado <herrlado@gmail.com> | 2011-11-06 15:07:08 +0100 |
commit | 3248a802c6b4559416fbea3a1ef84145dc1e66f9 (patch) | |
tree | ea52812b7ea0fcc84f6be3756553e68686a11dce | |
parent | 086554987e0ab84c3ebfc54879a45a21c3a69837 (diff) | |
download | vdr-manager-3248a802c6b4559416fbea3a1ef84145dc1e66f9.tar.gz vdr-manager-3248a802c6b4559416fbea3a1ef84145dc1e66f9.tar.bz2 |
simplify Trim
-rw-r--r-- | vdr-vdrmanager/helpers.cpp | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/vdr-vdrmanager/helpers.cpp b/vdr-vdrmanager/helpers.cpp index 8eba3e7..182d2b4 100644 --- a/vdr-vdrmanager/helpers.cpp +++ b/vdr-vdrmanager/helpers.cpp @@ -582,24 +582,13 @@ string cHelpers::ToLower(string text) } -string cHelpers::Trim(string text) { - - const char * start = text.c_str(); - - // skip leading spaces - const char * first = start; - while (*first && isspace(*first)) - first++; - - // find trailing spaces - const char * last = first + strlen(first) - 1; - while (first < last && isspace(*last)) - last--; - - char * dst = (char *)malloc(last - first + 2); - sprintf(dst, "%*s", last - first + 1, first); - - return dst; +string cHelpers::Trim(string str) +{ + int a = str.find_first_not_of(" \t"); + int b = str.find_last_not_of(" \t"); + if ( a == -1 ) a = 0; + if ( b == -1 ) b = str.length() - 1; + return str.substr(a, (b-a)+1); } string cHelpers::SafeCall(string (*f)()) |