-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnaming.cpp
More file actions
62 lines (56 loc) · 1.8 KB
/
naming.cpp
File metadata and controls
62 lines (56 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// *******************************************************************
// DCue (github.com/xavery/dcue)
// Copyright (c) 2019-2022 Daniel Kamil Kozar
// Original version by :
// DCue (sourceforge.net/projects/dcue)
// Copyright (c) 2013 Fluxtion, DCue project
// *******************************************************************
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// *******************************************************************
#include "naming.h"
#include <cctype>
#include <nlohmann/json.hpp>
namespace {
void remove_artist_number(std::string& out) {
const std::string::size_type out_size = out.size();
if (out[out_size - 1] == ')' && std::isdigit(out[out_size - 2])) {
const std::string::size_type bracket = out.find_last_of("(");
if (bracket != std::string::npos) {
out.erase(bracket - 1);
}
}
}
void reverse_artist_the(std::string& out) {
const std::string::size_type out_size = out.size();
if (out_size > 5 && out.substr(out_size - 5) == ", The") {
out.erase(out_size - 5);
out = "The " + out;
}
}
void artist_facets(std::string& out) {
remove_artist_number(out);
reverse_artist_the(out);
}
}
std::string NamingFacets::concatenate_artists(const nlohmann::json& artists) {
std::string rv;
for (auto&& artist_info : artists) {
auto name = artist_info.value("anv", std::string());
if (name.empty()) {
name = artist_info.value("name", std::string());
}
artist_facets(name);
rv += name;
if (&artist_info != &artists.back()) {
auto join = artist_info.value("join", ",");
if (join != ",") {
rv += " ";
}
rv += join;
rv += " ";
}
}
return rv;
}