Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 113:32afe0e940bf | 114:ab191e28e69d |
|---|---|
| 39 } | 39 } |
| 40 return string; | 40 return string; |
| 41 } | 41 } |
| 42 | 42 |
| 43 std::string SanitizeLineEndings(const std::string& string) { | 43 std::string SanitizeLineEndings(const std::string& string) { |
| 44 return ReplaceAll(ReplaceAll(ReplaceAll(string, "\r\n", "\n"), "<br>", "\n"), "\n\n\n", "\n\n"); | 44 /* LOL */ |
| 45 return | |
| 46 ReplaceAll( | |
| 47 ReplaceAll( | |
| 48 ReplaceAll( | |
| 49 ReplaceAll( | |
| 50 ReplaceAll(string, "\r\n", "\n"), | |
| 51 "</p>", "\n"), | |
| 52 "<br>", "\n"), | |
| 53 "<br />", "\n"), | |
| 54 "\n\n\n", "\n\n"); | |
| 45 } | 55 } |
| 46 | 56 |
| 47 /* removes dumb HTML tags because anilist is aids and | 57 /* removes dumb HTML tags because anilist is aids and |
| 48 gives us HTML for synopses :/ */ | 58 gives us HTML for synopses :/ */ |
| 49 std::string RemoveHtmlTags(std::string string) { | 59 std::string RemoveHtmlTags(std::string string) { |
| 144 tmp = def; | 154 tmp = def; |
| 145 } | 155 } |
| 146 return tmp; | 156 return tmp; |
| 147 } | 157 } |
| 148 | 158 |
| 159 uint64_t HumanReadableSizeToBytes(const std::string& str) { | |
| 160 const std::unordered_map<std::string, uint64_t> bytes_map = { | |
| 161 {"KB", 1 << 10}, | |
| 162 {"MB", 1 << 20}, | |
| 163 {"GB", 1 << 30}, | |
| 164 {"TB", 1 << 40}, | |
| 165 {"PB", 1 << 50} /* surely we won't need more than this */ | |
| 166 }; | |
| 167 | |
| 168 for (const auto& suffix : bytes_map) { | |
| 169 if (str.find(suffix.first) != std::string::npos) { | |
| 170 try { | |
| 171 uint64_t size = std::stod(str) * suffix.second; | |
| 172 return size; | |
| 173 } catch (std::invalid_argument const& ex) { | |
| 174 continue; | |
| 175 } | |
| 176 } | |
| 177 } | |
| 178 | |
| 179 return ToInt(str, 0); | |
| 180 } | |
| 181 | |
| 182 std::string RemoveLeadingChars(std::string s, const char c) { | |
| 183 s.erase(0, std::min(s.find_first_not_of(c), s.size() - 1)); | |
| 184 return s; | |
| 185 } | |
| 186 | |
| 187 std::string RemoveTrailingChars(std::string s, const char c) { | |
| 188 s.erase(s.find_last_not_of(c) + 1, std::string::npos); | |
| 189 return s; | |
| 190 } | |
| 191 | |
| 149 bool BeginningMatchesSubstring(const std::string& str, const std::string& sub) { | 192 bool BeginningMatchesSubstring(const std::string& str, const std::string& sub) { |
| 150 for (unsigned long long i = 0; i < str.length() && i < sub.length(); i++) | 193 for (unsigned long long i = 0; i < str.length() && i < sub.length(); i++) |
| 151 if (str[i] != sub[i]) | 194 if (str[i] != sub[i]) |
| 152 return false; | 195 return false; |
| 153 return true; | 196 return true; |
