tag/Tag: move tag_name_parse() to ParseName.cxx

This commit is contained in:
Max Kellermann
2017-02-08 08:57:22 +01:00
parent 03a97d87ea
commit a3e28c2d1a
15 changed files with 110 additions and 58 deletions

View File

@@ -20,7 +20,7 @@
#include "config.h"
#include "ApeTag.hxx"
#include "ApeLoader.hxx"
#include "Tag.hxx"
#include "ParseName.hxx"
#include "Table.hxx"
#include "Handler.hxx"
#include "util/StringView.hxx"

View File

@@ -20,7 +20,7 @@
#include "config.h"
#include "Config.hxx"
#include "Settings.hxx"
#include "Tag.hxx"
#include "ParseName.hxx"
#include "config/ConfigGlobal.hxx"
#include "config/ConfigOption.hxx"
#include "system/FatalError.hxx"

View File

@@ -20,6 +20,7 @@
#include "config.h"
#include "Format.hxx"
#include "Tag.hxx"
#include "ParseName.hxx"
#include "util/format.h"
#include "util/StringUtil.hxx"

55
src/tag/ParseName.cxx Normal file
View File

@@ -0,0 +1,55 @@
/*
* Copyright 2003-2017 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 "ParseName.hxx"
#include "util/ASCII.hxx"
#include <assert.h>
#include <string.h>
TagType
tag_name_parse(const char *name)
{
assert(name != nullptr);
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) {
assert(tag_item_names[i] != nullptr);
if (strcmp(name, tag_item_names[i]) == 0)
return (TagType)i;
}
return TAG_NUM_OF_ITEM_TYPES;
}
TagType
tag_name_parse_i(const char *name)
{
assert(name != nullptr);
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) {
assert(tag_item_names[i] != nullptr);
if (StringEqualsCaseASCII(name, tag_item_names[i]))
return (TagType)i;
}
return TAG_NUM_OF_ITEM_TYPES;
}

44
src/tag/ParseName.hxx Normal file
View File

@@ -0,0 +1,44 @@
/*
* Copyright 2003-2017 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_PARSE_NAME_HXX
#define MPD_TAG_PARSE_NAME_HXX
#include "Type.h"
#include "Compiler.h"
/**
* Parse the string, and convert it into a #TagType. Returns
* #TAG_NUM_OF_ITEM_TYPES if the string could not be recognized.
*/
gcc_pure
TagType
tag_name_parse(const char *name);
/**
* Parse the string, and convert it into a #TagType. Returns
* #TAG_NUM_OF_ITEM_TYPES if the string could not be recognized.
*
* Case does not matter.
*/
gcc_pure
TagType
tag_name_parse_i(const char *name);
#endif

View File

@@ -21,40 +21,8 @@
#include "Tag.hxx"
#include "Pool.hxx"
#include "Builder.hxx"
#include "util/ASCII.hxx"
#include <assert.h>
#include <string.h>
TagType
tag_name_parse(const char *name)
{
assert(name != nullptr);
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) {
assert(tag_item_names[i] != nullptr);
if (strcmp(name, tag_item_names[i]) == 0)
return (TagType)i;
}
return TAG_NUM_OF_ITEM_TYPES;
}
TagType
tag_name_parse_i(const char *name)
{
assert(name != nullptr);
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) {
assert(tag_item_names[i] != nullptr);
if (StringEqualsCaseASCII(name, tag_item_names[i]))
return (TagType)i;
}
return TAG_NUM_OF_ITEM_TYPES;
}
void
Tag::Clear()

View File

@@ -196,22 +196,4 @@ struct Tag {
}
};
/**
* Parse the string, and convert it into a #TagType. Returns
* #TAG_NUM_OF_ITEM_TYPES if the string could not be recognized.
*/
gcc_pure
TagType
tag_name_parse(const char *name);
/**
* Parse the string, and convert it into a #TagType. Returns
* #TAG_NUM_OF_ITEM_TYPES if the string could not be recognized.
*
* Case does not matter.
*/
gcc_pure
TagType
tag_name_parse_i(const char *name);
#endif