diff 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
line wrap: on
line diff
--- a/src/core/strings.cpp	Sun Oct 01 06:39:47 2023 -0400
+++ b/src/core/strings.cpp	Sun Oct 01 23:15:43 2023 -0400
@@ -2,6 +2,8 @@
  * strings.cpp: Useful functions for manipulating strings
  **/
 #include "core/strings.h"
+#include <QByteArray>
+#include <QString>
 #include <algorithm>
 #include <cctype>
 #include <codecvt>
@@ -62,8 +64,8 @@
 }
 
 /* these functions suck for i18n!...
-   but we only use them with JSON
-   stuff anyway */
+	but we only use them with JSON
+	stuff anyway */
 std::string ToUpper(const std::string& string) {
 	std::string result(string);
 	std::transform(result.begin(), result.end(), result.begin(), [](unsigned char c) { return std::toupper(c); });
@@ -81,9 +83,28 @@
 	return converter.from_bytes(string);
 }
 
+std::wstring ToWstring(const QString& string) {
+	std::wstring arr(string.size(), L'\0');
+	string.toWCharArray(&arr.front());
+	return arr;
+}
+
 std::string ToUtf8String(const std::wstring& wstring) {
 	std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
 	return converter.to_bytes(wstring);
 }
 
+std::string ToUtf8String(const QString& string) {
+	QByteArray ba = string.toUtf8();
+	return std::string(ba.data(), ba.size());
+}
+
+QString ToQString(const std::string& string) {
+	return QString::fromUtf8(string.c_str(), string.length());
+}
+
+QString ToQString(const std::wstring& wstring) {
+	return QString::fromWCharArray(wstring.c_str(), wstring.length());
+}
+
 } // namespace Strings