mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-13 08:27:14 +00:00
trim_multiline: ignore empty lines
This commit is contained in:
parent
dece5a6cb5
commit
5ce8e7ba85
1 changed files with 7 additions and 4 deletions
11
src/utils.rs
11
src/utils.rs
|
@ -70,12 +70,15 @@ pub fn trim_multiline<'a>(s: Cow<'a, str>, ignore_first: bool) -> Cow<'a, str> {
|
|||
|
||||
fn trim_multiline_inner<'a>(s: Cow<'a, str>, ignore_first: bool, ch: char) -> Cow<'a, str> {
|
||||
let x = s.lines().skip(ignore_first as usize)
|
||||
.map(|l| l.char_indices()
|
||||
.find(|&(_,x)| x != ch)
|
||||
.unwrap_or((l.len(), ch)).0)
|
||||
.filter_map(|l| { if l.len() > 0 { // ignore empty lines
|
||||
Some(l.char_indices()
|
||||
.find(|&(_,x)| x != ch)
|
||||
.unwrap_or((l.len(), ch)).0)
|
||||
} else {None}})
|
||||
.min().unwrap_or(0);
|
||||
if x > 0 {
|
||||
Cow::Owned(s.lines().enumerate().map(|(i,l)| if ignore_first && i==0 {
|
||||
Cow::Owned(s.lines().enumerate().map(|(i,l)| if (ignore_first && i == 0) ||
|
||||
l.len() == 0 {
|
||||
l
|
||||
} else {
|
||||
l.split_at(x).1
|
||||
|
|
Loading…
Reference in a new issue