mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-09-23 11:18:07 +00:00
Merge branch 'dev' into tu19-take-2
This commit is contained in:
@@ -43,48 +43,55 @@ std::wstring convStringToWstring(const std::string& converting) {
|
||||
}
|
||||
|
||||
std::wstring u16string_to_wstring(const std::u16string& converting) {
|
||||
#if WCHAR_MAX == 0xFFFF
|
||||
// on windows, wchar_t is UTF-16 so we can get away with just a type
|
||||
// transmutation
|
||||
return std::wstring(reinterpret_cast<const wchar_t*>(converting.data()),
|
||||
converting.size());
|
||||
#else
|
||||
// POSIX has wchar_t as UTF-32 instead so simdutf time :>>>
|
||||
if (converting.empty()) return {};
|
||||
if constexpr (sizeof(wchar_t) == 2) {
|
||||
// on Windows, wchar_t is UTF-16 so we can get away with just a type
|
||||
// transmutation
|
||||
return std::wstring(reinterpret_cast<const wchar_t*>(converting.data()),
|
||||
converting.size());
|
||||
} else if constexpr (sizeof(wchar_t) == 4) {
|
||||
// POSIX has wchar_t as UTF-32 instead so simdutf time :>>>
|
||||
if (converting.empty()) return {};
|
||||
|
||||
std::wstring result(
|
||||
simdutf::utf32_length_from_utf16(converting.data(), converting.size()),
|
||||
L'\0');
|
||||
std::size_t convertedLength = simdutf::convert_utf16_to_utf32(
|
||||
converting.data(), converting.size(),
|
||||
reinterpret_cast<char32_t*>(result.data()));
|
||||
result.resize(convertedLength);
|
||||
std::wstring result(simdutf::utf32_length_from_utf16(converting.data(),
|
||||
converting.size()),
|
||||
L'\0');
|
||||
std::size_t convertedLength = simdutf::convert_utf16_to_utf32(
|
||||
converting.data(), converting.size(),
|
||||
reinterpret_cast<char32_t*>(result.data()));
|
||||
result.resize(convertedLength);
|
||||
|
||||
return result;
|
||||
#endif
|
||||
return result;
|
||||
} else {
|
||||
static_assert(sizeof(wchar_t) != 2 || sizeof(wchar_t) != 4,
|
||||
"Here's a nickel, Kid. Go buy yourself a real computer.");
|
||||
}
|
||||
}
|
||||
|
||||
std::u16string wstring_to_u16string(const std::wstring& converting) {
|
||||
#if WCHAR_MAX == 0xFFFF
|
||||
// windows, UTF-16
|
||||
return std::u16string(reinterpret_cast<const char16_t*>(converting.data()),
|
||||
converting.size());
|
||||
#else
|
||||
// POSIX, UTF-32
|
||||
if (converting.empty()) return {};
|
||||
if constexpr (sizeof(wchar_t) == 2) {
|
||||
// Windows, UTF-16
|
||||
return std::u16string(
|
||||
reinterpret_cast<const char16_t*>(converting.data()),
|
||||
converting.size());
|
||||
} else if constexpr (sizeof(wchar_t) == 4) {
|
||||
// POSIX, UTF-32
|
||||
if (converting.empty()) return {};
|
||||
|
||||
const char32_t* data32 =
|
||||
reinterpret_cast<const char32_t*>(converting.data());
|
||||
const std::size_t len32 = converting.size();
|
||||
const char32_t* data32 =
|
||||
reinterpret_cast<const char32_t*>(converting.data());
|
||||
const std::size_t len32 = converting.size();
|
||||
|
||||
std::u16string result(simdutf::utf16_length_from_utf32(data32, len32),
|
||||
u'\0');
|
||||
std::size_t convertedLength =
|
||||
simdutf::convert_utf32_to_utf16(data32, len32, result.data());
|
||||
result.resize(convertedLength);
|
||||
std::u16string result(simdutf::utf16_length_from_utf32(data32, len32),
|
||||
u'\0');
|
||||
std::size_t convertedLength =
|
||||
simdutf::convert_utf32_to_utf16(data32, len32, result.data());
|
||||
result.resize(convertedLength);
|
||||
|
||||
return result;
|
||||
#endif
|
||||
return result;
|
||||
} else {
|
||||
static_assert(sizeof(wchar_t) != 2 || sizeof(wchar_t) != 4,
|
||||
"Here's a nickel, Kid. Go buy yourself a real computer.");
|
||||
}
|
||||
}
|
||||
|
||||
// Convert for filename std::wstrings to a straight character pointer for Xbox
|
||||
|
||||
Reference in New Issue
Block a user