You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(icu4c): Add right-to-left text functions for Arabic shaping and line reordering - #3734
This is M2 of the right-to-left text design in #3593. It adds the text functions that the later rendering changes will use. Nothing calls them yet, so there is no change in the game.
New ICU/bidi.h in deps_icu, next to ICU/utf8.h from #3187:
Bidi_Get_Paragraph_Level gets the direction of a paragraph from its first strong character, such as a Latin or an Arabic letter.
Bidi_Shape_Arabic replaces Arabic letters with the presentation forms that join them to their neighbours. A lam followed by an alef becomes one ligature, so the text can get shorter.
Bidi_Reorder_Line puts one line of a paragraph into display order and mirrors brackets in right-to-left runs. It analyzes the whole paragraph, so a wrapped line displays the same as in the unwrapped text. It can also return the logical index of each display position, which the text entry needs later for the caret. A surrogate pair, such as an emoji, keeps its two units in order in the text and in the index map.
Each function returns false when ICU is not available, and the caller keeps the text as it is. The bidi tests are skipped on Windows without a system icu.dll, such as before Windows 10 1903. When the DLL exists, they must pass.
How ICU is used, the same way as the UTF-8 functions:
Windows, including VC6: IcuLoader resolves u_shapeArabic and the ubidi_* functions from the Windows icu.dll. These exports are optional, so the UTF-8 conversions still work with an icu.dll that does not have them.
Other platforms: the functions call linked ICU.
Tests: bidi_test.cpp has Google Tests for paragraph direction, reordering of Hebrew, Arabic, digits and mixed text, bracket mirroring, a line that needs its paragraph, the position map with a surrogate pair, Arabic shaping including lam-alef, and invalid arguments. They run in g_googletest and z_googletest against IcuLoader, and in icu_linked_googletest against linked ICU.
I ran the tests locally with MinGW-w64 against the Windows 11 icu.dll: all 26 ICU tests pass (8 bidi, 18 utf8).
AI USE
I used Claude Code to write the change and the tests, based on the design in #3593. I ran the tests and checked the results myself.
No actionable comments were generated in the recent review.
Walkthrough
Adds public ICU-backed helpers for paragraph direction, Arabic shaping, and line reordering. The helpers use linked ICU or dynamically loaded ICU exports. Build configuration, tests, and the ICU README now include these bidi functions.
Changes
ICU bidi and Arabic shaping
Layer / File(s)
Summary
Bidi API and ICU loader Dependencies/ICU/ICU/IcuLoader.h, Dependencies/ICU/ICU/IcuLoader.cpp
Adds the Level alias and bidi methods. The loader resolves optional Arabic-shaping and bidi exports, then exposes calls that return failure when required loading or exports are unavailable.
Bidi and shaping operations Dependencies/ICU/ICU/bidi.h, Dependencies/ICU/ICU/bidi.cpp
Adds paragraph direction detection, Arabic shaping, and line reordering for linked or dynamically loaded ICU. The functions validate lengths and line ranges, and can return a display-to-logical index map.
Build integration and tests Dependencies/ICU/CMakeLists.txt, Tests/Google/Dependencies/CMakeLists.txt, Tests/Google/Dependencies/ICU/bidi_test.cpp, Dependencies/ICU/README.md
Adds the bidi source to ICU targets and registers bidi tests for shared and linked-ICU test builds. The README documents the API and Windows dynamic-loading behavior.
sequenceDiagram
participant Caller
participant BidiHelpers
participant IcuLoader
participant ICU
Caller->>BidiHelpers: Call a bidi helper
alt Linked ICU build
BidiHelpers->>ICU: Process text
ICU-->>BidiHelpers: Return operation result
else Dynamic ICU
BidiHelpers->>IcuLoader: Request bidi or shaping operation
IcuLoader->>ICU: Call resolved ICU exports
ICU-->>IcuLoader: Return operation result
IcuLoader-->>BidiHelpers: Return result and output
end
BidiHelpers-->>Caller: Return status and output
Loading
Possibly related issues
TheSuperHackers/GeneralsGameCode#3593: Proposes right-to-left text support using ICU shaping and bidi reordering. This PR adds the bidi functions described as milestone M2 but does not connect them to game rendering.
This change adds ICU-backed Arabic shaping and bidirectional line-reordering helpers that no game code calls yet. The earlier concern that the display-to-logical index map disagreed with the reordered text for UTF-16 surrogate pairs is now fixed and covered by a test. No unresolved merge-blocking risk remains.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title states the main change: adding right-to-left text functions (Arabic shaping and line reordering) to the ICU dependency. The changeset adds ICU/bidi.h and bidi.cpp with paragraph-level detect…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The description is specific and on-topic. It names the new ICU/bidi.h functions (Bidi_Get_Paragraph_Level, Bidi_Shape_Arabic, Bidi_Reorder_Line), explains the IcuLoader optional exports on Windows and…
Full details: Title check
Explanation
The title states the main change: adding right-to-left text functions (Arabic shaping and line reordering) to the ICU dependency. The changeset adds ICU/bidi.h and bidi.cpp with paragraph-level detection, Arabic shaping, and line reordering, plus IcuLoader support and tests. The title matches the primary change, and the format follows conventional commit style.
Full details: Description check
Explanation
The description is specific and on-topic. It names the new ICU/bidi.h functions (Bidi_Get_Paragraph_Level, Bidi_Shape_Arabic, Bidi_Reorder_Line), explains the IcuLoader optional exports on Windows and linked ICU elsewhere, lists the test coverage, and gives local test results. It matches the changeset summaries, so the check passes.
Warning
Some tools did not complete. Review the errors below.
Clang (23.1.4)
Dependencies/ICU/ICU/IcuLoader.cpp
Clang-Tidy produced no recognizable diagnostics; analysis is incomplete
Dependencies/ICU/ICU/IcuLoader.h
Clang-Tidy produced no recognizable diagnostics; analysis is incomplete
Dependencies/ICU/ICU/bidi.cpp
Clang-Tidy produced no recognizable diagnostics; analysis is incomplete
2 others
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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 12f3a5c1-6f10-4cf9-8cd4-5a7667d8aeb4
Commits
Reviewing files that changed from the base of the PR and between 0701ba4 and 73212dd.
Files selected for processing: 5
Dependencies/ICU/ICU/IcuLoader.cpp
Dependencies/ICU/ICU/IcuLoader.h
Dependencies/ICU/ICU/bidi.cpp
Dependencies/ICU/ICU/bidi.h
Tests/Google/Dependencies/ICU/bidi_test.cpp
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
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: 2254a872-e6ba-4701-be86-a83bdf179395
Commits
Reviewing files that changed from the base of the PR and between 0f43d37 and 0701ba4.
Files selected for processing: 8
Dependencies/ICU/CMakeLists.txt
Dependencies/ICU/ICU/IcuLoader.cpp
Dependencies/ICU/ICU/IcuLoader.h
Dependencies/ICU/ICU/bidi.cpp
Dependencies/ICU/ICU/bidi.h
Dependencies/ICU/README.md
Tests/Google/Dependencies/CMakeLists.txt
Tests/Google/Dependencies/ICU/bidi_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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is M2 of the right-to-left text design in #3593. It adds the text functions that the later rendering changes will use. Nothing calls them yet, so there is no change in the game.
New
ICU/bidi.hindeps_icu, next toICU/utf8.hfrom #3187:Bidi_Get_Paragraph_Levelgets the direction of a paragraph from its first strong character, such as a Latin or an Arabic letter.Bidi_Shape_Arabicreplaces Arabic letters with the presentation forms that join them to their neighbours. A lam followed by an alef becomes one ligature, so the text can get shorter.Bidi_Reorder_Lineputs one line of a paragraph into display order and mirrors brackets in right-to-left runs. It analyzes the whole paragraph, so a wrapped line displays the same as in the unwrapped text. It can also return the logical index of each display position, which the text entry needs later for the caret. A surrogate pair, such as an emoji, keeps its two units in order in the text and in the index map.Each function returns false when ICU is not available, and the caller keeps the text as it is. The bidi tests are skipped on Windows without a system
icu.dll, such as before Windows 10 1903. When the DLL exists, they must pass.How ICU is used, the same way as the UTF-8 functions:
IcuLoaderresolvesu_shapeArabicand theubidi_*functions from the Windowsicu.dll. These exports are optional, so the UTF-8 conversions still work with anicu.dllthat does not have them.Tests:
bidi_test.cpphas Google Tests for paragraph direction, reordering of Hebrew, Arabic, digits and mixed text, bracket mirroring, a line that needs its paragraph, the position map with a surrogate pair, Arabic shaping including lam-alef, and invalid arguments. They run ing_googletestandz_googletestagainstIcuLoader, and inicu_linked_googletestagainst linked ICU.I ran the tests locally with MinGW-w64 against the Windows 11
icu.dll: all 26 ICU tests pass (8 bidi, 18 utf8).AI USE
I used Claude Code to write the change and the tests, based on the design in #3593. I ran the tests and checked the results myself.