annotate include/core/strings.h @ 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 f784b5b1914c
children dd211ff68b36
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #ifndef __core__strings_h
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2 #define __core__strings_h
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
3
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 226
diff changeset
4 #include <set>
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 226
diff changeset
5 #include <sstream>
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 #include <string>
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
7 #include <vector>
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
8
218
c39ad2a8587d strings: include cstdint
Paper <mrpapersonic@gmail.com>
parents: 211
diff changeset
9 #include <cstdint>
c39ad2a8587d strings: include cstdint
Paper <mrpapersonic@gmail.com>
parents: 211
diff changeset
10
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
11 class QString;
116
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
12 class QByteArray;
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
13
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
14 namespace Strings {
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
15
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 /* Implode function: takes a vector of strings and turns it
211
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
17 * into a string, separated by delimiters.
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 226
diff changeset
18 */
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19 std::string Implode(const std::vector<std::string>& vector, const std::string& delimiter);
226
f784b5b1914c settings: add library page
Paper <mrpapersonic@gmail.com>
parents: 218
diff changeset
20 std::string Implode(const std::set<std::string>& set, const std::string& delimiter);
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 226
diff changeset
21 std::vector<std::string> Split(const std::string& text, const std::string& delimiter);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23 /* Substring removal functions */
98
582b2fca1561 strings: parse HTML entities when reading synopsis, make the
Paper <mrpapersonic@gmail.com>
parents: 85
diff changeset
24 std::string ReplaceAll(std::string string, const std::string& find, const std::string& replace);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25 std::string SanitizeLineEndings(const std::string& string);
100
f5940a575d83 track/constants: add many more video formats
Paper <mrpapersonic@gmail.com>
parents: 98
diff changeset
26 std::string RemoveHtmlTags(std::string string);
f5940a575d83 track/constants: add many more video formats
Paper <mrpapersonic@gmail.com>
parents: 98
diff changeset
27 std::string ParseHtmlEntities(std::string string);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
29 /* stupid HTML bullshit */
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
30 std::string TextifySynopsis(const std::string& string);
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
31
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
32 std::string ToUpper(const std::string& string);
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
33 std::string ToLower(const std::string& string);
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
34
98
582b2fca1561 strings: parse HTML entities when reading synopsis, make the
Paper <mrpapersonic@gmail.com>
parents: 85
diff changeset
35 /* functions that make the way we convert from and to
211
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
36 * different string formats universal (and these functions
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
37 * typically do things the right way so we avoid retarded
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
38 * code)
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 226
diff changeset
39 */
62
4c6dd5999b39 *: update
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
40 std::wstring ToWstring(const std::string& string);
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
41 std::wstring ToWstring(const QString& string);
62
4c6dd5999b39 *: update
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
42 std::string ToUtf8String(const std::wstring& wstring);
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
43 std::string ToUtf8String(const QString& string);
116
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
44 std::string ToUtf8String(const QByteArray& ba);
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
45 QString ToQString(const std::string& string);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
46 QString ToQString(const std::wstring& wstring);
62
4c6dd5999b39 *: update
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
47
211
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
48 /* not really an "int"... but who cares? */
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 226
diff changeset
49 template<typename T = int, std::enable_if_t<std::is_integral<T>::value, bool> = true>
122
bc218c9d2ea6 strings: convert ToInt() to be a template
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
50 T ToInt(const std::string& str, T def = 0) {
211
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
51 std::istringstream s(str);
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
52 s >> std::noboolalpha >> def;
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
53 return def;
122
bc218c9d2ea6 strings: convert ToInt() to be a template
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
54 }
101
c537996cf67b *: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents: 100
diff changeset
55
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 226
diff changeset
56 template<typename T, std::enable_if_t<std::is_integral<T>::value && !std::is_same<T, bool>::value, bool> = true>
211
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
57 std::string ToUtf8String(T i) {
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
58 std::ostringstream s;
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
59 s << i;
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
60 return s.str();
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
61 }
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
62
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
63 bool ToBool(const std::string& s, bool def);
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
64
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
65 std::string ToUtf8String(bool b);
116
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
66
114
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
67 uint64_t HumanReadableSizeToBytes(const std::string& str);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
68
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
69 std::string RemoveLeadingChars(std::string s, const char c);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
70 std::string RemoveTrailingChars(std::string s, const char c);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
71
102
b315f3759c56 *: big patch
Paper <mrpapersonic@gmail.com>
parents: 101
diff changeset
72 bool BeginningMatchesSubstring(const std::string& str, const std::string& sub);
b315f3759c56 *: big patch
Paper <mrpapersonic@gmail.com>
parents: 101
diff changeset
73
85
c69230dc2b5d *: cleanup includes
Paper <mrpapersonic@gmail.com>
parents: 64
diff changeset
74 }; // namespace Strings
c69230dc2b5d *: cleanup includes
Paper <mrpapersonic@gmail.com>
parents: 64
diff changeset
75
211
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
76 #endif // __core__strings_h