mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-14 08:57:30 +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> {
|
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)
|
let x = s.lines().skip(ignore_first as usize)
|
||||||
.map(|l| l.char_indices()
|
.filter_map(|l| { if l.len() > 0 { // ignore empty lines
|
||||||
.find(|&(_,x)| x != ch)
|
Some(l.char_indices()
|
||||||
.unwrap_or((l.len(), ch)).0)
|
.find(|&(_,x)| x != ch)
|
||||||
|
.unwrap_or((l.len(), ch)).0)
|
||||||
|
} else {None}})
|
||||||
.min().unwrap_or(0);
|
.min().unwrap_or(0);
|
||||||
if x > 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
|
l
|
||||||
} else {
|
} else {
|
||||||
l.split_at(x).1
|
l.split_at(x).1
|
||||||
|
|
Loading…
Reference in a new issue