diff src/core/strings.cc @ 258:862d0d8619f6

*: HUUUGE changes animia has been renamed to animone, so instead of thinking of a health condition, you think of a beautiful flower :) I've also edited some of the code for animone, but I have no idea if it even works or not because I don't have a mac or windows machine lying around. whoops! ... anyway, all of the changes divergent from Anisthesia are now licensed under BSD. it's possible that I could even rewrite most of the code to where I don't even have to keep the MIT license, but that's thinking too far into the future I've been slacking off on implementing the anime seasons page, mostly out of laziness. I think I'd have to create another db file specifically for the seasons anyway, this code is being pushed *primarily* because the hard drive it's on is failing! yay :)
author Paper <paper@paper.us.eu.org>
date Mon, 01 Apr 2024 02:43:44 -0400
parents c130f47f6f48
children dd211ff68b36
line wrap: on
line diff
--- a/src/core/strings.cc	Sun Feb 18 16:02:14 2024 -0500
+++ b/src/core/strings.cc	Mon Apr 01 02:43:44 2024 -0400
@@ -6,17 +6,17 @@
 
 #include <QByteArray>
 #include <QDebug>
+#include <QLocale>
 #include <QString>
-#include <QLocale>
 
 #include <algorithm>
 #include <cctype>
 #include <codecvt>
+#include <iostream>
 #include <locale>
 #include <string>
+#include <unordered_map>
 #include <vector>
-#include <unordered_map>
-#include <iostream>
 
 namespace Strings {
 
@@ -51,7 +51,7 @@
 	return out;
 }
 
-std::vector<std::string> Split(const std::string &text, const std::string& delimiter) {
+std::vector<std::string> Split(const std::string& text, const std::string& delimiter) {
 	if (text.length() < 1)
 		return {};
 
@@ -69,7 +69,7 @@
 
 /* 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) {
 	size_t pos = 0;
 	while ((pos = string.find(find, pos)) != std::string::npos) {
@@ -81,21 +81,14 @@
 
 std::string SanitizeLineEndings(const std::string& string) {
 	/* LOL */
-	return
-		ReplaceAll(
-			ReplaceAll(
-				ReplaceAll(
-					ReplaceAll(
-						ReplaceAll(string, "\r\n", "\n"),
-					"</p>", "\n"),
-				"<br>", "\n"),
-			"<br />", "\n"),
-		"\n\n\n", "\n\n");
+	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
  * gives us HTML for synopses :/
-*/
+ */
 std::string RemoveHtmlTags(std::string string) {
 	while (string.find("<") != std::string::npos) {
 		auto startpos = string.find("<");
@@ -110,24 +103,24 @@
 /* e.g. "&lt;" for "<" */
 std::string ParseHtmlEntities(std::string string) {
 	const std::unordered_map<std::string, std::string> map = {
-		/* The only one of these I can understand using are the first
-		 * three. why do the rest of these exist?
-		 *
-		 * probably mojibake.
-		*/
-		{"&lt;", "<"},
-		{"&rt;", ">"},
-		{"&nbsp;", "\xA0"},
-		{"&amp;", "&"},
-		{"&quot;", "\""},
-		{"&apos;", "'"},
-		{"&cent;", "¢"},
-		{"&pound;", "£"},
-		{"&euro;", "€"},
-		{"&yen;", "¥"},
-		{"&copy;", "©"},
-		{"&reg;", "®"},
-		{"&rsquo;", "’"} // Haibane Renmei, AniList
+  /* The only one of these I can understand using are the first
+  * three. why do the rest of these exist?
+  *
+  * probably mojibake.
+  */
+	    {"&lt;",    "<"   },
+        {"&rt;",    ">"   },
+        {"&nbsp;",  "\xA0"},
+        {"&amp;",   "&"   },
+        {"&quot;",  "\""  },
+	    {"&apos;",  "'"   },
+        {"&cent;",  "¢"  },
+        {"&pound;", "£"  },
+        {"&euro;",  "€" },
+        {"&yen;",   "¥"  },
+	    {"&copy;",  "©"  },
+        {"&reg;",   "®"  },
+        {"&rsquo;", "’" }  // Haibane Renmei, AniList
 	};
 
 	for (const auto& item : map)
@@ -142,7 +135,7 @@
 
 /* let Qt handle the heavy lifting of locale shit
  * I don't want to deal with
-*/
+ */
 std::string ToUpper(const std::string& string) {
 	return ToUtf8String(session.config.locale.GetLocale().toUpper(ToQString(string)));
 }
@@ -204,11 +197,11 @@
 /* util funcs */
 uint64_t HumanReadableSizeToBytes(const std::string& str) {
 	static const std::unordered_map<std::string, uint64_t> bytes_map = {
-		{"KB", 1ull << 10},
-		{"MB", 1ull << 20},
-		{"GB", 1ull << 30},
-		{"TB", 1ull << 40},
-		{"PB", 1ull << 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) {