diff options
author | Max Kellermann <max@duempel.org> | 2014-12-04 23:05:44 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-12-04 23:05:44 +0100 |
commit | 4b70f9d213e8cb71bc225a73494625e31dfaa721 (patch) | |
tree | 3f81136416b0b88e917a08e26d32326a839e0efd /src/util/DivideString.cxx | |
parent | 79d2d1c201babcbbfa1337295d42feebaebb6021 (diff) | |
download | mpd-4b70f9d213e8cb71bc225a73494625e31dfaa721.tar.gz mpd-4b70f9d213e8cb71bc225a73494625e31dfaa721.tar.xz mpd-4b70f9d213e8cb71bc225a73494625e31dfaa721.zip |
util/DivideString: add option "strip"
Diffstat (limited to 'src/util/DivideString.cxx')
-rw-r--r-- | src/util/DivideString.cxx | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/util/DivideString.cxx b/src/util/DivideString.cxx index d30dfaa16..f781d141f 100644 --- a/src/util/DivideString.cxx +++ b/src/util/DivideString.cxx @@ -18,10 +18,11 @@ */ #include "DivideString.hxx" +#include "StringUtil.hxx" #include <string.h> -DivideString::DivideString(const char *s, char separator) +DivideString::DivideString(const char *s, char separator, bool strip) :first(nullptr) { const char *x = strchr(s, separator); @@ -31,6 +32,16 @@ DivideString::DivideString(const char *s, char separator) size_t length = x - s; second = x + 1; + if (strip) + second = StripLeft(second); + + if (strip) { + const char *end = s + length; + s = StripLeft(s); + end = StripRight(s, end); + length = end - s; + } + first = new char[length + 1]; memcpy(first, s, length); first[length] = 0; |