comparison src/core/strings.cc @ 118:39521c47c7a3

*: another huge megacommit, SORRY The torrents page works a lot better now Added the edit option to the anime list right click menu Vectorized currently playing files Available player and extensions are now loaded at runtime from files in (dotpath)/players.json and (dotpath)/extensions.json These paths are not permanent and will likely be moved to (dotpath)/recognition ... ... ...
author Paper <mrpapersonic@gmail.com>
date Tue, 07 Nov 2023 23:40:54 -0500
parents 254b1d2b7096
children 275da698697d
comparison
equal deleted inserted replaced
117:2c1b6782e1d0 118:39521c47c7a3
25 out.append(vector.at(i)); 25 out.append(vector.at(i));
26 if (i < vector.size() - 1) 26 if (i < vector.size() - 1)
27 out.append(delimiter); 27 out.append(delimiter);
28 } 28 }
29 return out; 29 return out;
30 }
31
32 std::vector<std::string> Split(const std::string &text, const std::string& delimiter) {
33 std::vector<std::string> tokens;
34
35 std::size_t start = 0, end = 0;
36 while ((end = text.find(delimiter, start)) != std::string::npos) {
37 tokens.push_back(text.substr(start, end - start));
38 start = end + delimiter.length();
39 }
40 tokens.push_back(text.substr(start));
41
42 return tokens;
30 } 43 }
31 44
32 /* This function is really only used for cleaning up the synopsis of 45 /* This function is really only used for cleaning up the synopsis of
33 horrible HTML debris from AniList :) */ 46 horrible HTML debris from AniList :) */
34 std::string ReplaceAll(std::string string, const std::string& find, const std::string& replace) { 47 std::string ReplaceAll(std::string string, const std::string& find, const std::string& replace) {
171 return b ? "true" : "false"; 184 return b ? "true" : "false";
172 } 185 }
173 186
174 uint64_t HumanReadableSizeToBytes(const std::string& str) { 187 uint64_t HumanReadableSizeToBytes(const std::string& str) {
175 const std::unordered_map<std::string, uint64_t> bytes_map = { 188 const std::unordered_map<std::string, uint64_t> bytes_map = {
176 {"KB", 1 << 10}, 189 {"KB", 1ull << 10},
177 {"MB", 1 << 20}, 190 {"MB", 1ull << 20},
178 {"GB", 1 << 30}, 191 {"GB", 1ull << 30},
179 {"TB", 1 << 40}, 192 {"TB", 1ull << 40},
180 {"PB", 1 << 50} /* surely we won't need more than this */ 193 {"PB", 1ull << 50} /* surely we won't need more than this */
181 }; 194 };
182 195
183 for (const auto& suffix : bytes_map) { 196 for (const auto& suffix : bytes_map) {
184 if (str.find(suffix.first) != std::string::npos) { 197 if (str.find(suffix.first) != std::string::npos) {
185 try { 198 try {
193 206
194 return ToInt(str, 0); 207 return ToInt(str, 0);
195 } 208 }
196 209
197 std::string RemoveLeadingChars(std::string s, const char c) { 210 std::string RemoveLeadingChars(std::string s, const char c) {
198 s.erase(0, std::min(s.find_first_not_of(c), s.size() - 1)); 211 s.erase(0, std::min(s.find_first_not_of(c), s.size() - 1));
199 return s; 212 return s;
200 } 213 }
201 214
202 std::string RemoveTrailingChars(std::string s, const char c) { 215 std::string RemoveTrailingChars(std::string s, const char c) {
203 s.erase(s.find_last_not_of(c) + 1, std::string::npos); 216 s.erase(s.find_last_not_of(c) + 1, std::string::npos);
204 return s; 217 return s;