util/DivideString: add option "strip"
This commit is contained in:
@@ -128,7 +128,7 @@ AoOutput::Configure(const config_param ¶m, Error &error)
|
||||
value = param.GetBlockValue("options", nullptr);
|
||||
if (value != nullptr) {
|
||||
for (const auto &i : SplitString(value, ';')) {
|
||||
const DivideString ss(i.c_str(), '=');
|
||||
const DivideString ss(i.c_str(), '=', true);
|
||||
|
||||
if (!ss.IsDefined()) {
|
||||
error.Format(ao_output_domain,
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user