summaryrefslogtreecommitdiffstats
path: root/src/git_ignore.rs
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2019-10-07 21:34:04 +0200
committerCanop <cano.petrole@gmail.com>2019-10-07 21:34:04 +0200
commit1b5060a3fa7eccfa9fb5d675bcaff1d45a577581 (patch)
tree06afb203eb06642279fb318f29b5f07038ef5ffc /src/git_ignore.rs
parent1f56a940ec91aa17a35b48c569864559980a403e (diff)
use lazy-regex to slightly clean regex creation code
Diffstat (limited to 'src/git_ignore.rs')
-rw-r--r--src/git_ignore.rs23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/git_ignore.rs b/src/git_ignore.rs
index d0f1b6d..da48d43 100644
--- a/src/git_ignore.rs
+++ b/src/git_ignore.rs
@@ -20,22 +20,19 @@ struct GitIgnoreRule {
impl GitIgnoreRule {
fn from(line: &str, dir: &Path) -> Option<GitIgnoreRule> {
- lazy_static! {
- static ref RE: Regex = Regex::new(
- r"(?x)
- ^\s*
- (!)? # 1 : negation
- (.+?) # 2 : pattern
- (/)? # 3 : directory
- \s*$
- "
- )
- .unwrap();
- }
if line.starts_with('#') {
return None; // comment line
}
- if let Some(c) = RE.captures(line) {
+ let r = regex!(
+ r"(?x)
+ ^\s*
+ (!)? # 1 : negation
+ (.+?) # 2 : pattern
+ (/)? # 3 : directory
+ \s*$
+ "
+ );
+ if let Some(c) = r.captures(line) {
if let Some(p) = c.get(2) {
let mut p = p.as_str().to_string();
let has_separator = p.contains('/');