diff options
Diffstat (limited to 'vdr-vdrmanager/helpers.cpp')
-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)()) |