mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 04:57:45 +00:00
Prevent double scanning from dircolors
This commit is contained in:
parent
def5bec1ce
commit
8a03ac6caa
1 changed files with 19 additions and 16 deletions
|
@ -191,24 +191,27 @@ pub trait StrUtils {
|
||||||
|
|
||||||
impl StrUtils for str {
|
impl StrUtils for str {
|
||||||
fn purify(&self) -> &Self {
|
fn purify(&self) -> &Self {
|
||||||
let mut line = self;
|
let line = if self.as_bytes().first() == Some(&b'#') {
|
||||||
for (n, c) in self.chars().enumerate() {
|
|
||||||
if c != '#' {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ignore if '#' is at the beginning of line
|
// Ignore if '#' is at the beginning of line
|
||||||
if n == 0 {
|
&self[..0]
|
||||||
line = &self[..0];
|
} else {
|
||||||
break;
|
let mut line = self;
|
||||||
|
for (n, _) in self
|
||||||
|
.as_bytes()
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.rev()
|
||||||
|
.filter(|(_, c)| **c == b'#')
|
||||||
|
{
|
||||||
|
// Ignore the content after '#'
|
||||||
|
// only if it is preceded by at least one whitespace
|
||||||
|
if self[..n].chars().last().unwrap().is_whitespace() {
|
||||||
|
line = &self[..n];
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
line
|
||||||
// Ignore the content after '#'
|
};
|
||||||
// only if it is preceded by at least one whitespace
|
|
||||||
if self.chars().nth(n - 1).unwrap().is_whitespace() {
|
|
||||||
line = &self[..n];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
line.trim()
|
line.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue