util/DivideString: remove unused library
This commit is contained in:
parent
46b461df42
commit
01a04baf7b
@ -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;
|
||||
}
|
@ -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
|
@ -8,7 +8,6 @@ util = static_library(
|
||||
'StringUtil.cxx',
|
||||
'StringCompare.cxx',
|
||||
'WStringCompare.cxx',
|
||||
'DivideString.cxx',
|
||||
'SplitString.cxx',
|
||||
'Tokenizer.cxx',
|
||||
'UriExtract.cxx',
|
||||
|
@ -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());
|
||||
}
|
@ -3,7 +3,6 @@ test(
|
||||
executable(
|
||||
'TestUtil',
|
||||
'TestCircularBuffer.cxx',
|
||||
'TestDivideString.cxx',
|
||||
'TestException.cxx',
|
||||
'TestIntrusiveForwardList.cxx',
|
||||
'TestIntrusiveHashSet.cxx',
|
||||
|
Loading…
x
Reference in New Issue
Block a user