Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
40393b8
feat(utf8): add UTF-8 string conversion and validation functions
bobtista Apr 6, 2026
abb71f0
refactor(utf8): Return size_t from conversions, use consistent len na…
bobtista Apr 7, 2026
0c9074d
refactor(utf8): Update callers to use new conversion API
bobtista Apr 7, 2026
149a07f
refactor(utf8): rename to Utf16Le_To_Utf8 and return required size on…
bobtista Apr 15, 2026
6097799
refactor(utf8): add writeDirect mode, use _Len helpers, const locals,…
bobtista Apr 17, 2026
9078de5
refactor(utf8): simplify conversion API and reject UTF-16 surrogates
bobtista Apr 18, 2026
327bb4b
style(utf8): assert after write, add braces, const locals
bobtista Apr 18, 2026
4d5d2dc
style(utf8): Use >= 0 in length return ternaries
bobtista Apr 18, 2026
f582ac8
refactor(utf8): remove unused validators and simplify conversion fail…
bobtista Jun 29, 2026
40683de
style(string): add braces to translate conversion check
bobtista Jun 29, 2026
44f8fca
fix(string): return empty string when ThreadUtils conversion fails
bobtista Jun 29, 2026
fc3add5
refactor(string): drop unrelated ensureUniqueBufferOfSize null-termin…
bobtista Jul 19, 2026
ce8a2f4
refactor(utf8): replace Win32 wrappers with portable RFC 3629 transcoder
bobtista Jul 19, 2026
d4a7e73
fix(string): fall back to 1:1 byte cast for non-UTF-8 data in Unicode…
bobtista Jul 19, 2026
e0a425e
fix(utf8): Substitute U+FFFD for wide values with no UTF-8 representa…
bobtista Jul 28, 2026
159da01
refactor(utf8): Return UTF8_INVALID instead of 0 for malformed UTF-8
bobtista Jul 28, 2026
51a0460
fix(gamespy): Fall back to byte cast for non-UTF-8 text in MultiByteT…
bobtista Jul 28, 2026
1a58d95
refactor(utf8): Rename conversions to Wide_To_Utf8 and Utf8_To_Wide
bobtista Jul 28, 2026
81a47bf
refactor(utf8): Remove unused Utf8_Validate
bobtista Jul 28, 2026
d98492c
build: Use qualified include path for WWLib utf8.h
bobtista Jul 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions Core/GameEngine/Source/Common/System/AsciiString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine

#include "Common/CriticalSection.h"
#include "WWLib/utf8.h"


// -----------------------------------------------------
Expand Down Expand Up @@ -272,11 +273,19 @@ char* AsciiString::getBufferForRead(Int len)
void AsciiString::translate(const UnicodeString& stringSrc)
{
validate();
/// @todo srj put in a real translation here; this will only work for 7-bit ascii
clear();
Int len = stringSrc.getLength();
for (Int i = 0; i < len; i++)
concat((char)stringSrc.getCharAt(i));
// TheSuperHackers @fix bobtista 02/04/2026 Implement UTF-8 conversion replacing 7-bit ASCII only implementation
const WideChar* src = stringSrc.str();
const size_t srcLen = wcslen(src);
const size_t len = Wide_To_Utf8_Len(src, srcLen);
if (len == 0)
{
clear();
}
else
{
ensureUniqueBufferOfSize((Int)len + 1, false, nullptr, nullptr);
Wide_To_Utf8(peek(), len + 1, src, srcLen);
}
validate();
}

Expand Down
31 changes: 26 additions & 5 deletions Core/GameEngine/Source/Common/System/UnicodeString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine

#include "Common/CriticalSection.h"
#include "WWLib/utf8.h"


// -----------------------------------------------------
Expand Down Expand Up @@ -221,11 +222,31 @@ WideChar* UnicodeString::getBufferForRead(Int len)
void UnicodeString::translate(const AsciiString& stringSrc)
{
validate();
/// @todo srj put in a real translation here; this will only work for 7-bit ascii
clear();
Int len = stringSrc.getLength();
for (Int i = 0; i < len; i++)
concat((WideChar)stringSrc.getCharAt(i));
// TheSuperHackers @fix bobtista 02/04/2026 Convert UTF-8 to wide, replacing the 7-bit ASCII only
// implementation. Data that is not valid UTF-8 (e.g. legacy CP1252) falls back to a 1:1 byte cast
// to preserve the original characters instead of producing replacement characters.
const char* src = stringSrc.str();
const size_t srcLen = strlen(src);
const size_t len = Utf8_To_Wide_Len(src, srcLen);
if (srcLen == 0)
{
clear();
}
else if (len == UTF8_INVALID)
{
ensureUniqueBufferOfSize((Int)srcLen + 1, false, nullptr, nullptr);
WideChar* buf = peek();
for (size_t i = 0; i < srcLen; ++i)
{
buf[i] = (WideChar)(unsigned char)src[i];
}
buf[srcLen] = 0;
}
else
{
ensureUniqueBufferOfSize((Int)len + 1, false, nullptr, nullptr);
Utf8_To_Wide(peek(), len + 1, src, srcLen);
}
validate();
}

Expand Down
49 changes: 31 additions & 18 deletions Core/GameEngine/Source/GameNetwork/GameSpy/Thread/ThreadUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,37 @@

#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine

#include "WWLib/utf8.h"

//-------------------------------------------------------------------------

// TheSuperHackers @refactor bobtista 02/04/2026 Use WWLib UTF-8 functions instead of raw Win32 API calls
std::wstring MultiByteToWideCharSingleLine( const char *orig )
{
Int len = strlen(orig);
WideChar *dest = NEW WideChar[len+1];

MultiByteToWideChar(CP_UTF8, 0, orig, -1, dest, len);
const size_t srcLen = strlen(orig);
const size_t len = Utf8_To_Wide_Len(orig, srcLen);
if (len == 0)
return std::wstring();
std::wstring ret;
if (len == UTF8_INVALID)
{
// Not UTF-8. Fall back to a 1:1 byte cast so legacy data keeps its characters, matching
// UnicodeString::translate.
ret.resize(srcLen);
for (size_t i = 0; i < srcLen; ++i)
{
ret[i] = (WideChar)(unsigned char)orig[i];
}
}
else
{
ret.resize(len);
Utf8_To_Wide(&ret[0], len, orig, srcLen);
}
WideChar *c = nullptr;
do
{
c = wcschr(dest, L'\n');
c = wcschr(&ret[0], L'\n');
if (c)
{
*c = L' ';
Expand All @@ -48,32 +67,26 @@ std::wstring MultiByteToWideCharSingleLine( const char *orig )
while ( c != nullptr );
do
{
c = wcschr(dest, L'\r');
c = wcschr(&ret[0], L'\r');
if (c)
{
*c = L' ';
}
}
while ( c != nullptr );

dest[len] = 0;
std::wstring ret = dest;
delete[] dest;
return ret;
}

std::string WideCharStringToMultiByte( const WideChar *orig )
{
const size_t srcLen = wcslen(orig);
const size_t len = Wide_To_Utf8_Len(orig, srcLen);
if (len == 0)
return std::string();
std::string ret;
Int len = WideCharToMultiByte( CP_UTF8, 0, orig, wcslen(orig), nullptr, 0, nullptr, nullptr ) + 1;
if (len > 0)
{
char *dest = NEW char[len];
WideCharToMultiByte( CP_UTF8, 0, orig, -1, dest, len, nullptr, nullptr );
dest[len-1] = 0;
ret = dest;
delete[] dest;
}
ret.resize(len);
Wide_To_Utf8(&ret[0], len, orig, srcLen);
return ret;
}

Expand Down
2 changes: 2 additions & 0 deletions Core/Libraries/Source/WWVegas/WWLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ set(WWLIB_SRC
trim.cpp
trim.h
uarray.h
utf8.cpp
utf8.h
Comment thread
xezon marked this conversation as resolved.
vector.cpp
Vector.h
visualc.h
Expand Down
Loading
Loading