comparison 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
comparison
equal deleted inserted replaced
257:699a20c57dc8 258:862d0d8619f6
1 #ifndef __core__strings_h 1 #ifndef __core__strings_h
2 #define __core__strings_h 2 #define __core__strings_h
3 3
4 #include <set>
5 #include <sstream>
4 #include <string> 6 #include <string>
5 #include <vector> 7 #include <vector>
6 #include <set>
7 #include <sstream>
8 8
9 #include <cstdint> 9 #include <cstdint>
10 10
11 class QString; 11 class QString;
12 class QByteArray; 12 class QByteArray;
13 13
14 namespace Strings { 14 namespace Strings {
15 15
16 /* Implode function: takes a vector of strings and turns it 16 /* Implode function: takes a vector of strings and turns it
17 * into a string, separated by delimiters. 17 * into a string, separated by delimiters.
18 */ 18 */
19 std::string Implode(const std::vector<std::string>& vector, const std::string& delimiter); 19 std::string Implode(const std::vector<std::string>& vector, const std::string& delimiter);
20 std::string Implode(const std::set<std::string>& set, const std::string& delimiter); 20 std::string Implode(const std::set<std::string>& set, const std::string& delimiter);
21 std::vector<std::string> Split(const std::string &text, const std::string& delimiter); 21 std::vector<std::string> Split(const std::string& text, const std::string& delimiter);
22 22
23 /* Substring removal functions */ 23 /* Substring removal functions */
24 std::string ReplaceAll(std::string string, const std::string& find, const std::string& replace); 24 std::string ReplaceAll(std::string string, const std::string& find, const std::string& replace);
25 std::string SanitizeLineEndings(const std::string& string); 25 std::string SanitizeLineEndings(const std::string& string);
26 std::string RemoveHtmlTags(std::string string); 26 std::string RemoveHtmlTags(std::string string);
34 34
35 /* functions that make the way we convert from and to 35 /* functions that make the way we convert from and to
36 * different string formats universal (and these functions 36 * different string formats universal (and these functions
37 * typically do things the right way so we avoid retarded 37 * typically do things the right way so we avoid retarded
38 * code) 38 * code)
39 */ 39 */
40 std::wstring ToWstring(const std::string& string); 40 std::wstring ToWstring(const std::string& string);
41 std::wstring ToWstring(const QString& string); 41 std::wstring ToWstring(const QString& string);
42 std::string ToUtf8String(const std::wstring& wstring); 42 std::string ToUtf8String(const std::wstring& wstring);
43 std::string ToUtf8String(const QString& string); 43 std::string ToUtf8String(const QString& string);
44 std::string ToUtf8String(const QByteArray& ba); 44 std::string ToUtf8String(const QByteArray& ba);
45 QString ToQString(const std::string& string); 45 QString ToQString(const std::string& string);
46 QString ToQString(const std::wstring& wstring); 46 QString ToQString(const std::wstring& wstring);
47 47
48 /* not really an "int"... but who cares? */ 48 /* not really an "int"... but who cares? */
49 template<typename T = int, 49 template<typename T = int, std::enable_if_t<std::is_integral<T>::value, bool> = true>
50 std::enable_if_t<std::is_integral<T>::value, bool> = true>
51 T ToInt(const std::string& str, T def = 0) { 50 T ToInt(const std::string& str, T def = 0) {
52 std::istringstream s(str); 51 std::istringstream s(str);
53 s >> std::noboolalpha >> def; 52 s >> std::noboolalpha >> def;
54 return def; 53 return def;
55 } 54 }
56 55
57 template<typename T, 56 template<typename T, std::enable_if_t<std::is_integral<T>::value && !std::is_same<T, bool>::value, bool> = true>
58 std::enable_if_t<std::is_integral<T>::value && !std::is_same<T, bool>::value, bool> = true>
59 std::string ToUtf8String(T i) { 57 std::string ToUtf8String(T i) {
60 std::ostringstream s; 58 std::ostringstream s;
61 s << i; 59 s << i;
62 return s.str(); 60 return s.str();
63 } 61 }