@@ -2,6 +2,27 @@ use ib_pinyin::{matcher::PinyinMatcher, pinyin::PinyinNotation};
2
2
use std:: env;
3
3
use std:: io:: { BufRead , BufReader } ;
4
4
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
+
5
26
fn parse_pinyin_notation_env ( ) -> PinyinNotation {
6
27
let env_val = env:: var ( "PINYIN_COMP_MODE" ) . unwrap_or_default ( ) ;
7
28
let mut notation = PinyinNotation :: empty ( ) ;
@@ -65,9 +86,13 @@ fn main() {
65
86
let stdin = std:: io:: stdin ( ) ;
66
87
let reader = BufReader :: new ( stdin. lock ( ) ) ;
67
88
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 ;
72
93
}
94
+ if matcher. is_match ( & candidate) {
95
+ println ! ( "{}" , candidate) ;
96
+ }
97
+ }
73
98
}
0 commit comments