Mercurial > minori
comparison src/gui/translate/anime.cc @ 187:9613d72b097e
*: multiple performance improvements
like marking `static const` when it makes sense...
date: change old stupid heap-based method to a structure which should
make copying the thing actually make a copy.
also many performance-based changes, like removing the std::tie
dependency and forward-declaring nlohmann json
*: replace every instance of QString::fromUtf8 to Strings::ToQString.
the main difference is that our function will always convert exactly
what is in the string, while some other times it would only convert
up to the nearest NUL byte
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 06 Dec 2023 13:43:54 -0500 |
parents | 62e336597bb7 |
children | 71832ffe425a |
comparison
equal
deleted
inserted
replaced
186:6ef31dbb90ca | 187:9613d72b097e |
---|---|
81 case Anime::ScoreFormat::POINT_100: return "POINT_100"; | 81 case Anime::ScoreFormat::POINT_100: return "POINT_100"; |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 Anime::ListStatus ToListStatus(const std::string& str) { | 85 Anime::ListStatus ToListStatus(const std::string& str) { |
86 const std::unordered_map<std::string, Anime::ListStatus> map = { | 86 static const std::unordered_map<std::string, Anime::ListStatus> map = { |
87 {"Currently watching", Anime::ListStatus::CURRENT}, | 87 {"Currently watching", Anime::ListStatus::CURRENT}, |
88 {"Plan to watch", Anime::ListStatus::PLANNING}, | 88 {"Plan to watch", Anime::ListStatus::PLANNING}, |
89 {"Completed", Anime::ListStatus::COMPLETED}, | 89 {"Completed", Anime::ListStatus::COMPLETED}, |
90 {"Dropped", Anime::ListStatus::DROPPED}, | 90 {"Dropped", Anime::ListStatus::DROPPED}, |
91 {"On hold", Anime::ListStatus::PAUSED} | 91 {"On hold", Anime::ListStatus::PAUSED} |
95 return Anime::ListStatus::NOT_IN_LIST; | 95 return Anime::ListStatus::NOT_IN_LIST; |
96 return map.at(str); | 96 return map.at(str); |
97 } | 97 } |
98 | 98 |
99 Anime::SeriesStatus ToSeriesStatus(const std::string& str) { | 99 Anime::SeriesStatus ToSeriesStatus(const std::string& str) { |
100 const std::unordered_map<std::string, Anime::SeriesStatus> map = { | 100 static const std::unordered_map<std::string, Anime::SeriesStatus> map = { |
101 {"Currently airing", Anime::SeriesStatus::RELEASING}, | 101 {"Currently airing", Anime::SeriesStatus::RELEASING}, |
102 {"Finished airing", Anime::SeriesStatus::FINISHED}, | 102 {"Finished airing", Anime::SeriesStatus::FINISHED}, |
103 {"Not yet aired", Anime::SeriesStatus::NOT_YET_RELEASED}, | 103 {"Not yet aired", Anime::SeriesStatus::NOT_YET_RELEASED}, |
104 {"Cancelled", Anime::SeriesStatus::CANCELLED}, | 104 {"Cancelled", Anime::SeriesStatus::CANCELLED}, |
105 {"On hiatus", Anime::SeriesStatus::HIATUS} | 105 {"On hiatus", Anime::SeriesStatus::HIATUS} |
109 return Anime::SeriesStatus::UNKNOWN; | 109 return Anime::SeriesStatus::UNKNOWN; |
110 return map.at(str); | 110 return map.at(str); |
111 } | 111 } |
112 | 112 |
113 Anime::SeriesSeason ToSeriesSeason(const std::string& str) { | 113 Anime::SeriesSeason ToSeriesSeason(const std::string& str) { |
114 const std::unordered_map<std::string, Anime::SeriesSeason> map = { | 114 static const std::unordered_map<std::string, Anime::SeriesSeason> map = { |
115 {"Winter", Anime::SeriesSeason::WINTER}, | 115 {"Winter", Anime::SeriesSeason::WINTER}, |
116 {"Summer", Anime::SeriesSeason::SUMMER}, | 116 {"Summer", Anime::SeriesSeason::SUMMER}, |
117 {"Fall", Anime::SeriesSeason::FALL}, | 117 {"Fall", Anime::SeriesSeason::FALL}, |
118 {"Spring", Anime::SeriesSeason::SPRING} | 118 {"Spring", Anime::SeriesSeason::SPRING} |
119 }; | 119 }; |
122 return Anime::SeriesSeason::UNKNOWN; | 122 return Anime::SeriesSeason::UNKNOWN; |
123 return map.at(str); | 123 return map.at(str); |
124 } | 124 } |
125 | 125 |
126 Anime::SeriesFormat ToSeriesFormat(const std::string& str) { | 126 Anime::SeriesFormat ToSeriesFormat(const std::string& str) { |
127 const std::unordered_map<std::string, Anime::SeriesFormat> map = { | 127 static const std::unordered_map<std::string, Anime::SeriesFormat> map = { |
128 {"TV", Anime::SeriesFormat::TV}, | 128 {"TV", Anime::SeriesFormat::TV}, |
129 {"TV short", Anime::SeriesFormat::TV_SHORT}, | 129 {"TV short", Anime::SeriesFormat::TV_SHORT}, |
130 {"OVA", Anime::SeriesFormat::OVA}, | 130 {"OVA", Anime::SeriesFormat::OVA}, |
131 {"Movie", Anime::SeriesFormat::MOVIE}, | 131 {"Movie", Anime::SeriesFormat::MOVIE}, |
132 {"Special", Anime::SeriesFormat::SPECIAL}, | 132 {"Special", Anime::SeriesFormat::SPECIAL}, |
138 return Anime::SeriesFormat::UNKNOWN; | 138 return Anime::SeriesFormat::UNKNOWN; |
139 return map.at(str); | 139 return map.at(str); |
140 } | 140 } |
141 | 141 |
142 Anime::Services ToService(const std::string& str) { | 142 Anime::Services ToService(const std::string& str) { |
143 const std::unordered_map<std::string, Anime::Services> map = { | 143 static const std::unordered_map<std::string, Anime::Services> map = { |
144 {"AniList", Anime::Services::ANILIST} | 144 {"AniList", Anime::Services::ANILIST} |
145 }; | 145 }; |
146 | 146 |
147 if (map.find(str) == map.end()) | 147 if (map.find(str) == map.end()) |
148 return Anime::Services::NONE; | 148 return Anime::Services::NONE; |
149 return map.at(str); | 149 return map.at(str); |
150 } | 150 } |
151 | 151 |
152 Anime::TitleLanguage ToLanguage(const std::string& str) { | 152 Anime::TitleLanguage ToLanguage(const std::string& str) { |
153 const std::unordered_map<std::string, Anime::TitleLanguage> map = { | 153 static const std::unordered_map<std::string, Anime::TitleLanguage> map = { |
154 {"Romaji", Anime::TitleLanguage::ROMAJI}, | 154 {"Romaji", Anime::TitleLanguage::ROMAJI}, |
155 {"Native", Anime::TitleLanguage::NATIVE}, | 155 {"Native", Anime::TitleLanguage::NATIVE}, |
156 {"English", Anime::TitleLanguage::ENGLISH} | 156 {"English", Anime::TitleLanguage::ENGLISH} |
157 }; | 157 }; |
158 | 158 |
160 return Anime::TitleLanguage::ROMAJI; | 160 return Anime::TitleLanguage::ROMAJI; |
161 return map.at(str); | 161 return map.at(str); |
162 } | 162 } |
163 | 163 |
164 Anime::ScoreFormat ToScoreFormat(const std::string& str) { | 164 Anime::ScoreFormat ToScoreFormat(const std::string& str) { |
165 const std::unordered_map<std::string, Anime::ScoreFormat> map = { | 165 static const std::unordered_map<std::string, Anime::ScoreFormat> map = { |
166 {"POINT_3", Anime::ScoreFormat::POINT_3}, | 166 {"POINT_3", Anime::ScoreFormat::POINT_3}, |
167 {"POINT_5", Anime::ScoreFormat::POINT_5}, | 167 {"POINT_5", Anime::ScoreFormat::POINT_5}, |
168 {"POINT_10", Anime::ScoreFormat::POINT_10}, | 168 {"POINT_10", Anime::ScoreFormat::POINT_10}, |
169 {"POINT_10_DECIMAL", Anime::ScoreFormat::POINT_10_DECIMAL}, | 169 {"POINT_10_DECIMAL", Anime::ScoreFormat::POINT_10_DECIMAL}, |
170 {"POINT_100", Anime::ScoreFormat::POINT_100} | 170 {"POINT_100", Anime::ScoreFormat::POINT_100} |
173 if (map.find(str) == map.end()) | 173 if (map.find(str) == map.end()) |
174 return Anime::ScoreFormat::POINT_100; | 174 return Anime::ScoreFormat::POINT_100; |
175 return map.at(str); | 175 return map.at(str); |
176 } | 176 } |
177 | 177 |
178 /* Localized versions of ToString() functions */ | 178 /* Localized versions of ToString() functions. Meant for display to the user. */ |
179 | 179 |
180 std::string ToLocalString(const Anime::ListStatus status) { | 180 std::string ToLocalString(const Anime::ListStatus status) { |
181 switch (status) { | 181 switch (status) { |
182 case Anime::ListStatus::CURRENT: return Strings::ToUtf8String(QCoreApplication::tr("Currently watching")); | 182 case Anime::ListStatus::CURRENT: return Strings::ToUtf8String(QCoreApplication::tr("Currently watching")); |
183 case Anime::ListStatus::PLANNING: return Strings::ToUtf8String(QCoreApplication::tr("Plan to watch")); | 183 case Anime::ListStatus::PLANNING: return Strings::ToUtf8String(QCoreApplication::tr("Plan to watch")); |
241 default: | 241 default: |
242 case Anime::TitleLanguage::ROMAJI: return Strings::ToUtf8String(QCoreApplication::tr("Romaji")); | 242 case Anime::TitleLanguage::ROMAJI: return Strings::ToUtf8String(QCoreApplication::tr("Romaji")); |
243 } | 243 } |
244 } | 244 } |
245 | 245 |
246 std::string ToLocalString(const Anime::ScoreFormat format) { | |
247 switch (format) { | |
248 case Anime::ScoreFormat::POINT_3: return Strings::ToUtf8String(QCoreApplication::tr("3-point")); | |
249 case Anime::ScoreFormat::POINT_5: return Strings::ToUtf8String(QCoreApplication::tr("5-point")); | |
250 case Anime::ScoreFormat::POINT_10: return Strings::ToUtf8String(QCoreApplication::tr("10-point")); | |
251 case Anime::ScoreFormat::POINT_10_DECIMAL: return Strings::ToUtf8String(QCoreApplication::tr("10-point (Decimal)")); | |
252 default: | |
253 case Anime::ScoreFormat::POINT_100: return Strings::ToUtf8String(QCoreApplication::tr("100-point")); | |
254 } | |
255 } | |
256 | |
246 } // namespace Translate | 257 } // namespace Translate |