Mercurial > minori
comparison src/core/anime_db.cc @ 264:9a04802848c0
*: improve multiple things
e.g. making some strings.cc functions modify strings in-place,
improving m4_ax_have_qt.m4 code, making anime_db.cc rely on
std::optional rather than std::shared_ptr (which was stupid
anyway)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Thu, 11 Apr 2024 10:15:57 -0400 |
parents | dd211ff68b36 |
children | 657fda1b9cac |
comparison
equal
deleted
inserted
replaced
263:96416310ea14 | 264:9a04802848c0 |
---|---|
102 amt++; | 102 amt++; |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 return (amt > 0) ? std::sqrt(squares_sum / amt) : 0; | 106 return (amt > 0) ? std::sqrt(squares_sum / amt) : 0; |
107 } | |
108 | |
109 template<typename T, typename U> | |
110 static T get_lowest_in_map(const std::unordered_map<T, U>& map) { | |
111 if (map.size() <= 0) | |
112 return 0; | |
113 | |
114 T id = 0; | |
115 U ret = std::numeric_limits<U>::max(); | |
116 for (const auto& t : map) { | |
117 if (t.second < ret) { | |
118 ret = t.second; | |
119 id = t.first; | |
120 } | |
121 } | |
122 return id; | |
123 } | 107 } |
124 | 108 |
125 /* | 109 /* |
126 * TODO: separate this from the anime DB, | 110 * TODO: separate this from the anime DB, |
127 * provide *some* sort of normalization | 111 * provide *some* sort of normalization |
128 */ | 112 */ |
129 int Database::GetAnimeFromTitle(const std::string& title) { | 113 int Database::GetAnimeFromTitle(const std::string& title) { |
130 if (title.empty()) | 114 if (title.empty()) |
131 return 0; | 115 return 0; |
132 | 116 |
117 std::string title_n(title); | |
118 Strings::NormalizeAnimeTitle(title_n); | |
119 | |
133 for (const auto& [id, anime] : items) { | 120 for (const auto& [id, anime] : items) { |
134 std::vector<std::string> synonyms(anime.GetTitleSynonyms()); | 121 std::vector<std::string> synonyms(anime.GetTitleSynonyms()); |
135 synonyms.push_back(anime.GetUserPreferredTitle()); | 122 synonyms.push_back(anime.GetUserPreferredTitle()); |
136 | 123 |
137 for (const auto& synonym : synonyms) { | 124 for (auto& synonym : synonyms) { |
138 if (synonym == title) { | 125 Strings::NormalizeAnimeTitle(synonym); |
126 if (synonym == title_n) | |
139 return id; | 127 return id; |
140 } | |
141 } | 128 } |
142 } | 129 } |
143 | 130 |
144 return 0; | 131 return 0; |
145 } | 132 } |