diff --git a/src/util/DivideString.cxx b/src/util/DivideString.cxx deleted file mode 100644 index 49f746979..000000000 --- a/src/util/DivideString.cxx +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -// Copyright The Music Player Daemon Project - -#include "DivideString.hxx" -#include "StringStrip.hxx" - -#include <cstring> - -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; - - 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 deleted file mode 100644 index 71daf44ef..000000000 --- a/src/util/DivideString.hxx +++ /dev/null @@ -1,57 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -// Copyright The Music Player Daemon Project - -#ifndef MPD_DIVIDE_STRING_HXX -#define MPD_DIVIDE_STRING_HXX - -#include <cassert> - -/** - * Split a given constant string at a separator character. Duplicates - * the first part to be able to null-terminate it. - */ -class DivideString { - char *first; - const char *second; - -public: - /** - * @param strip strip the first part and left-strip the second - * part? - */ - DivideString(const char *s, char separator, bool strip=false) noexcept; - - ~DivideString() { - delete[] first; - } - - /** - * Was the separator found? - */ - bool IsDefined() const { - return first != nullptr; - } - - /** - * Is the first part empty? - */ - bool empty() const { - assert(IsDefined()); - - return *first == 0; - } - - const char *GetFirst() const { - assert(IsDefined()); - - return first; - } - - const char *GetSecond() const { - assert(IsDefined()); - - return second; - } -}; - -#endif diff --git a/src/util/meson.build b/src/util/meson.build index 7ada1dd36..144f5db45 100644 --- a/src/util/meson.build +++ b/src/util/meson.build @@ -8,7 +8,6 @@ util = static_library( 'StringUtil.cxx', 'StringCompare.cxx', 'WStringCompare.cxx', - 'DivideString.cxx', 'SplitString.cxx', 'Tokenizer.cxx', 'UriExtract.cxx', diff --git a/test/util/TestDivideString.cxx b/test/util/TestDivideString.cxx deleted file mode 100644 index fe9c31917..000000000 --- a/test/util/TestDivideString.cxx +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Unit tests for src/util/ - */ - -#include "util/DivideString.hxx" - -#include <gtest/gtest.h> - -TEST(DivideString, Basic) -{ - constexpr char input[] = "foo.bar"; - const DivideString ds(input, '.'); - EXPECT_TRUE(ds.IsDefined()); - EXPECT_FALSE(ds.empty()); - EXPECT_EQ(0, strcmp(ds.GetFirst(), "foo")); - EXPECT_EQ(input + 4, ds.GetSecond()); -} - -TEST(DivideString, Empty) -{ - constexpr char input[] = ".bar"; - const DivideString ds(input, '.'); - EXPECT_TRUE(ds.IsDefined()); - EXPECT_TRUE(ds.empty()); - EXPECT_EQ(0, strcmp(ds.GetFirst(), "")); - EXPECT_EQ(input + 1, ds.GetSecond()); -} - -TEST(DivideString, Fail) -{ - constexpr char input[] = "foo!bar"; - const DivideString ds(input, '.'); - EXPECT_FALSE(ds.IsDefined()); -} - -TEST(DivideString, Strip) -{ - constexpr char input[] = " foo\t.\nbar\r"; - const DivideString ds(input, '.', true); - EXPECT_TRUE(ds.IsDefined()); - EXPECT_FALSE(ds.empty()); - EXPECT_EQ(0, strcmp(ds.GetFirst(), "foo")); - EXPECT_EQ(input + 7, ds.GetSecond()); -} diff --git a/test/util/meson.build b/test/util/meson.build index 30e6be00f..544f80314 100644 --- a/test/util/meson.build +++ b/test/util/meson.build @@ -3,7 +3,6 @@ test( executable( 'TestUtil', 'TestCircularBuffer.cxx', - 'TestDivideString.cxx', 'TestException.cxx', 'TestIntrusiveForwardList.cxx', 'TestIntrusiveHashSet.cxx',