Mercurial > minori
comparison src/core/anime_db.cc @ 198:bc1ae1810855
dep/animia: switch from using classes to global functions
the old idea was ok, but sort of hackish; this method doesn't use classes
at all, and this way (especially important!) we can do wayland stuff AND x11
at the same time, which wasn't really possible without stupid workarounds in
the other method
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 24 Dec 2023 02:59:42 -0500 |
parents | c4ca035c565d |
children | 4d461ef7d424 |
comparison
equal
deleted
inserted
replaced
197:c4ca035c565d | 198:bc1ae1810855 |
---|---|
120 } | 120 } |
121 } | 121 } |
122 return id; | 122 return id; |
123 } | 123 } |
124 | 124 |
125 /* This is really fugly but WHO CARES :P | 125 /* |
126 | 126 * This fairly basic algorithm is only in effect because |
127 This fairly basic algorithm is only in effect because | 127 * there are some special cases, e.g. Another and Re:ZERO, where |
128 there are some special cases, e.g. Another and Re:ZERO, where | 128 * we get the wrong match, so we have to create Advanced Techniques |
129 we get the wrong match, so we have to create Advanced Techniques | 129 * to solve this |
130 to solve this | 130 * |
131 | 131 * This algorithm: |
132 This algorithm: | 132 * 1. searches each anime item for a match to the preferred title |
133 1. searches each anime item for a match to the preferred title | 133 * AND all synonyms and marks those matches with |
134 AND all synonyms and marks those matches with | 134 * `synonym.length() - (synonym.find(needle) + needle.length());` |
135 `synonym.length() - (synonym.find(needle) + needle.length());` | 135 * which should never be less than zero and will be zero if, and only if |
136 which should never be less than zero and will be zero if, and only if | 136 * the titles match exactly. |
137 the titles match exactly. | 137 * 2. returns the id of the match that is the lowest, which will most |
138 2. returns the id of the match that is the lowest, which will most | 138 * definitely match anything that exactly matches the title of the |
139 definitely match anything that exactly matches the title of the | 139 * filename |
140 filename */ | 140 */ |
141 int Database::GetAnimeFromTitle(const std::string& title) { | 141 int Database::GetAnimeFromTitle(const std::string& title) { |
142 if (title.empty()) | 142 if (title.empty()) |
143 return 0; | 143 return 0; |
144 | 144 |
145 std::unordered_map<int, size_t> map; | 145 std::unordered_map<int, size_t> map; |
146 | 146 |
147 auto process_title = [&map](const Anime& anime, const std::string& title, const std::string& needle) -> bool { | 147 static const auto process_title = [&map](const Anime& anime, const std::string& title, const std::string& needle) -> bool { |
148 size_t ret = title.find(needle); | 148 size_t ret = title.find(needle); |
149 if (ret == std::string::npos) | 149 if (ret == std::string::npos) |
150 return false; | 150 return false; |
151 | 151 |
152 map[anime.GetId()] = title.length() - (ret + needle.length()); | 152 map[anime.GetId()] = title.length() - (ret + needle.length()); |