From 9031927b15cc487693dc14f9398c7fdba54cfe07 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 4 Oct 2023 15:42:14 +0200 Subject: Anilist better studios/producers formatting --- src/plugins/AniList.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/plugins/AniList.cpp b/src/plugins/AniList.cpp index 50b1a86..fb23ab6 100644 --- a/src/plugins/AniList.cpp +++ b/src/plugins/AniList.cpp @@ -290,7 +290,17 @@ query ($id: Int, $page: Int, $perPage: Int) { return {0, 0}; } - static void get_studios_and_producers(const Json::Value &nodes_json, std::string &studios, std::string &producers) { + static std::string string_vector_comma_separate(const std::vector &vec) { + std::string result; + for(const std::string &item : vec) { + if(!result.empty()) + result += ", "; + result += item; + } + return result; + } + + static void get_studios_and_producers(const Json::Value &nodes_json, std::vector &studios, std::vector &producers) { if(!nodes_json.isArray()) return; @@ -304,13 +314,9 @@ query ($id: Int, $page: Int, $perPage: Int) { continue; if(is_animation_studio_json.asBool()) { - if(!studios.empty()) - studios += "\n"; - studios += name_json.asString(); + studios.push_back(name_json.asString()); } else { - if(!producers.empty()) - producers += "\n"; - producers += name_json.asString(); + producers.push_back(name_json.asString()); } } } @@ -419,22 +425,22 @@ query ($id: Int, $page: Int, $perPage: Int) { } if(studios_json.isObject()) { - std::string studios; - std::string producers; + std::vector studios; + std::vector producers; get_studios_and_producers(studios_json["nodes"], studios, producers); if(!studios.empty()) { if(!description.empty()) description += "\n\n"; description += "Studios:\n"; - description.append(studios); + description.append(string_vector_comma_separate(studios)); } if(!producers.empty()) { if(!description.empty()) description += "\n\n"; description += "Producers:\n"; - description.append(producers); + description.append(string_vector_comma_separate(producers)); } } -- cgit v1.2.3