Mercurial > minori
comparison src/core/strings.cpp @ 64:fe719c109dbc
*: update
1. add media tracking ability, and it displays info on the `now playing` page
2. the `now playing` page now actually shows something
3. renamed every page class to be more accurate to what it is
4. ...
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Sun, 01 Oct 2023 23:15:43 -0400 |
| parents | 4c6dd5999b39 |
| children | 3364fadc8a36 |
comparison
equal
deleted
inserted
replaced
| 63:3d2decf093bb | 64:fe719c109dbc |
|---|---|
| 1 /** | 1 /** |
| 2 * strings.cpp: Useful functions for manipulating strings | 2 * strings.cpp: Useful functions for manipulating strings |
| 3 **/ | 3 **/ |
| 4 #include "core/strings.h" | 4 #include "core/strings.h" |
| 5 #include <QByteArray> | |
| 6 #include <QString> | |
| 5 #include <algorithm> | 7 #include <algorithm> |
| 6 #include <cctype> | 8 #include <cctype> |
| 7 #include <codecvt> | 9 #include <codecvt> |
| 8 #include <locale> | 10 #include <locale> |
| 9 #include <string> | 11 #include <string> |
| 60 std::string TextifySynopsis(const std::string& string) { | 62 std::string TextifySynopsis(const std::string& string) { |
| 61 return RemoveHtmlTags(SanitizeLineEndings(string)); | 63 return RemoveHtmlTags(SanitizeLineEndings(string)); |
| 62 } | 64 } |
| 63 | 65 |
| 64 /* these functions suck for i18n!... | 66 /* these functions suck for i18n!... |
| 65 but we only use them with JSON | 67 but we only use them with JSON |
| 66 stuff anyway */ | 68 stuff anyway */ |
| 67 std::string ToUpper(const std::string& string) { | 69 std::string ToUpper(const std::string& string) { |
| 68 std::string result(string); | 70 std::string result(string); |
| 69 std::transform(result.begin(), result.end(), result.begin(), [](unsigned char c) { return std::toupper(c); }); | 71 std::transform(result.begin(), result.end(), result.begin(), [](unsigned char c) { return std::toupper(c); }); |
| 70 return result; | 72 return result; |
| 71 } | 73 } |
| 79 std::wstring ToWstring(const std::string& string) { | 81 std::wstring ToWstring(const std::string& string) { |
| 80 std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter; | 82 std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter; |
| 81 return converter.from_bytes(string); | 83 return converter.from_bytes(string); |
| 82 } | 84 } |
| 83 | 85 |
| 86 std::wstring ToWstring(const QString& string) { | |
| 87 std::wstring arr(string.size(), L'\0'); | |
| 88 string.toWCharArray(&arr.front()); | |
| 89 return arr; | |
| 90 } | |
| 91 | |
| 84 std::string ToUtf8String(const std::wstring& wstring) { | 92 std::string ToUtf8String(const std::wstring& wstring) { |
| 85 std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter; | 93 std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter; |
| 86 return converter.to_bytes(wstring); | 94 return converter.to_bytes(wstring); |
| 87 } | 95 } |
| 88 | 96 |
| 97 std::string ToUtf8String(const QString& string) { | |
| 98 QByteArray ba = string.toUtf8(); | |
| 99 return std::string(ba.data(), ba.size()); | |
| 100 } | |
| 101 | |
| 102 QString ToQString(const std::string& string) { | |
| 103 return QString::fromUtf8(string.c_str(), string.length()); | |
| 104 } | |
| 105 | |
| 106 QString ToQString(const std::wstring& wstring) { | |
| 107 return QString::fromWCharArray(wstring.c_str(), wstring.length()); | |
| 108 } | |
| 109 | |
| 89 } // namespace Strings | 110 } // namespace Strings |
