Separated feedback services (stars / love for LB) from scrobbling services, to ease last.fm integration

This commit is contained in:
emeric
2023-10-31 13:37:14 +01:00
parent 3920c36896
commit 069470194b
89 changed files with 3763 additions and 3616 deletions
+1
View File
@@ -31,6 +31,7 @@ const char* getModuleName(Module mod)
case Module::DB: return "DB";
case Module::DBUPDATER: return "DB UPDATER";
case Module::FEATURE: return "FEATURE";
case Module::FEEDBACK: return "FEEDBACK";
case Module::HTTP: return "HTTP";
case Module::MAIN: return "MAIN";
case Module::METADATA: return "METADATA";
+69 -44
View File
@@ -21,7 +21,7 @@
#include <algorithm>
#include <iomanip>
#include <unordered_map>
#include <utility>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>
@@ -33,6 +33,63 @@
namespace StringUtils
{
namespace
{
constexpr std::pair<char, std::string_view> jsEscapeChars[]
{
{ '\\', "\\\\" },
{ '\n', "\\n" },
{ '\r', "\\r" },
{ '\t', "\\t" },
{ '"', "\\\"" },
{ '\'', "\\\'" },
};
constexpr std::pair<char, std::string_view> jsonEscapeChars[]
{
{ '\\', "\\\\" },
{ '\n', "\\n" },
{ '\r', "\\r" },
{ '\t', "\\t" },
{ '"', "\\\"" },
{ '\'', "\\\'" },
};
template <std::size_t N>
std::string escape(std::string_view str, const std::pair<char, std::string_view>(&charsToEscape)[N])
{
std::string escaped;
escaped.reserve(str.length());
for (const char c : str)
{
auto it{ std::find_if(std::cbegin(charsToEscape), std::cend(charsToEscape), [c](const auto& entry) { return entry.first == c; }) };
if (it == std::cend(charsToEscape))
{
escaped += c;
continue;
}
escaped += it->second;
}
return escaped;
}
template <std::size_t N>
void writeEscapedString(std::ostream& os, std::string_view str, const std::pair<char, std::string_view>(&charsToEscape)[N])
{
for (const char c : str)
{
auto itEntry{ std::find_if(std::cbegin(charsToEscape), std::cend(charsToEscape), [=](const auto& entry) { return entry.first == c;}) };
if (itEntry != std::cend(charsToEscape))
os << itEntry->second;
else
os << c;
}
}
}
bool readList(const std::string& str, const std::string& separators, std::list<std::string>& results)
{
std::string curStr;
@@ -221,54 +278,22 @@ namespace StringUtils
std::string jsEscape(std::string_view str)
{
static const std::unordered_map<char, std::string_view> escapeMap
{
{ '\\', "\\\\" },
{ '\n', "\\n" },
{ '\r', "\\r" },
{ '\t', "\\t" },
{ '"', "\\\"" },
{ '\'', "\\\'" },
};
std::string escaped;
escaped.reserve(str.length());
for (const char c : str)
{
auto it{ escapeMap.find(c) };
if (it == std::cend(escapeMap))
{
escaped += c;
continue;
}
escaped += it->second;
}
return escaped;
return escape(str, jsEscapeChars);
}
void writeJSEscapedString(std::ostream& os, std::string_view str)
{
static constexpr std::pair<char, std::string_view> charsToEscape[]
{
{'\\', "\\\\" },
{ '\n', "\\n" },
{ '\r', "\\r" },
{ '\t', "\\t" },
{ '"', "\\\"" },
{ '\'', "\\\'" },
};
writeEscapedString(os, str, jsEscapeChars);
}
std::string jsonEscape(std::string_view str)
{
return escape(str, jsonEscapeChars);
}
for (const char c : str)
{
auto itEntry{ std::find_if(std::cbegin(charsToEscape), std::cend(charsToEscape), [=](const auto& entry) { return entry.first == c;}) };
if (itEntry != std::cend(charsToEscape))
os << itEntry->second;
else
os << c;
}
void writeJsonEscapedString(std::ostream& os, std::string_view str)
{
writeEscapedString(os, str, jsonEscapeChars);
}
std::string escapeString(std::string_view str, std::string_view charsToEscape, char escapeChar)