From 2a7a7768c6377d03cd59d5e7a661d89957e5868e Mon Sep 17 00:00:00 2001 From: Etienne Palanga Date: Wed, 8 May 2024 15:01:01 +0200 Subject: [PATCH] fix schmfy breaking on non ext-ascii characters --- src/lib.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a983d39..6bab142 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -116,17 +116,15 @@ pub fn schmfy(source: &str) -> String { // schmfy first char if word is no longer than 3 if source.len() <= 3 && case != CaseType::FstUcase { - let (prefix, suffix) = source.split_at(1); + let first_c_size = source.chars().next().unwrap().len_utf8(); + let (prefix, suffix) = source.split_at(first_c_size); let c = prefix.chars().next().unwrap_or('-'); return restore_case(schmfy_char(c) + suffix, case); } // Normal words - replace prefix before first vocal // with "schm" - let vok_pos = source - .chars() - .position(|c| "aeiouäöü".contains(c)) - .unwrap_or(0); + let vok_pos = source.find(|c| "aeiouäöü".contains(c)).unwrap_or(0); let (_, suffix) = source.split_at(vok_pos); @@ -245,8 +243,9 @@ This is a Markdown codebox | This | is | |---|---| | a | Markdown | -| table | ! |"), -" +| table | ! |" + ), + " ``` Schmis schmis schma Schmarkdown schmodebox ```