diff 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
line wrap: on
line diff
--- a/src/core/strings.cc	Tue Nov 07 16:06:17 2023 -0500
+++ b/src/core/strings.cc	Tue Nov 07 23:40:54 2023 -0500
@@ -29,6 +29,19 @@
 	return out;
 }
 
+std::vector<std::string> Split(const std::string &text, const std::string& delimiter) {
+	std::vector<std::string> tokens;
+
+	std::size_t start = 0, end = 0;
+	while ((end = text.find(delimiter, start)) != std::string::npos) {
+		tokens.push_back(text.substr(start, end - start));
+		start = end + delimiter.length();
+	}
+	tokens.push_back(text.substr(start));
+
+	return tokens;
+}
+
 /* This function is really only used for cleaning up the synopsis of
    horrible HTML debris from AniList :) */
 std::string ReplaceAll(std::string string, const std::string& find, const std::string& replace) {
@@ -173,11 +186,11 @@
 
 uint64_t HumanReadableSizeToBytes(const std::string& str) {
 	const std::unordered_map<std::string, uint64_t> bytes_map = {
-		{"KB", 1 << 10},
-		{"MB", 1 << 20},
-		{"GB", 1 << 30},
-		{"TB", 1 << 40},
-		{"PB", 1 << 50} /* surely we won't need more than this */
+		{"KB", 1ull << 10},
+		{"MB", 1ull << 20},
+		{"GB", 1ull << 30},
+		{"TB", 1ull << 40},
+		{"PB", 1ull << 50} /* surely we won't need more than this */
 	};
 
 	for (const auto& suffix : bytes_map) {
@@ -195,8 +208,8 @@
 }
 
 std::string RemoveLeadingChars(std::string s, const char c) {
-    s.erase(0, std::min(s.find_first_not_of(c), s.size() - 1));
-    return s;
+	s.erase(0, std::min(s.find_first_not_of(c), s.size() - 1));
+	return s;
 }
 
 std::string RemoveTrailingChars(std::string s, const char c) {