mirror of
https://github.com/storytold/figcraft.git
synced 2026-10-28 12:26:52 -06:00
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 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
9ec80bf2c2
commit
ddeceb17b3
+17
-1
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user