db/upnp/Directory: apply coding style
This commit is contained in:
@@ -90,7 +90,7 @@ ParseDuration(const char *duration)
|
|||||||
*/
|
*/
|
||||||
gcc_pure
|
gcc_pure
|
||||||
static std::string
|
static std::string
|
||||||
titleToPathElt(std::string &&s)
|
TitleToPathSegment(std::string &&s)
|
||||||
{
|
{
|
||||||
std::replace(s.begin(), s.end(), '/', '_');
|
std::replace(s.begin(), s.end(), '/', '_');
|
||||||
return s;
|
return s;
|
||||||
@@ -100,7 +100,7 @@ titleToPathElt(std::string &&s)
|
|||||||
* An XML parser which builds directory contents from DIDL lite input.
|
* An XML parser which builds directory contents from DIDL lite input.
|
||||||
*/
|
*/
|
||||||
class UPnPDirParser final : public CommonExpatParser {
|
class UPnPDirParser final : public CommonExpatParser {
|
||||||
UPnPDirContent &m_dir;
|
UPnPDirContent &directory;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
NONE,
|
NONE,
|
||||||
@@ -120,22 +120,22 @@ class UPnPDirParser final : public CommonExpatParser {
|
|||||||
*/
|
*/
|
||||||
std::string value;
|
std::string value;
|
||||||
|
|
||||||
UPnPDirObject m_tobj;
|
UPnPDirObject object;
|
||||||
TagBuilder tag;
|
TagBuilder tag;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UPnPDirParser(UPnPDirContent& dir)
|
UPnPDirParser(UPnPDirContent &_directory)
|
||||||
:m_dir(dir),
|
:directory(_directory),
|
||||||
state(NONE),
|
state(NONE),
|
||||||
tag_type(TAG_NUM_OF_ITEM_TYPES)
|
tag_type(TAG_NUM_OF_ITEM_TYPES)
|
||||||
{
|
{
|
||||||
m_tobj.Clear();
|
object.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void StartElement(const XML_Char *name, const XML_Char **attrs)
|
virtual void StartElement(const XML_Char *name, const XML_Char **attrs)
|
||||||
{
|
{
|
||||||
if (m_tobj.type != UPnPDirObject::Type::UNKNOWN &&
|
if (object.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);
|
||||||
if (tag_type != TAG_NUM_OF_ITEM_TYPES)
|
if (tag_type != TAG_NUM_OF_ITEM_TYPES)
|
||||||
@@ -147,31 +147,31 @@ protected:
|
|||||||
switch (name[0]) {
|
switch (name[0]) {
|
||||||
case 'c':
|
case 'c':
|
||||||
if (!strcmp(name, "container")) {
|
if (!strcmp(name, "container")) {
|
||||||
m_tobj.Clear();
|
object.Clear();
|
||||||
m_tobj.type = UPnPDirObject::Type::CONTAINER;
|
object.type = UPnPDirObject::Type::CONTAINER;
|
||||||
|
|
||||||
const char *id = GetAttribute(attrs, "id");
|
const char *id = GetAttribute(attrs, "id");
|
||||||
if (id != nullptr)
|
if (id != nullptr)
|
||||||
m_tobj.id = id;
|
object.id = id;
|
||||||
|
|
||||||
const char *pid = GetAttribute(attrs, "parentID");
|
const char *pid = GetAttribute(attrs, "parentID");
|
||||||
if (pid != nullptr)
|
if (pid != nullptr)
|
||||||
m_tobj.parent_id = pid;
|
object.parent_id = pid;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
if (!strcmp(name, "item")) {
|
if (!strcmp(name, "item")) {
|
||||||
m_tobj.Clear();
|
object.Clear();
|
||||||
m_tobj.type = UPnPDirObject::Type::ITEM;
|
object.type = UPnPDirObject::Type::ITEM;
|
||||||
|
|
||||||
const char *id = GetAttribute(attrs, "id");
|
const char *id = GetAttribute(attrs, "id");
|
||||||
if (id != nullptr)
|
if (id != nullptr)
|
||||||
m_tobj.id = id;
|
object.id = id;
|
||||||
|
|
||||||
const char *pid = GetAttribute(attrs, "parentID");
|
const char *pid = GetAttribute(attrs, "parentID");
|
||||||
if (pid != nullptr)
|
if (pid != nullptr)
|
||||||
m_tobj.parent_id = pid;
|
object.parent_id = pid;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -200,12 +200,12 @@ protected:
|
|||||||
virtual void EndElement(const XML_Char *name)
|
virtual void EndElement(const XML_Char *name)
|
||||||
{
|
{
|
||||||
if (tag_type != TAG_NUM_OF_ITEM_TYPES) {
|
if (tag_type != TAG_NUM_OF_ITEM_TYPES) {
|
||||||
assert(m_tobj.type != UPnPDirObject::Type::UNKNOWN);
|
assert(object.type != UPnPDirObject::Type::UNKNOWN);
|
||||||
|
|
||||||
tag.AddItem(tag_type, value.c_str());
|
tag.AddItem(tag_type, value.c_str());
|
||||||
|
|
||||||
if (tag_type == TAG_TITLE)
|
if (tag_type == TAG_TITLE)
|
||||||
m_tobj.name = titleToPathElt(std::move(value));
|
object.name = TitleToPathSegment(std::move(value));
|
||||||
|
|
||||||
value.clear();
|
value.clear();
|
||||||
tag_type = TAG_NUM_OF_ITEM_TYPES;
|
tag_type = TAG_NUM_OF_ITEM_TYPES;
|
||||||
@@ -213,9 +213,9 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((!strcmp(name, "container") || !strcmp(name, "item")) &&
|
if ((!strcmp(name, "container") || !strcmp(name, "item")) &&
|
||||||
m_tobj.Check()) {
|
object.Check()) {
|
||||||
tag.Commit(m_tobj.tag);
|
tag.Commit(object.tag);
|
||||||
m_dir.objects.emplace_back(std::move(m_tobj));
|
directory.objects.emplace_back(std::move(object));
|
||||||
}
|
}
|
||||||
|
|
||||||
state = NONE;
|
state = NONE;
|
||||||
@@ -224,7 +224,7 @@ protected:
|
|||||||
virtual void CharacterData(const XML_Char *s, int len)
|
virtual void CharacterData(const XML_Char *s, int len)
|
||||||
{
|
{
|
||||||
if (tag_type != TAG_NUM_OF_ITEM_TYPES) {
|
if (tag_type != TAG_NUM_OF_ITEM_TYPES) {
|
||||||
assert(m_tobj.type != UPnPDirObject::Type::UNKNOWN);
|
assert(object.type != UPnPDirObject::Type::UNKNOWN);
|
||||||
|
|
||||||
value.append(s, len);
|
value.append(s, len);
|
||||||
return;
|
return;
|
||||||
@@ -235,11 +235,11 @@ protected:
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case RES:
|
case RES:
|
||||||
m_tobj.url.assign(s, len);
|
object.url.assign(s, len);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CLASS:
|
case CLASS:
|
||||||
m_tobj.item_class = ParseItemClass(s, len);
|
object.item_class = ParseItemClass(s, len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user