aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-12-14 12:58:26 +0100
committerMax Kellermann <max@duempel.org>2013-12-14 12:58:26 +0100
commit635a67afac8e8af1a848d67dbfc287eb9b67dd70 (patch)
tree1e3f9daeafe1fedee9186e3c0440b37a4b950422 /src/decoder
parentc7e7c819a2b76553efeae35c4449cadf642a53b3 (diff)
downloadmpd-635a67afac8e8af1a848d67dbfc287eb9b67dd70.tar.gz
mpd-635a67afac8e8af1a848d67dbfc287eb9b67dd70.tar.xz
mpd-635a67afac8e8af1a848d67dbfc287eb9b67dd70.zip
util/SplitString: new utility class
To replace g_strdup().
Diffstat (limited to 'src/decoder')
-rw-r--r--src/decoder/FlacMetadata.cxx15
-rw-r--r--src/decoder/VorbisComments.cxx16
2 files changed, 11 insertions, 20 deletions
diff --git a/src/decoder/FlacMetadata.cxx b/src/decoder/FlacMetadata.cxx
index 9cbedd67b..a3d62d07a 100644
--- a/src/decoder/FlacMetadata.cxx
+++ b/src/decoder/FlacMetadata.cxx
@@ -26,6 +26,7 @@
#include "tag/TagBuilder.hxx"
#include "ReplayGainInfo.hxx"
#include "util/ASCII.hxx"
+#include "util/SplitString.hxx"
#include <glib.h>
@@ -165,16 +166,12 @@ flac_scan_comment(const FLAC__StreamMetadata_VorbisComment_Entry *entry,
const struct tag_handler *handler, void *handler_ctx)
{
if (handler->pair != nullptr) {
- char *name = g_strdup((const char*)entry->entry);
- char *value = strchr(name, '=');
-
- if (value != nullptr && value > name) {
- *value++ = 0;
+ const char *comment = (const char *)entry->entry;
+ const SplitString split(comment, '=');
+ if (split.IsDefined() && !split.IsEmpty())
tag_handler_invoke_pair(handler, handler_ctx,
- name, value);
- }
-
- g_free(name);
+ split.GetFirst(),
+ split.GetSecond());
}
for (const struct tag_table *i = xiph_tags; i->name != nullptr; ++i)
diff --git a/src/decoder/VorbisComments.cxx b/src/decoder/VorbisComments.cxx
index 4a6cded42..2adc498d5 100644
--- a/src/decoder/VorbisComments.cxx
+++ b/src/decoder/VorbisComments.cxx
@@ -25,8 +25,7 @@
#include "tag/TagBuilder.hxx"
#include "ReplayGainInfo.hxx"
#include "util/ASCII.hxx"
-
-#include <glib.h>
+#include "util/SplitString.hxx"
#include <stddef.h>
#include <string.h>
@@ -102,16 +101,11 @@ vorbis_scan_comment(const char *comment,
const struct tag_handler *handler, void *handler_ctx)
{
if (handler->pair != nullptr) {
- char *name = g_strdup(comment);
- char *value = strchr(name, '=');
-
- if (value != nullptr && value > name) {
- *value++ = 0;
+ const SplitString split(comment, '=');
+ if (split.IsDefined() && !split.IsEmpty())
tag_handler_invoke_pair(handler, handler_ctx,
- name, value);
- }
-
- g_free(name);
+ split.GetFirst(),
+ split.GetSecond());
}
for (const struct tag_table *i = xiph_tags; i->name != nullptr; ++i)