From 050f0c3d8f374011eb8199254714fdba9a78c49f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 3 Dec 2014 21:38:06 +0100 Subject: util/SplitString: rename to DivideString --- Makefile.am | 2 +- src/decoder/plugins/FlacMetadata.cxx | 4 +- src/decoder/plugins/VorbisComments.cxx | 4 +- src/output/plugins/AoOutputPlugin.cxx | 4 +- src/util/DivideString.cxx | 37 ++++++++++++++++++ src/util/DivideString.hxx | 71 ++++++++++++++++++++++++++++++++++ src/util/SplitString.cxx | 37 ------------------ src/util/SplitString.hxx | 71 ---------------------------------- 8 files changed, 115 insertions(+), 115 deletions(-) create mode 100644 src/util/DivideString.cxx create mode 100644 src/util/DivideString.hxx delete mode 100644 src/util/SplitString.cxx delete mode 100644 src/util/SplitString.hxx diff --git a/Makefile.am b/Makefile.am index 023f7e45a..339f27e2e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -374,7 +374,7 @@ libutil_a_SOURCES = \ src/util/CharUtil.hxx \ src/util/NumberParser.hxx \ src/util/StringUtil.cxx src/util/StringUtil.hxx \ - src/util/SplitString.cxx src/util/SplitString.hxx \ + src/util/DivideString.cxx src/util/DivideString.hxx \ src/util/FormatString.cxx src/util/FormatString.hxx \ src/util/Tokenizer.cxx src/util/Tokenizer.hxx \ src/util/TextFile.hxx \ diff --git a/src/decoder/plugins/FlacMetadata.cxx b/src/decoder/plugins/FlacMetadata.cxx index 03e276dce..86c6da04b 100644 --- a/src/decoder/plugins/FlacMetadata.cxx +++ b/src/decoder/plugins/FlacMetadata.cxx @@ -30,7 +30,7 @@ #include "tag/MixRamp.hxx" #include "ReplayGainInfo.hxx" #include "util/ASCII.hxx" -#include "util/SplitString.hxx" +#include "util/DivideString.hxx" bool flac_parse_replay_gain(ReplayGainInfo &rgi, @@ -97,7 +97,7 @@ flac_scan_comment(const FLAC__StreamMetadata_VorbisComment_Entry *entry, { if (handler->pair != nullptr) { const char *comment = (const char *)entry->entry; - const SplitString split(comment, '='); + const DivideString split(comment, '='); if (split.IsDefined() && !split.IsEmpty()) tag_handler_invoke_pair(handler, handler_ctx, split.GetFirst(), diff --git a/src/decoder/plugins/VorbisComments.cxx b/src/decoder/plugins/VorbisComments.cxx index 062f46acf..10652f129 100644 --- a/src/decoder/plugins/VorbisComments.cxx +++ b/src/decoder/plugins/VorbisComments.cxx @@ -27,7 +27,7 @@ #include "tag/ReplayGain.hxx" #include "ReplayGainInfo.hxx" #include "util/ASCII.hxx" -#include "util/SplitString.hxx" +#include "util/DivideString.hxx" #include #include @@ -74,7 +74,7 @@ vorbis_scan_comment(const char *comment, const struct tag_handler *handler, void *handler_ctx) { if (handler->pair != nullptr) { - const SplitString split(comment, '='); + const DivideString split(comment, '='); if (split.IsDefined() && !split.IsEmpty()) tag_handler_invoke_pair(handler, handler_ctx, split.GetFirst(), diff --git a/src/output/plugins/AoOutputPlugin.cxx b/src/output/plugins/AoOutputPlugin.cxx index 2b66fb8db..6faa30b1b 100644 --- a/src/output/plugins/AoOutputPlugin.cxx +++ b/src/output/plugins/AoOutputPlugin.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "AoOutputPlugin.hxx" #include "../OutputAPI.hxx" -#include "util/SplitString.hxx" +#include "util/DivideString.hxx" #include "util/Error.hxx" #include "util/Domain.hxx" #include "Log.hxx" @@ -130,7 +130,7 @@ AoOutput::Configure(const config_param ¶m, Error &error) gchar **_options = g_strsplit(value, ";", 0); for (unsigned i = 0; _options[i] != nullptr; ++i) { - const SplitString ss(_options[i], '='); + const DivideString ss(_options[i], '='); if (!ss.IsDefined()) { error.Format(ao_output_domain, diff --git a/src/util/DivideString.cxx b/src/util/DivideString.cxx new file mode 100644 index 000000000..d30dfaa16 --- /dev/null +++ b/src/util/DivideString.cxx @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2003-2014 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "DivideString.hxx" + +#include + +DivideString::DivideString(const char *s, char separator) + :first(nullptr) +{ + const char *x = strchr(s, separator); + if (x == nullptr) + return; + + size_t length = x - s; + second = x + 1; + + first = new char[length + 1]; + memcpy(first, s, length); + first[length] = 0; +} diff --git a/src/util/DivideString.hxx b/src/util/DivideString.hxx new file mode 100644 index 000000000..d8d911691 --- /dev/null +++ b/src/util/DivideString.hxx @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2003-2014 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_DIVIDE_STRING_HXX +#define MPD_DIVIDE_STRING_HXX + +#include "Compiler.h" + +#include + +/** + * 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: + DivideString(const char *s, char separator); + + ~DivideString() { + delete[] first; + } + + /** + * Was the separator found? + */ + bool IsDefined() const { + return first != nullptr; + } + + /** + * Is the first part empty? + */ + bool IsEmpty() 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/SplitString.cxx b/src/util/SplitString.cxx deleted file mode 100644 index 75e799279..000000000 --- a/src/util/SplitString.cxx +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2003-2014 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "SplitString.hxx" - -#include - -SplitString::SplitString(const char *s, char separator) - :first(nullptr) -{ - const char *x = strchr(s, separator); - if (x == nullptr) - return; - - size_t length = x - s; - second = x + 1; - - first = new char[length + 1]; - memcpy(first, s, length); - first[length] = 0; -} diff --git a/src/util/SplitString.hxx b/src/util/SplitString.hxx deleted file mode 100644 index 96ffb21ec..000000000 --- a/src/util/SplitString.hxx +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2003-2014 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPD_SPLIT_STRING_HXX -#define MPD_SPLIT_STRING_HXX - -#include "Compiler.h" - -#include - -/** - * Split a given constant string at a separator character. Duplicates - * the first part to be able to null-terminate it. - */ -class SplitString { - char *first; - const char *second; - -public: - SplitString(const char *s, char separator); - - ~SplitString() { - delete[] first; - } - - /** - * Was the separator found? - */ - bool IsDefined() const { - return first != nullptr; - } - - /** - * Is the first part empty? - */ - bool IsEmpty() const { - assert(IsDefined()); - - return *first == 0; - } - - const char *GetFirst() const { - assert(IsDefined()); - - return first; - } - - const char *GetSecond() const { - assert(IsDefined()); - - return second; - } -}; - -#endif -- cgit v1.2.3