Show More
@@ -171,6 +171,10 b' pub fn parse_pattern_syntax(' | |||
|
171 | 171 | } |
|
172 | 172 | } |
|
173 | 173 | |
|
174 | lazy_static! { | |
|
175 | static ref FLAG_RE: Regex = Regex::new(r"^\(\?[aiLmsux]+\)").unwrap(); | |
|
176 | } | |
|
177 | ||
|
174 | 178 | /// Builds the regex that corresponds to the given pattern. |
|
175 | 179 | /// If within a `syntax: regexp` context, returns the pattern, |
|
176 | 180 | /// otherwise, returns the corresponding regex. |
@@ -193,7 +197,22 b' fn _build_single_regex(entry: &IgnorePat' | |||
|
193 | 197 | { |
|
194 | 198 | return pattern.to_owned(); |
|
195 | 199 | } |
|
196 | [&b".*"[..], pattern].concat() | |
|
200 | match FLAG_RE.find(pattern) { | |
|
201 | Some(mat) => { | |
|
202 | let s = mat.start(); | |
|
203 | let e = mat.end(); | |
|
204 | [ | |
|
205 | &b"(?"[..], | |
|
206 | &pattern[s + 2..e - 1], | |
|
207 | &b":"[..], | |
|
208 | &b".*"[..], | |
|
209 | &pattern[e..], | |
|
210 | &b")"[..], | |
|
211 | ] | |
|
212 | .concat() | |
|
213 | } | |
|
214 | None => [&b".*"[..], pattern].concat(), | |
|
215 | } | |
|
197 | 216 | } |
|
198 | 217 | PatternSyntax::Path | PatternSyntax::RelPath => { |
|
199 | 218 | if pattern == b"." { |
@@ -703,4 +722,35 b' mod tests {' | |||
|
703 | 722 | Some(br"[^/]*\.o(?:/|$)".to_vec()), |
|
704 | 723 | ); |
|
705 | 724 | } |
|
725 | ||
|
726 | #[test] | |
|
727 | fn test_build_single_relregex() { | |
|
728 | assert_eq!( | |
|
729 | build_single_regex(&IgnorePattern::new( | |
|
730 | PatternSyntax::RelRegexp, | |
|
731 | b"^ba{2}r", | |
|
732 | Path::new("") | |
|
733 | )) | |
|
734 | .unwrap(), | |
|
735 | Some(b"^ba{2}r".to_vec()), | |
|
736 | ); | |
|
737 | assert_eq!( | |
|
738 | build_single_regex(&IgnorePattern::new( | |
|
739 | PatternSyntax::RelRegexp, | |
|
740 | b"ba{2}r", | |
|
741 | Path::new("") | |
|
742 | )) | |
|
743 | .unwrap(), | |
|
744 | Some(b".*ba{2}r".to_vec()), | |
|
745 | ); | |
|
746 | assert_eq!( | |
|
747 | build_single_regex(&IgnorePattern::new( | |
|
748 | PatternSyntax::RelRegexp, | |
|
749 | b"(?ia)ba{2}r", | |
|
750 | Path::new("") | |
|
751 | )) | |
|
752 | .unwrap(), | |
|
753 | Some(b"(?ia:.*ba{2}r)".to_vec()), | |
|
754 | ); | |
|
755 | } | |
|
706 | 756 | } |
General Comments 0
You need to be logged in to leave comments.
Login now