feat(libSceNKWebKit): implement the WTF grapheme cluster counts #23723

Merged
Dark3581 merged 1 commit from upstream-pr/23723 into main 2026-11-19 16:14:44 +00:00
Dark3581 commented 2026-11-19 14:30:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dark3581 on 2026-11-19T14:30:14Z.


What

Implements WTF::numGraphemeClusters(StringView) and WTF::numCodeUnitsInGraphemeClusters(StringView, unsigned) in libSceNKWebKit. Both were throwing stubs in Export.cpp.

  • The code follows pinned PS5 WebKit 11.x TextBreakIterator.cpp. The two bodies are the same as WebKit c55364d53f97.
  • 8-bit strings take WebKit's Latin-1 path, where CR LF is the only cluster longer than one code unit.
  • 16-bit strings whose code units are all at most U+00FF take the same path. UAX #29 gives them the same boundaries, because no Extend, SpacingMark, Prepend or ZWJ code point lies below U+0100.
  • A 16-bit string with any code unit above U+00FF throws through NotImplemented_nid_no_patch. That case needs the ICU character break iterator, and the bundled ICU has no break rule data.
  • Early returns match WebKit: an empty view gives 0, and a cluster count at or past the length returns the length without reading the buffer. A null buffer that must be read throws std::invalid_argument, as CheckBuffer does elsewhere in the library.
  • StringView is passed by value as the existing 16-byte NKWebKit::WtfAbi::StringView. Its copy constructor is user-provided only under CHECK_STRINGVIEW_LIFETIME.
  • The debt fragment removes the two inventory rows and adds a Functional entry for the 16-bit gap.

tools/pr_overlap.py --branch failed closed on PR 23468 and PR 23475, which conflict with main. I compared them by hand. Each edits a stub next to these in Export.cpp/InventoryExports.hpp (only context lines match), and --names lists no open PR for either function.

Tested

Windows 10 22H2, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, on main 713cc62069 plus this commit.

  • ctest -R "^(nkwebkit_|guest_nkwebkit)": 153 of 153 pass, including the new nkwebkit_graphemeclusters.
  • The new test covers:
    • both widths;
    • CR and LF runs (\r\r\n, \n\r, \r\n\r\n) and embedded nulls;
    • Latin-1 code units in 16-bit strings;
    • code unit counts below, at and past the string length;
    • null buffers;
    • the throwing path for a combining sequence and a surrogate pair.
  • tools/check_conventions.py --base origin/main, tools/debt_fold.py --check and tools/env_reference.py --check pass.

No title run: no title on hand reaches these functions.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5396825436 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23723). Originally posted by [Dark3581](https://github.com/Dark3581) on 2026-11-19T14:30:14Z. --- ### What Implements `WTF::numGraphemeClusters(StringView)` and `WTF::numCodeUnitsInGraphemeClusters(StringView, unsigned)` in libSceNKWebKit. Both were throwing stubs in `Export.cpp`. - The code follows pinned [PS5 WebKit 11.x TextBreakIterator.cpp](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/text/TextBreakIterator.cpp#L178-L233). The two bodies are the same as WebKit c55364d53f97. - 8-bit strings take WebKit's Latin-1 path, where CR LF is the only cluster longer than one code unit. - 16-bit strings whose code units are all at most U+00FF take the same path. [UAX #29](https://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundary_Rules) gives them the same boundaries, because no Extend, SpacingMark, Prepend or ZWJ code point lies below U+0100. - A 16-bit string with any code unit above U+00FF throws through `NotImplemented_nid_no_patch`. That case needs the ICU character break iterator, and the bundled ICU has no break rule data. - Early returns match WebKit: an empty view gives 0, and a cluster count at or past the length returns the length without reading the buffer. A null buffer that must be read throws `std::invalid_argument`, as `CheckBuffer` does elsewhere in the library. - `StringView` is passed by value as the existing 16-byte `NKWebKit::WtfAbi::StringView`. Its copy constructor is user-provided only under `CHECK_STRINGVIEW_LIFETIME`. - The debt fragment removes the two inventory rows and adds a Functional entry for the 16-bit gap. `tools/pr_overlap.py --branch` failed closed on PR 23468 and PR 23475, which conflict with `main`. I compared them by hand. Each edits a stub next to these in `Export.cpp`/`InventoryExports.hpp` (only context lines match), and `--names` lists no open PR for either function. ### Tested Windows 10 22H2, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, on `main` 713cc62069 plus this commit. - `ctest -R "^(nkwebkit_|guest_nkwebkit)"`: 153 of 153 pass, including the new `nkwebkit_graphemeclusters`. - The new test covers: - both widths; - CR and LF runs (`\r\r\n`, `\n\r`, `\r\n\r\n`) and embedded nulls; - Latin-1 code units in 16-bit strings; - code unit counts below, at and past the string length; - null buffers; - the throwing path for a combining sequence and a surrogate pair. - `tools/check_conventions.py --base origin/main`, `tools/debt_fold.py --check` and `tools/env_reference.py --check` pass. No title run: no title on hand reaches these functions. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-19 14:32:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T14:32:51Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 3510ea7d5d:

  • Conventions: tools/check_conventions.py passed.
  • Build: nkwebkit_graphemeclusters_tests built cleanly.
  • CTest (nkwebkit_graphemeclusters):
    1/1 Test #4648: nkwebkit_graphemeclusters ........   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNKWebKit/Export.cpp, core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp, core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp, core/libs/prx/libSceNKWebKit/src/GraphemeClusters.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified numGraphemeClusters and numCodeUnitsInGraphemeClusters correctly handle null data pointers, empty strings, and stringLength <= numGraphemeClusters before memory access.
    • Verified RequireLatin1 and Latin1Unit access 8-bit and 16-bit buffers safely, throwing std::invalid_argument on null buffers when stringLength > 0 and calling NotImplemented_nid_no_patch for wide characters > 0xFF.
    • Verified loop boundary conditions and CRLF pairing logic in numGraphemeClusters and numCodeUnitsInGraphemeClusters against upstream WebKit TextBreakIterator.cpp.
    • Verified technical debt fragment format, removal of inventory rows, and strict adherence to AGENTS.md conventions (no disallowed comments, no forbidden files).
    • Verified C++20 type safety, return types, VABI macros, and LP64/LLP64 portability.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5976959407 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23723#pullrequestreview-5976959407). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-19T14:32:51Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `3510ea7d5d`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `nkwebkit_graphemeclusters_tests` built cleanly. - **CTest** (`nkwebkit_graphemeclusters`): ``` 1/1 Test #4648: nkwebkit_graphemeclusters ........ Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceNKWebKit/Export.cpp`, `core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp`, `core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp`, `core/libs/prx/libSceNKWebKit/src/GraphemeClusters.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified numGraphemeClusters and numCodeUnitsInGraphemeClusters correctly handle null data pointers, empty strings, and stringLength <= numGraphemeClusters before memory access. - Verified RequireLatin1 and Latin1Unit access 8-bit and 16-bit buffers safely, throwing std::invalid_argument on null buffers when stringLength > 0 and calling NotImplemented_nid_no_patch for wide characters > 0xFF. - Verified loop boundary conditions and CRLF pairing logic in numGraphemeClusters and numCodeUnitsInGraphemeClusters against upstream WebKit TextBreakIterator.cpp. - Verified technical debt fragment format, removal of inventory rows, and strict adherence to AGENTS.md conventions (no disallowed comments, no forbidden files). - Verified C++20 type safety, return types, VABI macros, and LP64/LLP64 portability. Looks Good To Me
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!23723
No description provided.