feat(libSceNKWebKit): implement WTF string case mapping, foldCase and normalizedNFC #18391

Merged
SHOnnay merged 6 commits from upstream-pr/18391 into main 2026-11-14 11:49:58 +00:00
SHOnnay commented 2026-11-11 13:20:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SHOnnay on 2026-11-11T13:20:18Z.


What

Implements 13 libSceNKWebKit exports that threw:

  • WTF::StringImpl:
    • convertToLowercaseWithoutLocale
    • convertToUppercaseWithoutLocale
    • convertToLowercaseWithoutLocaleStartingAtFailingIndex8Bit(unsigned)
    • convertToLowercaseWithLocale(const AtomString&)
    • convertToUppercaseWithLocale(const AtomString&)
  • WTF::String: the same five, plus foldCase.
  • WTF::normalizedNFC: the StringView and const String& overloads.

Source. Ported from pinned WebKit c55364d53f97:

  • StringImpl.cpp L351-689
  • WTFString.cpp L340-412
  • StringView.cpp L277-312

These declarations match the mangled parameter lists. The case-mapping code is identical in the PS5-WebKit-11.x revision this library also cites.

Behaviour.

  • ASCII and Latin-1 fast paths are ported as written.
  • Non-ASCII text goes through this repo's libSceIcu exports, all already implemented:
    • u_strToLower, u_strToUpper, u_strFoldCase
    • u_tolower, u_toupper, u_foldCase
    • unorm2_getNFCInstance, unorm2_isNormalized, unorm2_normalize
  • libSceNKWebKit already links libSceIcu.

Placement. The code is in a new src/WtfStringIcu.cpp, because nkwebkit_wtftext_allocation links WtfString.cpp with libc only.

Allocation. New strings come from the module's existing NewImpl, exposed as WtfAbi::CreateUninitialized. Paths that return this add a reference the way the existing code does.

ABI. StringViewWithUnderlyingString, 24 bytes, is added to WtfStringAbi.hpp with static asserts.

Debt file. The 13 stubs and placeholder declarations are removed. The debt count drops from 6000 to 5987 and the 13 table rows are removed. One debt entry records three things:

  • The AtomString/StringViewWithUnderlyingString ABI follows the pinned headers.
  • The libSceIcu Unicode version may differ from the console's.
  • Where WebKit only asserts, this code throws: null arguments, a failing index past the end or on a 16-bit string, and normalizer errors.

Left throwing:

  • String::simplifyWhiteSpace(CodeUnitMatchFunction): open in #16890.
  • String::number(double/float) and numberToStringFixed*: open in #14259.
  • MediaTime::toString: depends on #14259's formatting.
  • StringImpl::adopt(StringBuffer): StringBuffer is not modelled.

Tested

macOS 27 on Apple M1. The registered nkwebkit_* tests are full-build tests and were not run: the full build does not run on macOS. A Linux or Windows run is needed.

Harness. Five new test functions in tests/WtfText.cpp use expectations worked out by hand from Unicode case and normalization rules. A temporary host harness, not committed, compiled the whole of tests/WtfText.cpp with the unchanged production files:

  • WtfString.cpp
  • WtfStringIcu.cpp
  • StringBuilder.cpp, StringBuilderJSON.cpp
  • WtfNumberFormat.cpp
  • TextStream.cpp

Results:

  • x86-64 under Rosetta: all 14 test functions passed.
  • libSceIcu substitute: the harness forwarded the libSceIcu entry points to the system ICU (libicucore). libSceIcu wraps the ICU sources, which the harness could not include without the submodule, so the Unicode tables used may differ from libSceIcu's ICU version.
  • arm64: not built. The existing static_assert in libc/include/GuestLongDouble.hpp fails there; this change does not cause it.
  • Mutation check: 11 of 12 hand mutations failed the harness. The survivor drops realLength == length from the first-pass check. Its behaviour is equivalent, because ICU always reports overflow when the result is longer.

Syntax. clang++ -arch x86_64 -fsyntax-only passes on these files:

  • WtfStringIcu.cpp, WtfString.cpp, Export.cpp
  • tests/WtfText.cpp, tests/Wtf.cpp, tests/WtfTextAllocation.cpp
$ python3 tools/check_conventions.py --base upstream/main
All conventions checks passed.
$ python3 core/libs/tests/test_public_headers.py --audit-only
407 libraries, 34229 exports: unique declarations and umbrella coverage verified

Overlap. pr_overlap.py found no shared exports among the pull requests it could merge. It could not compare 59 that conflict with main. None of their diffs names any of these exports, the new file or the new helper; #15853 only matches the existing TryCreateUninitialized. gh pr list searches for the case-mapping names and normalizedNFC found nothing.

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
  • 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 (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5260215848 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18391). Originally posted by [SHOnnay](https://github.com/SHOnnay) on 2026-11-11T13:20:18Z. --- ### What Implements 13 libSceNKWebKit exports that threw: - **`WTF::StringImpl`:** - `convertToLowercaseWithoutLocale` - `convertToUppercaseWithoutLocale` - `convertToLowercaseWithoutLocaleStartingAtFailingIndex8Bit(unsigned)` - `convertToLowercaseWithLocale(const AtomString&)` - `convertToUppercaseWithLocale(const AtomString&)` - **`WTF::String`:** the same five, plus `foldCase`. - **`WTF::normalizedNFC`:** the `StringView` and `const String&` overloads. **Source.** Ported from pinned WebKit [`c55364d53f97`](https://github.com/WebKit/WebKit/tree/c55364d53f971f63a709976f168d932d558b8909): - StringImpl.cpp L351-689 - WTFString.cpp L340-412 - StringView.cpp L277-312 These declarations match the mangled parameter lists. The case-mapping code is identical in the [PS5-WebKit-11.x](https://github.com/neonmodder123/PS5-WebKit-11.x/tree/80f77e94c63ee7202eec3d4b5b1a021dd89011ba) revision this library also cites. **Behaviour.** - ASCII and Latin-1 fast paths are ported as written. - Non-ASCII text goes through this repo's libSceIcu exports, all already implemented: - `u_strToLower`, `u_strToUpper`, `u_strFoldCase` - `u_tolower`, `u_toupper`, `u_foldCase` - `unorm2_getNFCInstance`, `unorm2_isNormalized`, `unorm2_normalize` - libSceNKWebKit already links libSceIcu. **Placement.** The code is in a new `src/WtfStringIcu.cpp`, because `nkwebkit_wtftext_allocation` links `WtfString.cpp` with libc only. **Allocation.** New strings come from the module's existing `NewImpl`, exposed as `WtfAbi::CreateUninitialized`. Paths that return `this` add a reference the way the existing code does. **ABI.** `StringViewWithUnderlyingString`, 24 bytes, is added to `WtfStringAbi.hpp` with static asserts. **Debt file.** The 13 stubs and placeholder declarations are removed. The debt count drops from 6000 to 5987 and the 13 table rows are removed. One debt entry records three things: - The `AtomString`/`StringViewWithUnderlyingString` ABI follows the pinned headers. - The libSceIcu Unicode version may differ from the console's. - Where WebKit only asserts, this code throws: null arguments, a failing index past the end or on a 16-bit string, and normalizer errors. **Left throwing:** - `String::simplifyWhiteSpace(CodeUnitMatchFunction)`: open in #16890. - `String::number(double/float)` and `numberToStringFixed*`: open in #14259. - `MediaTime::toString`: depends on #14259's formatting. - `StringImpl::adopt(StringBuffer)`: `StringBuffer` is not modelled. ### Tested macOS 27 on Apple M1. The registered `nkwebkit_*` tests are full-build tests and were **not run**: the full build does not run on macOS. A Linux or Windows run is needed. **Harness.** Five new test functions in `tests/WtfText.cpp` use expectations worked out by hand from Unicode case and normalization rules. A temporary host harness, not committed, compiled the whole of `tests/WtfText.cpp` with the unchanged production files: - `WtfString.cpp` - `WtfStringIcu.cpp` - `StringBuilder.cpp`, `StringBuilderJSON.cpp` - `WtfNumberFormat.cpp` - `TextStream.cpp` Results: - **x86-64 under Rosetta:** all 14 test functions passed. - **libSceIcu substitute:** the harness forwarded the libSceIcu entry points to the system ICU (`libicucore`). libSceIcu wraps the ICU sources, which the harness could not include without the submodule, so the Unicode tables used may differ from libSceIcu's ICU version. - **arm64:** not built. The existing `static_assert` in `libc/include/GuestLongDouble.hpp` fails there; this change does not cause it. - **Mutation check:** 11 of 12 hand mutations failed the harness. The survivor drops `realLength == length` from the first-pass check. Its behaviour is equivalent, because ICU always reports overflow when the result is longer. **Syntax.** `clang++ -arch x86_64 -fsyntax-only` passes on these files: - `WtfStringIcu.cpp`, `WtfString.cpp`, `Export.cpp` - `tests/WtfText.cpp`, `tests/Wtf.cpp`, `tests/WtfTextAllocation.cpp` ```text $ python3 tools/check_conventions.py --base upstream/main All conventions checks passed. $ python3 core/libs/tests/test_public_headers.py --audit-only 407 libraries, 34229 exports: unique declarations and umbrella coverage verified ``` **Overlap.** `pr_overlap.py` found no shared exports among the pull requests it could merge. It could not compare 59 that conflict with `main`. None of their diffs names any of these exports, the new file or the new helper; #15853 only matches the existing `TryCreateUninitialized`. `gh pr list` searches for the case-mapping names and `normalizedNFC` found nothing. ### 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) - [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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
PrivacyOnion commented 2026-11-11 17:25:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-11T17:25:33Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 26036c540d:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: nkwebkit_wtftext_tests built cleanly.
  • CTest (nkwebkit_wtftext, nkwebkit_wtftext_allocation):
    1/2 Test #3728: nkwebkit_wtftext_allocation ......***Not Run   0.00 sec
    2/2 Test #3724: nkwebkit_wtftext .................   Passed    0.03 sec
    50% tests passed, 1 tests failed out of 2
    
    The following tests FAILED:
    
  • Minor: please drop the Generated with footer from the description; the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5862761051 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18391#pullrequestreview-5862761051). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-11T17:25:33Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `26036c540d`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `nkwebkit_wtftext_tests` built cleanly. - **CTest** (`nkwebkit_wtftext`, `nkwebkit_wtftext_allocation`): ``` 1/2 Test #3728: nkwebkit_wtftext_allocation ......***Not Run 0.00 sec 2/2 Test #3724: nkwebkit_wtftext ................. Passed 0.03 sec 50% tests passed, 1 tests failed out of 2 ``` ``` The following tests FAILED: ``` - Minor: please drop the `Generated with` footer from the description; the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-11 18:35:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-11T18:35:54Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 26036c540d:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: nkwebkit_wtftext_tests built cleanly.
  • CTest (nkwebkit_wtftext, nkwebkit_wtftext_allocation):
    1/2 Test #3728: nkwebkit_wtftext_allocation ......   Passed    0.02 sec
    2/2 Test #3724: nkwebkit_wtftext .................   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libSceNKWebKit/Export.cpp, core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp, core/libs/prx/libSceNKWebKit/include/WtfExports.hpp, core/libs/prx/libSceNKWebKit/src/WtfString.cpp, core/libs/prx/libSceNKWebKit/src/WtfStringAbi.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified pointer safety and bounds validation in core/libs/prx/libSceNKWebKit/src/WtfStringIcu.cpp: Self, Impl, NeedsTurkishCasingRules, and NormalizedNFC correctly validate caller pointers against nullptr and reject null character buffers with non-zero lengths via std::invalid_argument, while CheckedLength guards against std::int32_t overflow.
    • Verified Latin-1 and ASCII fast-paths in LowercaseWithoutLocale, UppercaseWithoutLocale, and FoldCase in WtfStringIcu.cpp, confirming correct handling of length expansion for German sharp S (0xDF -> 'SS' / 'ss'), 16-bit upconversion triggers for 0xFF and 0xB5, and reference retaining via Retained(impl) with refCount += 2.
    • Verified libSceIcu integration across MapWithLocale, FoldCase, and NormalizedNFC against u_strToLower_nid_postfix, u_strToUpper_nid_postfix, u_strFoldCase_nid_postfix, unorm2_getNFCInstance_nid_postfix, unorm2_isNormalized_nid_postfix, and unorm2_normalize_nid_postfix, ensuring two-pass allocation handles buffer expansion and ICU status checks properly distinguish warnings (<= 0) from errors (> 0).
    • Verified Turkish and Azeri locale handling in NeedsTurkishCasingRules and TurkishCase, confirming correct case-insensitive tag prefix parsing ('tr', 'az', 'TR-tr') and Contains(impl, 'i') conditional bypass for uppercase mapping matching WebKit specifications.
    • Verified ABI conformity in core/libs/prx/libSceNKWebKit/src/WtfStringAbi.hpp and WtfExports.hpp, ensuring StringViewWithUnderlyingString matches the 24-byte layout (view at offset 0, underlyingString at offset 16), String copy constructor preserves reference count increments, and all 13 exports adhere to APS5_VABI calling conventions.
    • Verified AGENTS.md repository compliance, confirming zero forbidden code comments, complete removal of NotImplemented_nid_no_patch stubs and debt table rows with corresponding technical debt documentation in docs/dev/debt/libSceNKWebKit.md, and comprehensive test coverage across 5 test suites in tests/WtfText.cpp.
  • Minor: please drop the Generated with footer from the description; the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5863693715 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18391#pullrequestreview-5863693715). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-11T18:35:54Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `26036c540d`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `nkwebkit_wtftext_tests` built cleanly. - **CTest** (`nkwebkit_wtftext`, `nkwebkit_wtftext_allocation`): ``` 1/2 Test #3728: nkwebkit_wtftext_allocation ...... Passed 0.02 sec 2/2 Test #3724: nkwebkit_wtftext ................. Passed 0.02 sec 100% tests passed, 0 tests failed out of 2 ``` - **Negative control**: with `core/libs/prx/libSceNKWebKit/Export.cpp`, `core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp`, `core/libs/prx/libSceNKWebKit/include/WtfExports.hpp`, `core/libs/prx/libSceNKWebKit/src/WtfString.cpp`, `core/libs/prx/libSceNKWebKit/src/WtfStringAbi.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified pointer safety and bounds validation in core/libs/prx/libSceNKWebKit/src/WtfStringIcu.cpp: Self, Impl, NeedsTurkishCasingRules, and NormalizedNFC correctly validate caller pointers against nullptr and reject null character buffers with non-zero lengths via std::invalid_argument, while CheckedLength guards against std::int32_t overflow. - Verified Latin-1 and ASCII fast-paths in LowercaseWithoutLocale, UppercaseWithoutLocale, and FoldCase in WtfStringIcu.cpp, confirming correct handling of length expansion for German sharp S (0xDF -> 'SS' / 'ss'), 16-bit upconversion triggers for 0xFF and 0xB5, and reference retaining via Retained(impl) with refCount += 2. - Verified libSceIcu integration across MapWithLocale, FoldCase, and NormalizedNFC against u_strToLower_nid_postfix, u_strToUpper_nid_postfix, u_strFoldCase_nid_postfix, unorm2_getNFCInstance_nid_postfix, unorm2_isNormalized_nid_postfix, and unorm2_normalize_nid_postfix, ensuring two-pass allocation handles buffer expansion and ICU status checks properly distinguish warnings (<= 0) from errors (> 0). - Verified Turkish and Azeri locale handling in NeedsTurkishCasingRules and TurkishCase, confirming correct case-insensitive tag prefix parsing ('tr', 'az', 'TR-tr') and Contains(impl, 'i') conditional bypass for uppercase mapping matching WebKit specifications. - Verified ABI conformity in core/libs/prx/libSceNKWebKit/src/WtfStringAbi.hpp and WtfExports.hpp, ensuring StringViewWithUnderlyingString matches the 24-byte layout (view at offset 0, underlyingString at offset 16), String copy constructor preserves reference count increments, and all 13 exports adhere to APS5_VABI calling conventions. - Verified AGENTS.md repository compliance, confirming zero forbidden code comments, complete removal of NotImplemented_nid_no_patch stubs and debt table rows with corresponding technical debt documentation in docs/dev/debt/libSceNKWebKit.md, and comprehensive test coverage across 5 test suites in tests/WtfText.cpp. - Minor: please drop the `Generated with` footer from the description; the AI-assisted checkbox can stay. 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!18391
No description provided.