Skip to content

Titlecase the first-of-word code point without leading adjustment#8241

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowone:titlecase
Jul 8, 2026
Merged

Titlecase the first-of-word code point without leading adjustment#8241
youknowone merged 1 commit into
RustPython:mainfrom
youknowone:titlecase

Conversation

@youknowone

@youknowone youknowone commented Jul 8, 2026

Copy link
Copy Markdown
Member

case::title_wtf8 / capitalize_wtf8 pass a single first-of-word code point to
TitlecaseMapper::titlecase_segment. Under the default LeadingAdjustment::Auto
the mapper looks for a head in Letter | Number | Symbol | Private_Use and skips
anything else, which drops the titlecase mapping of cased marks such as
U+0345 COMBINING GREEK YPOGEGRAMMENI, whose titlecase is U+0399:

>>> 'ͅ'.title()   # CPython
'Ι'

The crate returned 'ͅ' unchanged instead.

These helpers always pass a single first-of-word code point, which Python
titlecases unconditionally (applying its titlecase mapping). Switch to
LeadingAdjustment::None so the code point is titlecased directly. Full
(one-to-many) mappings still apply to word starts (Fi, dzDz, ßSs).
Added a regression test.

authored with Claude

Summary by CodeRabbit

  • Bug Fixes

    • Improved titlecasing for words that start with leading combining marks, making capitalization more consistent across edge cases.
  • Tests

    • Added a unit test to verify that the first cased character in a titlecased word uses its correct titlecase mapping, including cases with leading combining marks and per-word first-character behavior.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 19c7da4b-3521-4c53-a855-6618940c1511

📥 Commits

Reviewing files that changed from the base of the PR and between 978ffc1 and 22a899f.

📒 Files selected for processing (1)
  • crates/unicode/src/case.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/unicode/src/case.rs

📝 Walkthrough

Walkthrough

crates/unicode/src/case.rs now passes explicit ICU titlecasing options with leading_adjustment set to LeadingAdjustment::None in titlecase_segment. A unit test was added for leading cased combining marks and word-initial titlecasing cases.

Changes

Titlecase Segment Behavior Update

Layer / File(s) Summary
Explicit leading adjustment option and test coverage
crates/unicode/src/case.rs
Imports LeadingAdjustment and TitlecaseOptions, configures titlecase_segment to use LeadingAdjustment::None instead of default options, and adds a test verifying titlecasing behavior for leading cased combining marks and word-initial characters.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: ShaharNaveh

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: titlecasing the first word code point without ICU leading adjustment.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

case::{title,capitalize}_wtf8 pass a single first-of-word code point to
TitlecaseMapper::titlecase_segment. Under the default Auto leading
adjustment the mapper looks for a Letter/Number/Symbol/Private_Use head
and skips anything else, dropping the titlecase mapping of cased marks
such as U+0345 (COMBINING GREEK YPOGEGRAMMENI) -> U+0399: 'ͅ'.title()
returned 'ͅ' instead of 'Ι'. Use LeadingAdjustment::None so the
given code point is titlecased directly, matching CPython str.title and
str.capitalize.

Assisted-by: Claude
@youknowone youknowone merged commit 5c36d5c into RustPython:main Jul 8, 2026
26 checks passed
@youknowone youknowone deleted the titlecase branch July 8, 2026 16:38
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