diff src/core/strings.cc @ 365:f81bed4e04ac

*: megacommit that probably breaks things
author Paper <paper@paper.us.eu.org>
date Wed, 02 Oct 2024 23:06:43 -0400
parents a0aa8c8c4307
children
line wrap: on
line diff
--- a/src/core/strings.cc	Tue Jul 16 21:15:59 2024 -0400
+++ b/src/core/strings.cc	Wed Oct 02 23:06:43 2024 -0400
@@ -82,9 +82,9 @@
 /* this also performs case folding, so our string is lowercase after this */
 void NormalizeUnicode(std::string& string) {
 	static constexpr utf8proc_option_t options = static_cast<utf8proc_option_t>(
-		UTF8PROC_COMPAT | UTF8PROC_COMPOSE | UTF8PROC_STABLE |
-		UTF8PROC_IGNORE | UTF8PROC_STRIPCC | UTF8PROC_STRIPMARK |
-		UTF8PROC_LUMP | UTF8PROC_CASEFOLD | UTF8PROC_NLF2LS
+		UTF8PROC_COMPAT | UTF8PROC_COMPOSE  | UTF8PROC_STABLE |
+		UTF8PROC_IGNORE | UTF8PROC_STRIPCC  | UTF8PROC_STRIPMARK |
+		UTF8PROC_LUMP   | UTF8PROC_CASEFOLD | UTF8PROC_NLF2LS
 	);
 
 	/* ack */
@@ -97,11 +97,12 @@
 		options
 	);
 
-	if (size)
-		string = std::string(reinterpret_cast<const char*>(buf), size);
+	if (buf) {
+		if (size)
+			string.assign(reinterpret_cast<const char*>(buf), size);
 
-	if (buf)
-		free(buf);
+		std::free(buf);
+	}
 }
 
 void NormalizeAnimeTitle(std::string& string) {
@@ -190,14 +191,20 @@
 	return def;
 }
 
+template<typename T>
+constexpr T ipow(T num, unsigned int pow) {
+    return (pow >= sizeof(unsigned int)*8) ? 0 :
+        pow == 0 ? 1 : num * ipow(num, pow-1);
+}
+
 /* util funcs */
 uint64_t HumanReadableSizeToBytes(const std::string& str) {
 	static const std::unordered_map<std::string, uint64_t> bytes_map = {
-		{"KB", 1000ull},
-		{"MB", 1000000ull},
-		{"GB", 1000000000ull},
-		{"TB", 1000000000000ull},
-		{"PB", 1000000000000000ull},
+		{"KB",  1e3},
+		{"MB",  1e6},
+		{"GB",  1e9},
+		{"TB",  1e12},
+		{"PB",  1e15},
 	    {"KiB", 1ull << 10},
 	    {"MiB", 1ull << 20},
 	    {"GiB", 1ull << 30},