Mercurial > minori
diff src/core/strings.cc @ 114:ab191e28e69d
*: add initial torrent stuff
WOAH!
these checkboxes are a pain in my fucking ass
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 07 Nov 2023 08:03:42 -0500 |
parents | b315f3759c56 |
children | 254b1d2b7096 |
line wrap: on
line diff
--- a/src/core/strings.cc Mon Nov 06 13:48:11 2023 -0500 +++ b/src/core/strings.cc Tue Nov 07 08:03:42 2023 -0500 @@ -41,7 +41,17 @@ } std::string SanitizeLineEndings(const std::string& string) { - return ReplaceAll(ReplaceAll(ReplaceAll(string, "\r\n", "\n"), "<br>", "\n"), "\n\n\n", "\n\n"); + /* LOL */ + return + ReplaceAll( + ReplaceAll( + ReplaceAll( + ReplaceAll( + ReplaceAll(string, "\r\n", "\n"), + "</p>", "\n"), + "<br>", "\n"), + "<br />", "\n"), + "\n\n\n", "\n\n"); } /* removes dumb HTML tags because anilist is aids and @@ -146,6 +156,39 @@ return tmp; } +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 */ + }; + + for (const auto& suffix : bytes_map) { + if (str.find(suffix.first) != std::string::npos) { + try { + uint64_t size = std::stod(str) * suffix.second; + return size; + } catch (std::invalid_argument const& ex) { + continue; + } + } + } + + return ToInt(str, 0); +} + +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; +} + +std::string RemoveTrailingChars(std::string s, const char c) { + s.erase(s.find_last_not_of(c) + 1, std::string::npos); + return s; +} + bool BeginningMatchesSubstring(const std::string& str, const std::string& sub) { for (unsigned long long i = 0; i < str.length() && i < sub.length(); i++) if (str[i] != sub[i])