Skip to content

feat(icu4c): Add right-to-left text functions for Arabic shaping and line reordering - #3734

Open
OmarAglan wants to merge 2 commits into
TheSuperHackers:mainfrom
OmarAglan:feat/icu-bidi
Open

OmarAglan wants to merge 2 commits into
TheSuperHackers:mainfrom
OmarAglan:feat/icu-bidi

Conversation

@OmarAglan

@OmarAglan OmarAglan commented Nov 29, 2026 •

Copy link
Copy Markdown

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.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-29T12:45:09.366535Z
We couldn’t complete this review. Comment @codex review to try again.
0701ba4 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Explain Change →

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.

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

Change: Feature

Sequence Diagram(s)

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.

Possibly related PRs

Suggested reviewers: cryotherenegade, bobtista

Merge Risk: Minimal · up to 73212

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: Passed 4

Check name Status Explanation
Title check Passed 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 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 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.

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: 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.

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; the previous caret-map issue is fixed and no new blocking issue was found.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; the previous caret-map issue is fixed and no new blocking issue was found.

Summary

Adds ICU-backed paragraph direction, Arabic shaping, and line reordering for later rendering changes. No game code calls these functions yet.

  • Text can be reordered for display one line at a time.
  • Arabic letters can be shaped to join neighboring letters.

The previous caret-map finding is fixed. No new actionable issues were found.

Reviews (2) · Last reviewed commit: "fix(icu4c): Reorder lines in paragraph c..." · Reviewed by Greptile

Comment thread Dependencies/ICU/ICU/IcuLoader.cpp Resolved

@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: 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.

Comment thread Dependencies/ICU/ICU/bidi.cpp Resolved
Comment thread Dependencies/ICU/ICU/IcuLoader.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