annotate include/core/strings.h @ 406:31ce85df55a8 default tip

filesystem: add mac os x directory watcher this code is incredibly stinky tbh we should probably be using C++ threads everywhere else just because they are SO much easier to code for than the shitty Qt threads API
author Paper <paper@tflc.us>
date Mon, 19 Jan 2026 22:48:56 -0500
parents 4562bc8bfdff
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
261
3ec7804abf17 include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
1 #ifndef MINORI_CORE_STRINGS_H_
3ec7804abf17 include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
2 #define MINORI_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
405
4562bc8bfdff strings: add conversion to/from CFString on Mac OS X
Paper <paper@tflc.us>
parents: 403
diff changeset
11 #if defined(__MACH__) && defined(__APPLE__)
4562bc8bfdff strings: add conversion to/from CFString on Mac OS X
Paper <paper@tflc.us>
parents: 403
diff changeset
12 # include <CoreFoundation/CoreFoundation.h>
4562bc8bfdff strings: add conversion to/from CFString on Mac OS X
Paper <paper@tflc.us>
parents: 403
diff changeset
13 #endif
4562bc8bfdff strings: add conversion to/from CFString on Mac OS X
Paper <paper@tflc.us>
parents: 403
diff changeset
14
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
15 class QString;
116
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
16 class QByteArray;
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
17
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
18 namespace Strings {
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
19
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 /* 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
21 * into a string, separated by delimiters.
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 226
diff changeset
22 */
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
23 std::string Implode(const std::vector<std::string> &vector, const std::string &delimiter);
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
24 std::vector<std::string> Split(const std::string &text, const std::string &delimiter);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26 /* Substring removal functions */
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
27 void ReplaceAll(std::string &string, std::string_view find, std::string_view replace);
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
28 void NormalizeUnicode(std::string &string);
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
29 void NormalizeAnimeTitle(std::string &string);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
30
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31 /* stupid HTML bullshit */
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
32 void TextifySynopsis(std::string &string);
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
33
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
34 std::string ToUpper(const std::string &string);
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
35 std::string ToLower(const std::string &string);
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
36
98
582b2fca1561 strings: parse HTML entities when reading synopsis, make the
Paper <mrpapersonic@gmail.com>
parents: 85
diff changeset
37 /* 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
38 * 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
39 * 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
40 * code)
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 226
diff changeset
41 */
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
42 std::wstring ToWstring(const std::string &string);
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
43 std::wstring ToWstring(const QString &string);
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
44 std::string ToUtf8String(const std::wstring &wstring);
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
45 std::string ToUtf8String(const QString &string);
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
46 std::string ToUtf8String(const QByteArray &ba);
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
47 std::string ToUtf8String(const std::u32string &u32string);
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
48 std::u32string ToUcs4String(const std::string &string);
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
49 QString ToQString(const std::string &string);
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
50 QString ToQString(const std::wstring &wstring);
405
4562bc8bfdff strings: add conversion to/from CFString on Mac OS X
Paper <paper@tflc.us>
parents: 403
diff changeset
51 #if defined(__APPLE__) && defined(__MACH__)
4562bc8bfdff strings: add conversion to/from CFString on Mac OS X
Paper <paper@tflc.us>
parents: 403
diff changeset
52 CFStringRef ToCFString(const std::string &string);
4562bc8bfdff strings: add conversion to/from CFString on Mac OS X
Paper <paper@tflc.us>
parents: 403
diff changeset
53 std::string ToUtf8String(CFStringRef str);
4562bc8bfdff strings: add conversion to/from CFString on Mac OS X
Paper <paper@tflc.us>
parents: 403
diff changeset
54 #endif
62
4c6dd5999b39 *: update
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
55
211
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
56 /* not really an "int"... but who cares? */
320
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 273
diff changeset
57 template<typename T = int, std::enable_if_t<std::is_arithmetic<T>::value, bool> = true>
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
58 T ToInt(const std::string &str, T def = 0)
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
59 {
211
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
60 std::istringstream s(str);
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
61 s >> std::noboolalpha >> def;
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
62 return def;
122
bc218c9d2ea6 strings: convert ToInt() to be a template
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
63 }
101
c537996cf67b *: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents: 100
diff changeset
64
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
65 template<typename T, std::enable_if_t<std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, bool> = true>
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
66 std::string ToUtf8String(T i)
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
67 {
211
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
68 std::ostringstream s;
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 347
diff changeset
69 s << std::noboolalpha << i;
211
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
70 return s.str();
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
71 }
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
72
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
73 bool ToBool(const std::string &s, bool def);
211
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
74
7cf53145de11 strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
75 std::string ToUtf8String(bool b);
116
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
76
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
77 uint64_t HumanReadableSizeToBytes(const std::string &str);
273
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 264
diff changeset
78 std::string BytesToHumanReadableSize(uint64_t bytes, int precision = 2);
114
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
79
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
80 void RemoveLeadingChars(std::string &s, const char c);
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
81 void RemoveTrailingChars(std::string &s, const char c);
114
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
82
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
83 bool BeginningMatchesSubstring(const std::string &str, const std::string &sub);
102
b315f3759c56 *: big patch
Paper <mrpapersonic@gmail.com>
parents: 101
diff changeset
84
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 348
diff changeset
85 std::string Translate(const char *str);
322
c32467cd06bb core/strings: add Strings::Translate function as tr() -> ToUtf8String
Paper <paper@paper.us.eu.org>
parents: 320
diff changeset
86
403
df4a027623d0 x11: fix build fail when glib is not detected
Paper <paper@tflc.us>
parents: 369
diff changeset
87 /* hehehe */
df4a027623d0 x11: fix build fail when glib is not detected
Paper <paper@tflc.us>
parents: 369
diff changeset
88 bool IsGTKThemeDark(const std::string_view str);
df4a027623d0 x11: fix build fail when glib is not detected
Paper <paper@tflc.us>
parents: 369
diff changeset
89
85
c69230dc2b5d *: cleanup includes
Paper <mrpapersonic@gmail.com>
parents: 64
diff changeset
90 }; // namespace Strings
c69230dc2b5d *: cleanup includes
Paper <mrpapersonic@gmail.com>
parents: 64
diff changeset
91
261
3ec7804abf17 include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
92 #endif // MINORI_CORE_STRINGS_H_