db/upnp/Directory: replace std::vector with a simple enum
Reduce bloat.
This commit is contained in:
parent
b7738e7af3
commit
fd754ff8f8
@ -28,17 +28,26 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
gcc_pure gcc_nonnull_all
|
||||||
|
static bool
|
||||||
|
CompareStringLiteral(const char *literal, const char *value, size_t length)
|
||||||
|
{
|
||||||
|
return length == strlen(literal) &&
|
||||||
|
memcmp(literal, value, length) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
static UPnPDirObject::ItemClass
|
static UPnPDirObject::ItemClass
|
||||||
ParseItemClass(const char *name)
|
ParseItemClass(const char *name, size_t length)
|
||||||
{
|
{
|
||||||
if (strcmp(name, "object.item.audioItem.musicTrack") == 0)
|
if (CompareStringLiteral("object.item.audioItem.musicTrack",
|
||||||
|
name, length))
|
||||||
return UPnPDirObject::ItemClass::MUSIC;
|
return UPnPDirObject::ItemClass::MUSIC;
|
||||||
else if (strcmp(name, "object.item.playlistItem") == 0)
|
else if (CompareStringLiteral("object.item.playlistItem",
|
||||||
|
name, length))
|
||||||
return UPnPDirObject::ItemClass::PLAYLIST;
|
return UPnPDirObject::ItemClass::PLAYLIST;
|
||||||
else
|
else
|
||||||
return UPnPDirObject::ItemClass::UNKNOWN;
|
return UPnPDirObject::ItemClass::UNKNOWN;
|
||||||
@ -88,7 +97,11 @@ titleToPathElt(std::string &&s)
|
|||||||
class UPnPDirParser final : public CommonExpatParser {
|
class UPnPDirParser final : public CommonExpatParser {
|
||||||
UPnPDirContent &m_dir;
|
UPnPDirContent &m_dir;
|
||||||
|
|
||||||
std::vector<std::string> m_path;
|
enum {
|
||||||
|
NONE,
|
||||||
|
RES,
|
||||||
|
CLASS,
|
||||||
|
} state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If not equal to #TAG_NUM_OF_ITEM_TYPES, then we're
|
* If not equal to #TAG_NUM_OF_ITEM_TYPES, then we're
|
||||||
@ -108,6 +121,7 @@ class UPnPDirParser final : public CommonExpatParser {
|
|||||||
public:
|
public:
|
||||||
UPnPDirParser(UPnPDirContent& dir)
|
UPnPDirParser(UPnPDirContent& dir)
|
||||||
:m_dir(dir),
|
:m_dir(dir),
|
||||||
|
state(NONE),
|
||||||
tag_type(TAG_NUM_OF_ITEM_TYPES)
|
tag_type(TAG_NUM_OF_ITEM_TYPES)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -115,8 +129,6 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual void StartElement(const XML_Char *name, const XML_Char **attrs)
|
virtual void StartElement(const XML_Char *name, const XML_Char **attrs)
|
||||||
{
|
{
|
||||||
m_path.push_back(name);
|
|
||||||
|
|
||||||
if (m_tobj.type != UPnPDirObject::Type::UNKNOWN &&
|
if (m_tobj.type != UPnPDirObject::Type::UNKNOWN &&
|
||||||
tag_type == TAG_NUM_OF_ITEM_TYPES) {
|
tag_type == TAG_NUM_OF_ITEM_TYPES) {
|
||||||
tag_type = tag_table_lookup(upnp_tags, name);
|
tag_type = tag_table_lookup(upnp_tags, name);
|
||||||
@ -167,9 +179,15 @@ protected:
|
|||||||
GetAttribute(attrs, "duration");
|
GetAttribute(attrs, "duration");
|
||||||
if (duration != nullptr)
|
if (duration != nullptr)
|
||||||
tag.SetTime(ParseDuration(duration));
|
tag.SetTime(ParseDuration(duration));
|
||||||
|
|
||||||
|
state = RES;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'u':
|
||||||
|
if (strcmp(name, "upnp:class") == 0)
|
||||||
|
state = CLASS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +222,7 @@ protected:
|
|||||||
m_dir.objects.push_back(std::move(m_tobj));
|
m_dir.objects.push_back(std::move(m_tobj));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_path.pop_back();
|
state = NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void CharacterData(const XML_Char *s, int len)
|
virtual void CharacterData(const XML_Char *s, int len)
|
||||||
@ -216,20 +234,16 @@ protected:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto ¤t = m_path.back();
|
switch (state) {
|
||||||
std::string str = trimstring(s, len);
|
case NONE:
|
||||||
|
|
||||||
switch (current[0]) {
|
|
||||||
case 'r':
|
|
||||||
if (!current.compare("res")) {
|
|
||||||
m_tobj.url = std::move(str);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'u':
|
|
||||||
if (current == "upnp:class") {
|
case RES:
|
||||||
m_tobj.item_class = ParseItemClass(str.c_str());
|
m_tobj.url.assign(s, len);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
case CLASS:
|
||||||
|
m_tobj.item_class = ParseItemClass(s, len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user