@@ -2,6 +2,27 @@ use ib_pinyin::{matcher::PinyinMatcher, pinyin::PinyinNotation};
22use std:: env;
33use std:: io:: { BufRead , BufReader } ;
44
5+ fn is_pure_english_path ( s : & str ) -> bool {
6+ // Consider a path "pure English" if every character is within a conservative
7+ // ASCII set that bash already handles well: letters, digits, '_', '-', '.', '/', '~'.
8+ // We also ignore trailing newlines/spaces (already trimmed).
9+ // Require at least one ASCII alphabetic letter so an empty string or just symbols
10+ // doesn't get suppressed accidentally.
11+ let mut has_alpha = false ;
12+ for ch in s. chars ( ) {
13+ if ch. is_ascii_alphabetic ( ) {
14+ has_alpha = true ;
15+ continue ;
16+ }
17+ if ch. is_ascii_digit ( ) || matches ! ( ch, '_' | '-' | '.' | '/' | '~' ) {
18+ continue ;
19+ }
20+ // Any other (non ASCII or other punctuation) means it's not pure English.
21+ return false ;
22+ }
23+ has_alpha
24+ }
25+
526fn parse_pinyin_notation_env ( ) -> PinyinNotation {
627 let env_val = env:: var ( "PINYIN_COMP_MODE" ) . unwrap_or_default ( ) ;
728 let mut notation = PinyinNotation :: empty ( ) ;
@@ -65,9 +86,13 @@ fn main() {
6586 let stdin = std:: io:: stdin ( ) ;
6687 let reader = BufReader :: new ( stdin. lock ( ) ) ;
6788 for line_result in reader. lines ( ) {
68- let candidate = line_result. unwrap ( ) . trim_end ( ) . to_string ( ) ;
69- if matcher . is_match ( & candidate ) {
70- println ! ( "{}" , candidate) ;
71- }
89+ let candidate = line_result. unwrap ( ) . trim_end ( ) . to_string ( ) ;
90+ // Ignore Pure English Path
91+ if is_pure_english_path ( & candidate) {
92+ continue ;
7293 }
94+ if matcher. is_match ( & candidate) {
95+ println ! ( "{}" , candidate) ;
96+ }
97+ }
7398 }
0 commit comments