From 7ac0d4b5e5af6503324b84fcdfd63e4618b1bdc6 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Mon, 11 Apr 2022 20:10:29 +0800 Subject: [PATCH] Fix incorrect format when leading with letter or number. #21 --- autocorrect/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/autocorrect/src/lib.rs b/autocorrect/src/lib.rs index c610692c..b1b60d8c 100644 --- a/autocorrect/src/lib.rs +++ b/autocorrect/src/lib.rs @@ -116,9 +116,11 @@ lazy_static! { // Strategies all rules static ref STRATEGIES: Vec = vec![ // EnglishLetter, Number - // But not start with %, $, \ for avoid change %s, %d, $1, $2, \1, \2, \d, \r, \p ... in source code + // Avoid add space when Letter, Number has %, $, \ prefix, eg. %s, %d, $1, $2, \1, \2, \d, \r, \p ... in source code Strategery::new(r"\p{CJK}[^%\$\\]", r"[a-zA-Z0-9]"), - Strategery::new(r"[a-zA-Z0-9]", r"\p{CJK}"), + Strategery::new(r"[^%\$\\][a-zA-Z0-9]", r"\p{CJK}"), + // Spcial format Letter, Number leading case, because the before Strategery can't cover eg. A开头的case测试 + Strategery::new(r"^[a-zA-Z0-9]", r"\p{CJK}"), // 10%中文 Strategery::new(r"[0-9][%]", r"\p{CJK}"), // SpecialSymbol