2024-02-23 23:32:32 +02:00
|
|
|
// SPDX-FileCopyrightText: 2013 Dolphin Emulator Project
|
|
|
|
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2023-08-01 00:42:49 +03:00
|
|
|
#include <algorithm>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2023-11-05 13:41:10 +02:00
|
|
|
#include "common/string_util.h"
|
2024-02-28 00:10:34 +02:00
|
|
|
#include "common/types.h"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
2023-08-01 00:42:49 +03:00
|
|
|
|
2023-11-05 16:56:28 +02:00
|
|
|
namespace Common {
|
2023-08-01 00:42:49 +03:00
|
|
|
|
2024-07-05 00:15:44 +03:00
|
|
|
std::string ToLower(std::string str) {
|
|
|
|
std::transform(str.begin(), str.end(), str.begin(),
|
|
|
|
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2024-02-23 22:57:57 +02:00
|
|
|
std::vector<std::string> SplitString(const std::string& str, char delimiter) {
|
2023-11-05 16:56:28 +02:00
|
|
|
std::istringstream iss(str);
|
|
|
|
std::vector<std::string> output(1);
|
2023-08-01 00:42:49 +03:00
|
|
|
|
2023-11-05 16:56:28 +02:00
|
|
|
while (std::getline(iss, *output.rbegin(), delimiter)) {
|
|
|
|
output.emplace_back();
|
2023-08-01 00:42:49 +03:00
|
|
|
}
|
2023-11-05 16:56:28 +02:00
|
|
|
|
|
|
|
output.pop_back();
|
|
|
|
return output;
|
2023-08-01 00:42:49 +03:00
|
|
|
}
|
|
|
|
|
2024-02-28 00:10:34 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
static std::wstring CPToUTF16(u32 code_page, std::string_view input) {
|
|
|
|
const auto size =
|
|
|
|
MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0);
|
|
|
|
|
|
|
|
if (size == 0) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::wstring output(size, L'\0');
|
|
|
|
|
|
|
|
if (size != MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()),
|
|
|
|
&output[0], static_cast<int>(output.size()))) {
|
|
|
|
output.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string UTF16ToUTF8(std::wstring_view input) {
|
|
|
|
const auto size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()),
|
|
|
|
nullptr, 0, nullptr, nullptr);
|
|
|
|
if (size == 0) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string output(size, '\0');
|
|
|
|
|
|
|
|
if (size != WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()),
|
|
|
|
&output[0], static_cast<int>(output.size()), nullptr,
|
|
|
|
nullptr)) {
|
|
|
|
output.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::wstring UTF8ToUTF16W(std::string_view input) {
|
|
|
|
return CPToUTF16(CP_UTF8, input);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-11-05 16:56:28 +02:00
|
|
|
} // namespace Common
|