Skip to content

refactor(unichar): Make unichar UTF-16 on every platform and remove the UTF-32 path - #3732

Draft
CryoTheRenegade wants to merge 2 commits into
TheSuperHackers:mainfrom
CryoTheRenegade:feat/unichar-uchar
Draft

CryoTheRenegade wants to merge 2 commits into
TheSuperHackers:mainfrom
CryoTheRenegade:feat/unichar-uchar

Conversation

@CryoTheRenegade

@CryoTheRenegade CryoTheRenegade commented Nov 27, 2026 •

Copy link
Copy Markdown

OmniBlade asked in #3187 for unichar to match ICU's UChar, so that it is UTF-16 on every platform and the UTF-32 path in utf8.cpp can go. This is the first part of that follow-up (reply).

 // unichar.h
+#ifdef _WIN32
 typedef wchar_t unichar;
+#else
+typedef char16_t unichar;   // ICU's UChar in C++
+#endif
  • Windows keeps wchar_t, which is 16-bit there, so VC6, L"" literals and the Win32 W APIs are unchanged.
  • deps_icu_linked (the Windows tests against vcpkg ICU) defines UCHAR_TYPE=wchar_t, so UChar is unichar wherever ICU is linked. utf8.cpp now passes unichar* to ICU without casts, so a type mismatch no longer compiles.
  • cmake/icu.cmake now requires ICU 59, the first version where UChar is char16_t in C++.
  • utf8.cpp loses the UTF-32 converters, the UTF8_WCHAR_IS_UTF16 switch and its #error. The tests lose their UTF-32 branches and ReplacesWideValuesBeyondUnicode, which cannot exist with a 16-bit unichar.

Off Windows, L"" literals and the wcs*/swprintf calls no longer match unichar. The game does not build there today. The next PRs add a literal macro (L on Windows, u elsewhere), unichar overloads of the wcs* functions built on stringex.h, and a swprintf replacement that keeps the MSVC %s/%hs meaning.

Evidence

  • utf8_test.cpp on Linux (WSL Ubuntu, g++ 13, ICU 74, unichar = char16_t): 18/18 pass, no warnings with -Wall -Wextra. Before this PR, that build took the UTF-32 path.
  • icu_linked_googletest (Windows, vcpkg ICU 78.3, UChar = wchar_t): 18/18 pass. g_googletest and z_googletest (IcuLoader): 270/270 each.
  • objdiff of utf8.cpp against main: 0 changed functions in ClangCL deps_icu, ClangCL deps_icu_linked and VC6 deps_icu.

AI Assistance:
Claude Opus 5.5 was used to assist implementation and testing

…he UTF-32 path

unichar is now char16_t outside Windows, which matches ICU's UChar, so
utf8.cpp no longer converts through UTF-32 there. Windows keeps wchar_t,
and deps_icu_linked defines UCHAR_TYPE=wchar_t so UChar matches it too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

unichar now represents UTF-16 code units on every platform. Linked-ICU conversions use unichar directly, ICU package lookup requires version 59 or newer, and the tests use surrogate pairs and UTF-16 truncation expectations.

Changes

UTF-16 ICU conversion alignment

Layer / File(s) Summary
Unify the UTF-16 representation and ICU setup
Dependencies/Precompiled/Precompiled/unichar.h, Dependencies/ICU/ICU/utf8.h, Dependencies/ICU/CMakeLists.txt, cmake/icu.cmake
unichar is wchar_t on Windows and char16_t elsewhere. The linked ICU target defines UCHAR_TYPE=wchar_t, and package lookup requires ICU 59 or newer.
Use direct ICU conversions and UTF-16 test expectations
Dependencies/ICU/ICU/utf8.cpp, Tests/Google/Dependencies/ICU/utf8_test.cpp
Linked-ICU conversions pass unichar directly to ICU, replacing the separate UTF-32 path. Surrogate-pair truncation handling applies unconditionally. Tests use surrogate pairs and remove platform-specific UTF-32 expectations.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Possibly related issues

  • Issue 3593: The proposed RTL text path uses ICU UTF-16 functions, and this change aligns non-Windows unichar with ICU’s UChar.

Possibly related PRs

  • TheSuperHackers/GeneralsGameCode#3187: This PR continues the ICU-based UTF-8 conversion work by aligning unichar with ICU’s UTF-16 representation and removing the UTF-32 conversion path.

Suggested reviewers: bobtista, xezon

Merge Risk: Minimal · up to 07431

This change makes unichar a UTF-16 code unit on every platform and removes the UTF-32 conversion path. Linked ICU now passes unichar directly to its conversion functions, and the ICU lookup requires version 59 or newer. No merge-blocking risk is identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: unichar becomes UTF-16 on every platform and the UTF-32 path is removed. The changeset matches this. The title uses the conventional refactor(scope) prefix and is 83 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description states the goal of making unichar UTF-16 on every platform and removing the UTF-32 path from utf8.cpp. It names the affected files and symbols (unichar.h, deps_icu_linked, cmake/icu.cm…
Full details: Title check

Explanation

The title states the main change: unichar becomes UTF-16 on every platform and the UTF-32 path is removed. The changeset matches this. The title uses the conventional refactor(scope) prefix and is 83 characters long, which is slightly long but still clear.

Full details: Description check

Explanation

The description states the goal of making unichar UTF-16 on every platform and removing the UTF-32 path from utf8.cpp. It names the affected files and symbols (unichar.h, deps_icu_linked, cmake/icu.cmake, utf8.cpp, utf8_test.cpp). It also gives a diff, test evidence, and the follow-up plan. It matches the changeset, so the check passes.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c6e81144-bd7c-46e0-9dcb-de4351047d0e
Commits

Reviewing files that changed from the base of the PR and between 7a3adc8 and 074313a.

Files selected for processing: 1

  • cmake/icu.cmake

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a55c6327-baf2-4b21-8672-1b64734a22a2
Commits

Reviewing files that changed from the base of the PR and between 9afbe5c and 7a3adc8.

Files selected for processing: 5

  • Dependencies/ICU/CMakeLists.txt
  • Dependencies/ICU/ICU/utf8.cpp
  • Dependencies/ICU/ICU/utf8.h
  • Dependencies/Precompiled/Precompiled/unichar.h
  • Tests/Google/Dependencies/ICU/utf8_test.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Comment thread Dependencies/ICU/ICU/utf8.cpp Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant