Reconstruct readable C++ and organize cohesive source subsystems

Administrative source import: native x86 compilation passed for 423 authored units. Source placement and submission states are migrated separately; this commit does not imply peer acceptance.

Previous head: 35d2a8cb36
Payload SHA256: 592f016d2730c5593bb653aa054c1e5f76a6df72c8f5a09e66f74876e2e33dee
This commit is contained in:
ragnarok-clanker 2026-10-25 07:42:41 +00:00
commit a47d20f8be
890 changed files with 11796 additions and 16664 deletions

View file

@ -15,20 +15,23 @@ std::string ToUtf8(std::string text) {
std::string result;
int wideLength = MultiByteToWideChar(g_textCodePage, 0, text.c_str(), lstrlenA(text.c_str()), nullptr, 0);
BSTR wide = SysAllocStringLen(nullptr, wideLength);
if (wide) {
MultiByteToWideChar(g_textCodePage, 0, text.c_str(), lstrlenA(text.c_str()), wide, wideLength);
int length = WideCharToMultiByte(CP_UTF8, 0, wide, -1, nullptr, 0, nullptr, nullptr);
char* converted = static_cast<char*>(_malloca(length + 1));
if (converted) {
WideCharToMultiByte(CP_UTF8, 0, wide, -1, converted, length, nullptr, nullptr);
result.assign(converted, std::strlen(converted));
_freea(converted);
} else {
// Original failure path reaches an unchecked null string assignment.
result.assign(converted, std::strlen(converted));
}
SysFreeString(wide);
}
return result;
}
@ -41,14 +44,17 @@ std::string FromUtf8(std::string text) {
MultiByteToWideChar(CP_UTF8, 0, text.c_str(), lstrlenA(text.c_str()) + 1, wide, wideLength);
int length = WideCharToMultiByte(g_textCodePage, 0, wide, -1, nullptr, 0, nullptr, nullptr);
char* converted = static_cast<char*>(_malloca(length + 1));
if (converted) {
WideCharToMultiByte(g_textCodePage, 0, wide, -1, converted, length, nullptr, nullptr);
result.assign(converted, std::strlen(converted));
_freea(converted);
}
if (wide) {
SysFreeString(wide);
}
return result;
}
@ -59,28 +65,34 @@ std::string FromUtf8(const std::string& text, UINT codePage) {
if (!wideLength) {
return {};
}
BSTR wide = SysAllocStringLen(nullptr, wideLength);
if (!wide) {
return {};
}
if (!MultiByteToWideChar(CP_UTF8, 0, text.data(), static_cast<int>(text.size()), wide, wideLength)) {
SysFreeString(wide);
return {};
}
int length = WideCharToMultiByte(codePage, 0, wide, -1, nullptr, 0, nullptr, nullptr);
if (!length) {
SysFreeString(wide);
return {};
}
char* converted = static_cast<char*>(std::malloc(length));
if (!converted) {
SysFreeString(wide);
return {};
}
std::string result;
if (WideCharToMultiByte(codePage, 0, wide, -1, converted, length, nullptr, nullptr)) {
result.assign(converted);
}
std::free(converted);
SysFreeString(wide);
return result;
@ -93,28 +105,34 @@ std::string ToUtf8(const std::string& text, UINT codePage) {
if (!wideLength) {
return {};
}
BSTR wide = SysAllocStringLen(nullptr, wideLength);
if (!wide) {
return {};
}
if (!MultiByteToWideChar(codePage, 0, text.data(), static_cast<int>(text.size()), wide, wideLength)) {
SysFreeString(wide);
return {};
}
int length = WideCharToMultiByte(CP_UTF8, 0, wide, -1, nullptr, 0, nullptr, nullptr);
if (!length) {
SysFreeString(wide);
return {};
}
char* converted = static_cast<char*>(std::malloc(length));
if (!converted) {
SysFreeString(wide);
return {};
}
std::string result;
if (WideCharToMultiByte(CP_UTF8, 0, wide, -1, converted, length, nullptr, nullptr)) {
result.assign(converted);
}
std::free(converted);
SysFreeString(wide);
return result;