diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/decoder/plugins/FlacMetadata.cxx | 13 | ||||
-rw-r--r-- | src/decoder/plugins/VorbisComments.cxx | 14 | ||||
-rw-r--r-- | src/tag/VorbisComment.cxx | 41 | ||||
-rw-r--r-- | src/tag/VorbisComment.hxx | 34 |
4 files changed, 78 insertions, 24 deletions
diff --git a/src/decoder/plugins/FlacMetadata.cxx b/src/decoder/plugins/FlacMetadata.cxx index 0ee6026dd..a36d1b2e9 100644 --- a/src/decoder/plugins/FlacMetadata.cxx +++ b/src/decoder/plugins/FlacMetadata.cxx @@ -25,6 +25,7 @@ #include "tag/TagTable.hxx" #include "tag/TagBuilder.hxx" #include "tag/Tag.hxx" +#include "tag/VorbisComment.hxx" #include "ReplayGainInfo.hxx" #include "util/ASCII.hxx" #include "util/SplitString.hxx" @@ -114,17 +115,7 @@ static const char * flac_comment_value(const FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *name) { - size_t name_length = strlen(name); - const char *comment = (const char*)entry->entry; - - if (!StringEqualsCaseASCII(comment, name, name_length)) - return nullptr; - - if (comment[name_length] == '=') { - return comment + name_length + 1; - } - - return nullptr; + return vorbis_comment_value((const char *)entry->entry, name); } /** diff --git a/src/decoder/plugins/VorbisComments.cxx b/src/decoder/plugins/VorbisComments.cxx index 2a0820ab5..f1dcdc1b0 100644 --- a/src/decoder/plugins/VorbisComments.cxx +++ b/src/decoder/plugins/VorbisComments.cxx @@ -23,26 +23,14 @@ #include "tag/TagTable.hxx" #include "tag/TagHandler.hxx" #include "tag/TagBuilder.hxx" +#include "tag/VorbisComment.hxx" #include "ReplayGainInfo.hxx" #include "util/ASCII.hxx" #include "util/SplitString.hxx" #include <stddef.h> -#include <string.h> #include <stdlib.h> -static const char * -vorbis_comment_value(const char *comment, const char *needle) -{ - size_t len = strlen(needle); - - if (StringEqualsCaseASCII(comment, needle, len) && - comment[len] == '=') - return comment + len + 1; - - return nullptr; -} - bool vorbis_comments_to_replay_gain(ReplayGainInfo &rgi, char **comments) { diff --git a/src/tag/VorbisComment.cxx b/src/tag/VorbisComment.cxx new file mode 100644 index 000000000..2dfc058d8 --- /dev/null +++ b/src/tag/VorbisComment.cxx @@ -0,0 +1,41 @@ +/* + * 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 "config.h" +#include "VorbisComment.hxx" +#include "util/ASCII.hxx" + +#include <assert.h> +#include <string.h> + +const char * +vorbis_comment_value(const char *entry, const char *name) +{ + assert(entry != nullptr); + assert(name != nullptr); + assert(*name != 0); + + const size_t length = strlen(name); + + if (StringEqualsCaseASCII(entry, name, length) && + entry[length] == '=') + return entry + length + 1; + + return nullptr; +} diff --git a/src/tag/VorbisComment.hxx b/src/tag/VorbisComment.hxx new file mode 100644 index 000000000..1dd3371c8 --- /dev/null +++ b/src/tag/VorbisComment.hxx @@ -0,0 +1,34 @@ +/* + * 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_TAG_VORBIS_COMMENT_HXX +#define MPD_TAG_VORBIS_COMMENT_HXX + +#include "check.h" +#include "Compiler.h" + +/** + * Checks if the specified name matches the entry's name, and if yes, + * returns the comment value. + */ +gcc_pure +const char * +vorbis_comment_value(const char *entry, const char *name); + +#endif |