@@ -3,8 +3,8 @@ bitflags! {
3
3
/// The match mode employed in [`Pattern::matches()`][crate::Pattern::matches()].
4
4
#[ cfg_attr( feature = "serde1" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
5
5
pub struct Mode : u8 {
6
- /// Let globs not match the slash `/` literal.
7
- const SLASH_IS_LITERAL = 1 << 0 ;
6
+ /// Let globs like `*` and `?` not match the slash `/` literal, which is useful when matching paths .
7
+ const NO_MATCH_SLASH_LITERAL = 1 << 0 ;
8
8
/// Match case insensitively for ascii characters only.
9
9
const IGNORE_CASE = 1 << 1 ;
10
10
}
@@ -65,22 +65,25 @@ pub(crate) mod function {
65
65
}
66
66
match p_ch {
67
67
b'?' => {
68
- if mode. contains ( Mode :: SLASH_IS_LITERAL ) && t_ch == SLASH {
68
+ if mode. contains ( Mode :: NO_MATCH_SLASH_LITERAL ) && t_ch == SLASH {
69
69
return NoMatch ;
70
70
} else {
71
71
continue ;
72
72
}
73
73
}
74
74
STAR => {
75
- let mut match_slash = mode. contains ( Mode :: SLASH_IS_LITERAL ) . then ( || false ) . unwrap_or ( true ) ;
75
+ let mut match_slash = mode
76
+ . contains ( Mode :: NO_MATCH_SLASH_LITERAL )
77
+ . then ( || false )
78
+ . unwrap_or ( true ) ;
76
79
match p. next ( ) {
77
80
Some ( ( next_p_idx, next_p_ch) ) => {
78
81
let next;
79
82
if next_p_ch == STAR {
80
83
let leading_slash_idx = p_idx. checked_sub ( 1 ) ;
81
84
while p. next_if ( |( _, c) | * c == STAR ) . is_some ( ) { }
82
85
next = p. next ( ) ;
83
- if !mode. contains ( Mode :: SLASH_IS_LITERAL ) {
86
+ if !mode. contains ( Mode :: NO_MATCH_SLASH_LITERAL ) {
84
87
match_slash = true ;
85
88
} else if leading_slash_idx. map_or ( true , |idx| pattern[ idx] == SLASH )
86
89
&& next. map_or ( true , |( _, c) | {
@@ -318,7 +321,7 @@ pub(crate) mod function {
318
321
break ;
319
322
}
320
323
}
321
- if matched == negated || mode. contains ( Mode :: SLASH_IS_LITERAL ) && t_ch == SLASH {
324
+ if matched == negated || mode. contains ( Mode :: NO_MATCH_SLASH_LITERAL ) && t_ch == SLASH {
322
325
return NoMatch ;
323
326
}
324
327
continue ;
0 commit comments