Skip to content

feat: add PHP mb_convert_case and MB_CASE_* constants - #902

Open
nahime0 wants to merge 14 commits into
mainfrom
cursor/mb-convert-case-63da
Open

feat: add PHP mb_convert_case and MB_CASE_* constants#902
nahime0 wants to merge 14 commits into
mainfrom
cursor/mb-convert-case-63da

Conversation

@nahime0

@nahime0 nahime0 commented Sep 5, 2026

Copy link
Copy Markdown
Member

Summary

Adds PHP 8.5 mb_convert_case() and the MB_CASE_* constants on both the AOT backend and Magician/eval. Termwind Styles capitalize calls mb_convert_case(..., MB_CASE_TITLE, 'UTF-8').

This change covers only mb_convert_case plus the eight MB_CASE_* modes. It does not add mb_strwidth, mb_strimwidth, mb_strtoupper, or mb_strtolower.

Behavior

  • Signature: mb_convert_case(string $string, int $mode, ?string $encoding = null): string
  • Modes: MB_CASE_UPPER/LOWER/TITLE/FOLD and the *_SIMPLE variants (0..=7)
  • Title case follows PHP 8.5 Cased / Case_Ignorable state (apostrophe stays inside the word: "don't""Don't")
  • Full mappings may expand (ßSS / title Ss / fold ss); simple mappings stay 1:1
  • Greek final sigma applies to MB_CASE_LOWER and MB_CASE_TITLE only
  • Omitted/null/UTF-8/UTF8 convert Unicode; 8bit/binary/7bit treat bytes as U+00xx; other names go through iconv
  • Invalid mode or encoding raises catchable ValueError

Implementation

  • Shared builtin contract + AOT builtin! home file
  • Magician eval_builtin! with the same convert algorithm
  • AOT __rt_mb_convert_case on linux-x86_64 and AArch64, gated by RuntimeFeatures
  • Generated Unicode tables from Rust char mappings plus Unicode 16 Case_Ignorable ranges
  • map_len and the emit index are packed 32-bit stack slots so they do not overlap

Tests and docs

  • Codegen, error, eval-parity, Magician, and registry metadata tests
  • examples/string-ops, docs/php/strings.md, docs/php/namespaces.md, ROADMAP, and generated builtin pages

Focused host verification (linux-x86_64): AOT title/modes/encoding tests, eval parity, error tests, and the string-ops Case example all pass. CI covers the remaining supported-target matrix.

Open in Web Open in Cursor 

cursoragent and others added 7 commits September 5, 2026 10:20
Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Declare the PHP 8.5 signature in the shared builtin catalog, add the
AOT checker home file, and implement Magician/eval with UTF-8 title
case, final sigma, and iconv encodings.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Add the shared AOT case-mapping tables, Case_Ignorable ranges, and
titlecase/final-sigma helpers used to emit the runtime convert tables.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Lower mb_convert_case through RuntimeFnId, gate __rt_mb_convert_case
on both supported targets, and convert UTF-8/8bit/iconv encodings
with the PHP 8.5 MB_CASE_* tables.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Full fold expands ß and alphabetic ligatures instead of reusing
lowercase, matching PHP 8.5 on AOT and Magician.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Add codegen, eval-parity, Magician, metadata, and type/arity tests
for title case, all MB_CASE_* modes, encodings, and ValueErrors.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Add the PHP 8.5 signature, title-case example, predefined constants,
string-ops demo, and a delivered ROADMAP item.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
@github-actions github-actions Bot added area:codegen Touches target-aware assembly or backend lowering. area:magician Touches eval, include execution, or elephc-magician. area:runtime Touches runtime helpers, GC, ownership, or bridge runtimes. scope:multi-area Touches more compiler areas than the automatic area-label cap. size:l Large pull request. target:linux-x86_64 Contains behavior specific to the Linux x86_64 target. type:feature Introduces new user-visible behavior or capabilities. labels Sep 5, 2026
Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
@github-actions github-actions Bot added size:xl Very large pull request that needs deliberate review planning. and removed size:l Large pull request. labels Sep 5, 2026
cursoragent and others added 3 commits September 5, 2026 10:45
Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Title-casing "hié" correctly leaves the trailing é lowercase, so
the latin1 check now verifies UPPER maps 0xE9 to 0xC9.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
A 64-bit map_len at rbp-232 shared four bytes with the emit index at
rbp-228, so incrementing the index inflated the length and SIGSEGV'd
on the next mapped-code load.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
@nahime0
nahime0 marked this pull request as ready for review September 5, 2026 10:53
@greptile-apps

greptile-apps Bot commented Sep 5, 2026

Copy link
Copy Markdown

Too many files changed for review (298 files, 100 file limit).

Bypass the limit by tagging @greptile-apps to review.

cursoragent and others added 3 commits September 5, 2026 14:45
AArch64 apply/sigma-ahead nested bl clobbered the convert-loop
return address and hung. x86_64 frameless entries now pad rsp so
the System V call-alignment audit stays green.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:codegen Touches target-aware assembly or backend lowering. area:magician Touches eval, include execution, or elephc-magician. area:runtime Touches runtime helpers, GC, ownership, or bridge runtimes. scope:multi-area Touches more compiler areas than the automatic area-label cap. size:xl Very large pull request that needs deliberate review planning. target:linux-x86_64 Contains behavior specific to the Linux x86_64 target. type:feature Introduces new user-visible behavior or capabilities.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants