Mercurial > minori
comparison include/core/strings.h @ 369:47c9f8502269
*: clang-format all the things
I've edited the formatting a bit. Now pointer asterisks (and reference
ampersands) are on the variable instead of the type, as well as having
newlines for function braces (but nothing else)
| author | Paper <paper@tflc.us> |
|---|---|
| date | Fri, 25 Jul 2025 10:16:02 -0400 |
| parents | 6b0768158dcd |
| children |
comparison
equal
deleted
inserted
replaced
| 368:6d37a998cf91 | 369:47c9f8502269 |
|---|---|
| 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::vector<std::string> Split(const std::string& text, const std::string& delimiter); | 20 std::vector<std::string> Split(const std::string &text, const std::string &delimiter); |
| 21 | 21 |
| 22 /* Substring removal functions */ | 22 /* Substring removal functions */ |
| 23 void ReplaceAll(std::string& string, std::string_view find, std::string_view replace); | 23 void ReplaceAll(std::string &string, std::string_view find, std::string_view replace); |
| 24 void NormalizeUnicode(std::string& string); | 24 void NormalizeUnicode(std::string &string); |
| 25 void NormalizeAnimeTitle(std::string& string); | 25 void NormalizeAnimeTitle(std::string &string); |
| 26 | 26 |
| 27 /* stupid HTML bullshit */ | 27 /* stupid HTML bullshit */ |
| 28 void TextifySynopsis(std::string& string); | 28 void TextifySynopsis(std::string &string); |
| 29 | 29 |
| 30 std::string ToUpper(const std::string& string); | 30 std::string ToUpper(const std::string &string); |
| 31 std::string ToLower(const std::string& string); | 31 std::string ToLower(const std::string &string); |
| 32 | 32 |
| 33 /* functions that make the way we convert from and to | 33 /* functions that make the way we convert from and to |
| 34 * different string formats universal (and these functions | 34 * different string formats universal (and these functions |
| 35 * typically do things the right way so we avoid retarded | 35 * typically do things the right way so we avoid retarded |
| 36 * code) | 36 * code) |
| 37 */ | 37 */ |
| 38 std::wstring ToWstring(const std::string& string); | 38 std::wstring ToWstring(const std::string &string); |
| 39 std::wstring ToWstring(const QString& string); | 39 std::wstring ToWstring(const QString &string); |
| 40 std::string ToUtf8String(const std::wstring& wstring); | 40 std::string ToUtf8String(const std::wstring &wstring); |
| 41 std::string ToUtf8String(const QString& string); | 41 std::string ToUtf8String(const QString &string); |
| 42 std::string ToUtf8String(const QByteArray& ba); | 42 std::string ToUtf8String(const QByteArray &ba); |
| 43 std::string ToUtf8String(const std::u32string& u32string); | 43 std::string ToUtf8String(const std::u32string &u32string); |
| 44 std::u32string ToUcs4String(const std::string& string); | 44 std::u32string ToUcs4String(const std::string &string); |
| 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, std::enable_if_t<std::is_arithmetic<T>::value, bool> = true> | 49 template<typename T = int, std::enable_if_t<std::is_arithmetic<T>::value, bool> = true> |
| 50 T ToInt(const std::string& str, T def = 0) { | 50 T ToInt(const std::string &str, T def = 0) |
| 51 { | |
| 51 std::istringstream s(str); | 52 std::istringstream s(str); |
| 52 s >> std::noboolalpha >> def; | 53 s >> std::noboolalpha >> def; |
| 53 return def; | 54 return def; |
| 54 } | 55 } |
| 55 | 56 |
| 56 template<typename T, std::enable_if_t<std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, bool> = true> | 57 template<typename T, std::enable_if_t<std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, bool> = true> |
| 57 std::string ToUtf8String(T i) { | 58 std::string ToUtf8String(T i) |
| 59 { | |
| 58 std::ostringstream s; | 60 std::ostringstream s; |
| 59 s << std::noboolalpha << i; | 61 s << std::noboolalpha << i; |
| 60 return s.str(); | 62 return s.str(); |
| 61 } | 63 } |
| 62 | 64 |
| 63 bool ToBool(const std::string& s, bool def); | 65 bool ToBool(const std::string &s, bool def); |
| 64 | 66 |
| 65 std::string ToUtf8String(bool b); | 67 std::string ToUtf8String(bool b); |
| 66 | 68 |
| 67 uint64_t HumanReadableSizeToBytes(const std::string& str); | 69 uint64_t HumanReadableSizeToBytes(const std::string &str); |
| 68 std::string BytesToHumanReadableSize(uint64_t bytes, int precision = 2); | 70 std::string BytesToHumanReadableSize(uint64_t bytes, int precision = 2); |
| 69 | 71 |
| 70 void RemoveLeadingChars(std::string& s, const char c); | 72 void RemoveLeadingChars(std::string &s, const char c); |
| 71 void RemoveTrailingChars(std::string& s, const char c); | 73 void RemoveTrailingChars(std::string &s, const char c); |
| 72 | 74 |
| 73 bool BeginningMatchesSubstring(const std::string& str, const std::string& sub); | 75 bool BeginningMatchesSubstring(const std::string &str, const std::string &sub); |
| 74 | 76 |
| 75 std::string Translate(const char* str); | 77 std::string Translate(const char *str); |
| 76 | 78 |
| 77 }; // namespace Strings | 79 }; // namespace Strings |
| 78 | 80 |
| 79 #endif // MINORI_CORE_STRINGS_H_ | 81 #endif // MINORI_CORE_STRINGS_H_ |
