Mercurial > minori
comparison src/core/strings.cc @ 221:53211cb1e7f5
library: add initial library stuff
nice
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Mon, 08 Jan 2024 13:21:08 -0500 |
| parents | 7cf53145de11 |
| children | f784b5b1914c 2f5a9247e501 |
comparison
equal
deleted
inserted
replaced
| 220:79a87a6dd39d | 221:53211cb1e7f5 |
|---|---|
| 22 /* ew */ | 22 /* ew */ |
| 23 std::string Implode(const std::vector<std::string>& vector, const std::string& delimiter) { | 23 std::string Implode(const std::vector<std::string>& vector, const std::string& delimiter) { |
| 24 if (vector.size() < 1) | 24 if (vector.size() < 1) |
| 25 return "-"; | 25 return "-"; |
| 26 | 26 |
| 27 std::string out = ""; | 27 std::string out; |
| 28 | 28 |
| 29 for (unsigned long long i = 0; i < vector.size(); i++) { | 29 for (unsigned long long i = 0; i < vector.size(); i++) { |
| 30 out.append(vector.at(i)); | 30 out.append(vector.at(i)); |
| 31 if (i < vector.size() - 1) | 31 if (i < vector.size() - 1) |
| 32 out.append(delimiter); | 32 out.append(delimiter); |
| 47 | 47 |
| 48 return tokens; | 48 return tokens; |
| 49 } | 49 } |
| 50 | 50 |
| 51 /* This function is really only used for cleaning up the synopsis of | 51 /* This function is really only used for cleaning up the synopsis of |
| 52 horrible HTML debris from AniList :) */ | 52 * horrible HTML debris from AniList :) |
| 53 */ | |
| 53 std::string ReplaceAll(std::string string, const std::string& find, const std::string& replace) { | 54 std::string ReplaceAll(std::string string, const std::string& find, const std::string& replace) { |
| 54 size_t pos = 0; | 55 size_t pos = 0; |
| 55 while ((pos = string.find(find, pos)) != std::string::npos) { | 56 while ((pos = string.find(find, pos)) != std::string::npos) { |
| 56 string.replace(pos, find.length(), replace); | 57 string.replace(pos, find.length(), replace); |
| 57 pos += replace.length(); | 58 pos += replace.length(); |
| 88 | 89 |
| 89 /* e.g. "<" for "<" */ | 90 /* e.g. "<" for "<" */ |
| 90 std::string ParseHtmlEntities(std::string string) { | 91 std::string ParseHtmlEntities(std::string string) { |
| 91 const std::unordered_map<std::string, std::string> map = { | 92 const std::unordered_map<std::string, std::string> map = { |
| 92 /* The only one of these I can understand using are the first | 93 /* The only one of these I can understand using are the first |
| 93 three. why do the rest of these exist? */ | 94 * three. why do the rest of these exist? |
| 95 * | |
| 96 * probably mojibake. | |
| 97 */ | |
| 94 {"<", "<"}, | 98 {"<", "<"}, |
| 95 {"&rt;", ">"}, | 99 {"&rt;", ">"}, |
| 96 {" ", "\xA0"}, | 100 {" ", "\xA0"}, |
| 97 {"&", "&"}, | 101 {"&", "&"}, |
| 98 {""", "\""}, | 102 {""", "\""}, |
| 115 std::string TextifySynopsis(const std::string& string) { | 119 std::string TextifySynopsis(const std::string& string) { |
| 116 return ParseHtmlEntities(RemoveHtmlTags(SanitizeLineEndings(string))); | 120 return ParseHtmlEntities(RemoveHtmlTags(SanitizeLineEndings(string))); |
| 117 } | 121 } |
| 118 | 122 |
| 119 /* let Qt handle the heavy lifting of locale shit | 123 /* let Qt handle the heavy lifting of locale shit |
| 120 I don't want to deal with */ | 124 * I don't want to deal with |
| 125 */ | |
| 121 std::string ToUpper(const std::string& string) { | 126 std::string ToUpper(const std::string& string) { |
| 122 return ToUtf8String(session.config.locale.GetLocale().toUpper(ToQString(string))); | 127 return ToUtf8String(session.config.locale.GetLocale().toUpper(ToQString(string))); |
| 123 } | 128 } |
| 124 | 129 |
| 125 std::string ToLower(const std::string& string) { | 130 std::string ToLower(const std::string& string) { |
