# HG changeset patch # User Paper # Date 1699016446 14400 # Node ID 503bc1547d4937f0415682bfd268a2553429a0f2 # Parent 582b2fca1561d66fe6ca5f9430bddff62ca2fa94 strings: clarify on some functions and make some of them miniscule amounts faster diff -r 582b2fca1561 -r 503bc1547d49 src/core/strings.cc --- a/src/core/strings.cc Thu Nov 02 15:22:02 2023 -0400 +++ b/src/core/strings.cc Fri Nov 03 09:00:46 2023 -0400 @@ -14,6 +14,7 @@ namespace Strings { +/* ew */ std::string Implode(const std::vector& vector, const std::string& delimiter) { if (vector.size() < 1) return "-"; @@ -26,6 +27,8 @@ return out; } +/* 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) { @@ -35,29 +38,28 @@ return string; } -/* :) */ std::string SanitizeLineEndings(const std::string& string) { return ReplaceAll(ReplaceAll(ReplaceAll(string, "\r\n", "\n"), "
", "\n"), "\n\n\n", "\n\n"); } /* removes dumb HTML tags because anilist is aids and gives us HTML for synopses :/ */ -std::string RemoveHtmlTags(const std::string& string) { - std::string html(string); - while (html.find("<") != std::string::npos) { - auto startpos = html.find("<"); - auto endpos = html.find(">") + 1; +std::string RemoveHtmlTags(std::string string) { + while (string.find("<") != std::string::npos) { + auto startpos = string.find("<"); + auto endpos = string.find(">") + 1; - if (endpos != std::string::npos) { - html.erase(startpos, endpos - startpos); - } + if (endpos != std::string::npos) + string.erase(startpos, endpos - startpos); } - return html; + return string; } /* e.g. "<" for "<" */ -std::string ParseHtmlEntities(const std::string& string) { +std::string ParseHtmlEntities(std::string string) { const std::unordered_map map = { + /* The only one of these I can understand using are the first + three. why do the rest of these exist? */ {"<", "<"}, {"&rt;", ">"}, {" ", "\xA0"}, @@ -73,13 +75,13 @@ {"’", "’"} // Haibane Renmei, AniList }; - std::string ret = string; for (const auto& item : map) - ret = ReplaceAll(ret, item.first, item.second); - return ret; + if (string.find(item.first) != std::string::npos) + string = ReplaceAll(string, item.first, item.second); + return string; } -/* */ +/* removes stupid HTML stuff */ std::string TextifySynopsis(const std::string& string) { return ParseHtmlEntities(RemoveHtmlTags(SanitizeLineEndings(string))); } @@ -87,7 +89,9 @@ /* let Qt handle the heavy lifting of locale shit I don't want to deal with */ std::string ToUpper(const std::string& string) { - /* todo: this "locale" will have to be moved to session.h */ + /* todo: this "locale" will have to be moved to session.h + it also defaults to en-US, which sucks very much for + anyone who doesn't speak american english... */ QLocale locale; return ToUtf8String(locale.toUpper(ToQString(string))); }