1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

Merge pull request #2386 from youknowone/dircolors-double-scan

Prevent double scanning from dircolors
This commit is contained in:
Sylvestre Ledru 2021-06-21 22:31:24 +02:00 committed by GitHub
commit a982030032
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -192,21 +192,25 @@ pub trait StrUtils {
impl StrUtils for str { impl StrUtils for str {
fn purify(&self) -> &Self { fn purify(&self) -> &Self {
let mut line = self; let mut line = self;
for (n, c) in self.chars().enumerate() { for (n, _) in self
if c != '#' { .as_bytes()
continue; .iter()
} .enumerate()
.filter(|(_, c)| **c == b'#')
// Ignore if '#' is at the beginning of line {
if n == 0 {
line = &self[..0];
break;
}
// Ignore the content after '#' // Ignore the content after '#'
// only if it is preceded by at least one whitespace // only if it is preceded by at least one whitespace
if self.chars().nth(n - 1).unwrap().is_whitespace() { match self[..n].chars().last() {
line = &self[..n]; Some(c) if c.is_whitespace() => {
line = &self[..n - c.len_utf8()];
break;
}
None => {
// n == 0
line = &self[..0];
break;
}
_ => (),
} }
} }
line.trim() line.trim()