mirror of
https://github.com/chmln/sd
synced 2024-10-14 19:42:24 +00:00
rustfmt and cleanup
This commit is contained in:
parent
6a31294da8
commit
d225a9024e
|
@ -1,8 +1,6 @@
|
|||
edition = "2018"
|
||||
max_width = 80
|
||||
wrap_comments = true
|
||||
control_brace_style = "ClosingNextLine"
|
||||
brace_style = "PreferSameLine"
|
||||
format_strings = true
|
||||
merge_imports = true
|
||||
match_block_trailing_comma = true
|
||||
|
|
|
@ -18,6 +18,7 @@ jobs:
|
|||
parameters:
|
||||
name: rustfmt
|
||||
displayName: Check formatting
|
||||
rust_version: nightly
|
||||
|
||||
# This represents the minimum Rust version supported.
|
||||
# Tests are not run as tests may require newer versions of rust.
|
||||
|
@ -86,5 +87,4 @@ jobs:
|
|||
github:
|
||||
gitHubConnection: githubConnection
|
||||
repositoryName: chmln/sd
|
||||
isPreRelease: true
|
||||
|
||||
|
|
22
src/input.rs
22
src/input.rs
|
@ -31,8 +31,7 @@ impl Replacer {
|
|||
) -> Result<Self> {
|
||||
let (look_for, replace_with) = if is_literal {
|
||||
(regex::escape(&look_for), replace_with.into_bytes())
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
(
|
||||
look_for,
|
||||
utils::unescape(&replace_with)
|
||||
|
@ -48,20 +47,20 @@ impl Replacer {
|
|||
match c {
|
||||
'c' => {
|
||||
regex.case_insensitive(false);
|
||||
},
|
||||
}
|
||||
'i' => {
|
||||
regex.case_insensitive(true);
|
||||
},
|
||||
}
|
||||
'm' => {
|
||||
regex.multi_line(true);
|
||||
},
|
||||
}
|
||||
'w' => {
|
||||
regex = regex::bytes::RegexBuilder::new(&format!(
|
||||
"\\b{}\\b",
|
||||
look_for
|
||||
));
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
@ -83,8 +82,7 @@ impl Replacer {
|
|||
&content,
|
||||
regex::bytes::NoExpand(&self.replace_with),
|
||||
)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
self.regex.replace_all(&content, &*self.replace_with)
|
||||
}
|
||||
}
|
||||
|
@ -130,7 +128,7 @@ impl Replacer {
|
|||
handle.write_all(&self.replace(&buffer))?;
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
(Source::Files(paths), true) => {
|
||||
use rayon::prelude::*;
|
||||
|
||||
|
@ -139,7 +137,7 @@ impl Replacer {
|
|||
.map(|p| self.replace_file(p).map_err(Error::log))
|
||||
.collect::<Vec<Result<()>>>();
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
(Source::Files(paths), false) => {
|
||||
let stdout = std::io::stdout();
|
||||
let mut handle = stdout.lock();
|
||||
|
@ -154,7 +152,7 @@ impl Replacer {
|
|||
})
|
||||
.collect::<Result<Vec<()>>>()?;
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue