From ddeceb17b34f05e599170930ca7dcfe3f96bb97e Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:36:45 +0000 Subject: [PATCH] Capitalise title-case word after an opening apostrophe Found while testing crates/doc/src/text.rs:138 (TextCase::apply_after; is_word_char at :153 counts ' and U+2019 as word characters) Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/doc/src/text.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/doc/src/text.rs b/crates/doc/src/text.rs index 458426ad..15e284bc 100644 --- a/crates/doc/src/text.rs +++ b/crates/doc/src/text.rs @@ -129,14 +129,17 @@ impl TextCase { TextCase::Title => { let mut out = String::with_capacity(s.len()); let mut start = prev.is_none_or(|c| !is_word_char(c)); + let mut before = prev; for ch in s.chars() { if start && ch.is_alphanumeric() { out.extend(ch.to_uppercase()); start = false; } else { out.push(ch); - start = !is_word_char(ch); + // An apostrophe only continues a word right after a letter or digit. + start = !is_word_char(ch) || (!ch.is_alphanumeric() && !before.is_some_and(|c| c.is_alphanumeric())); } + before = Some(ch); } out } @@ -831,3 +834,16 @@ mod case_tests { assert_eq!(t.para_list(0), ParaList::default()); } } + +#[cfg(test)] +mod title_case_tests { + use super::TextCase; + + #[test] + fn title_case_after_opening_apostrophe() { + assert_eq!(TextCase::Title.apply("'hello world'"), "'Hello World'"); + assert_eq!(TextCase::Title.apply("say 'hi'"), "Say 'Hi'"); + assert_eq!(TextCase::Title.apply("don't"), "Don't"); + assert_eq!(TextCase::Title.apply("\u{2019}hello"), "\u{2019}Hello"); + } +}