Switched to LiteralString for keys in subsonic responses
This commit is contained in:
@@ -193,13 +193,13 @@ namespace API::Subsonic
|
|||||||
for (const auto& [key, value] : node._attributes)
|
for (const auto& [key, value] : node._attributes)
|
||||||
{
|
{
|
||||||
if (std::holds_alternative<std::string>(value))
|
if (std::holds_alternative<std::string>(value))
|
||||||
res.put("<xmlattr>." + std::string{ key.get() }, std::get<std::string>(value));
|
res.put("<xmlattr>." + std::string{ key.str() }, std::get<std::string>(value));
|
||||||
else if (std::holds_alternative<bool>(value))
|
else if (std::holds_alternative<bool>(value))
|
||||||
res.put("<xmlattr>." + std::string{ key.get() }, std::get<bool>(value));
|
res.put("<xmlattr>." + std::string{ key.str() }, std::get<bool>(value));
|
||||||
else if (std::holds_alternative<float>(value))
|
else if (std::holds_alternative<float>(value))
|
||||||
res.put("<xmlattr>." + std::string{ key.get() }, std::get<float>(value));
|
res.put("<xmlattr>." + std::string{ key.str() }, std::get<float>(value));
|
||||||
else if (std::holds_alternative<long long>(value))
|
else if (std::holds_alternative<long long>(value))
|
||||||
res.put("<xmlattr>." + std::string{ key.get() }, std::get<long long>(value));
|
res.put("<xmlattr>." + std::string{ key.str() }, std::get<long long>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto valueToPropertyTree = [](const Node::ValueType& value)
|
auto valueToPropertyTree = [](const Node::ValueType& value)
|
||||||
@@ -221,19 +221,19 @@ namespace API::Subsonic
|
|||||||
{
|
{
|
||||||
for (const auto& [key, childNode] : node._children)
|
for (const auto& [key, childNode] : node._children)
|
||||||
{
|
{
|
||||||
res.add_child(std::string{ key.get() }, nodeToPropertyTree(childNode));
|
res.add_child(std::string{ key.str() }, nodeToPropertyTree(childNode));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& [key, childArrayNodes] : node._childrenArrays)
|
for (const auto& [key, childArrayNodes] : node._childrenArrays)
|
||||||
{
|
{
|
||||||
for (const Node& childNode : childArrayNodes)
|
for (const Node& childNode : childArrayNodes)
|
||||||
res.add_child(std::string{ key.get() }, nodeToPropertyTree(childNode));
|
res.add_child(std::string{ key.str() }, nodeToPropertyTree(childNode));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& [key, childArrayValues] : node._childrenValues)
|
for (const auto& [key, childArrayValues] : node._childrenValues)
|
||||||
{
|
{
|
||||||
for (const Response::Node::ValueType& value : childArrayValues)
|
for (const Response::Node::ValueType& value : childArrayValues)
|
||||||
res.add_child(std::string{ key.get() }, valueToPropertyTree(value));
|
res.add_child(std::string{ key.str() }, valueToPropertyTree(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,7 +255,7 @@ namespace API::Subsonic
|
|||||||
if (!first)
|
if (!first)
|
||||||
os << ',';
|
os << ',';
|
||||||
|
|
||||||
serializeEscapedString(os, key.get());
|
serializeEscapedString(os, key.str());
|
||||||
os << ':';
|
os << ':';
|
||||||
serializeValue(os, value);
|
serializeValue(os, value);
|
||||||
|
|
||||||
@@ -279,7 +279,7 @@ namespace API::Subsonic
|
|||||||
if (!first)
|
if (!first)
|
||||||
os << ',';
|
os << ',';
|
||||||
|
|
||||||
serializeEscapedString(os, key.get());
|
serializeEscapedString(os, key.str());
|
||||||
os << ':';
|
os << ':';
|
||||||
serializeNode(os, childNode);
|
serializeNode(os, childNode);
|
||||||
|
|
||||||
@@ -291,7 +291,7 @@ namespace API::Subsonic
|
|||||||
if (!first)
|
if (!first)
|
||||||
os << ',';
|
os << ',';
|
||||||
|
|
||||||
serializeEscapedString(os, key.get());
|
serializeEscapedString(os, key.str());
|
||||||
os << ":[";
|
os << ":[";
|
||||||
|
|
||||||
bool firstChild{ true };
|
bool firstChild{ true };
|
||||||
@@ -313,7 +313,7 @@ namespace API::Subsonic
|
|||||||
if (!first)
|
if (!first)
|
||||||
os << ',';
|
os << ',';
|
||||||
|
|
||||||
serializeEscapedString(os, key.get());
|
serializeEscapedString(os, key.str());
|
||||||
os << ":[";
|
os << ":[";
|
||||||
|
|
||||||
bool firstChild{ true };
|
bool firstChild{ true };
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <variant>
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "utils/LiteralString.hpp"
|
||||||
#include "RequestContext.hpp"
|
#include "RequestContext.hpp"
|
||||||
|
|
||||||
namespace API::Subsonic
|
namespace API::Subsonic
|
||||||
@@ -205,18 +206,7 @@ namespace API::Subsonic
|
|||||||
class Node
|
class Node
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
class Key
|
using Key = LiteralString;
|
||||||
{
|
|
||||||
public:
|
|
||||||
template<std::size_t N>
|
|
||||||
constexpr Key(const char (&str)[N]) : _str{ str } {}
|
|
||||||
constexpr std::string_view get() const { return _str; }
|
|
||||||
|
|
||||||
bool constexpr operator<(const Key& other) const { return _str < other._str; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
const std::string_view _str;
|
|
||||||
};
|
|
||||||
|
|
||||||
void setAttribute(Key key, std::string_view value);
|
void setAttribute(Key key, std::string_view value);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user