decoder/{vorbis,flac}: move duplicate code to tag/VorbisComment.cxx
This commit is contained in:
parent
05dd9acba8
commit
d1e31261fe
@ -766,6 +766,7 @@ libtag_a_SOURCES =\
|
||||
src/tag/TagPool.cxx src/tag/TagPool.hxx \
|
||||
src/tag/TagTable.cxx src/tag/TagTable.hxx \
|
||||
src/tag/Set.cxx src/tag/Set.hxx \
|
||||
src/tag/VorbisComment.cxx src/tag/VorbisComment.hxx \
|
||||
src/tag/ReplayGain.cxx src/tag/ReplayGain.hxx \
|
||||
src/tag/ApeLoader.cxx src/tag/ApeLoader.hxx \
|
||||
src/tag/ApeReplayGain.cxx src/tag/ApeReplayGain.hxx \
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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)
|
||||
{
|
||||
|
41
src/tag/VorbisComment.cxx
Normal file
41
src/tag/VorbisComment.cxx
Normal file
@ -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;
|
||||
}
|
34
src/tag/VorbisComment.hxx
Normal file
34
src/tag/VorbisComment.hxx
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user