mpd/src/util/DivideString.cxx

33 lines
622 B
C++
Raw Normal View History

// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project
#include "DivideString.hxx"
#include "StringStrip.hxx"
#include <cstring>
2017-05-16 10:22:36 +02:00
DivideString::DivideString(const char *s, char separator, bool strip) noexcept
:first(nullptr)
{
const char *x = std::strchr(s, separator);
if (x == nullptr)
return;
size_t length = x - s;
second = x + 1;
2014-12-04 23:05:44 +01:00
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;
}