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 | |
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')
-rw-r--r-- | src/util/DivideString.cxx | 13 | ||||
-rw-r--r-- | src/util/DivideString.hxx | 6 |
2 files changed, 17 insertions, 2 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; diff --git a/src/util/DivideString.hxx b/src/util/DivideString.hxx index d8d911691..126aa45d1 100644 --- a/src/util/DivideString.hxx +++ b/src/util/DivideString.hxx @@ -33,7 +33,11 @@ class DivideString { const char *second; public: - DivideString(const char *s, char separator); + /** + * @param strip strip the first part and left-strip the second + * part? + */ + DivideString(const char *s, char separator, bool strip=false); ~DivideString() { delete[] first; |