mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 20:17:45 +00:00
dircolor purify forward match '#'
This commit is contained in:
parent
8a03ac6caa
commit
e3197bea39
1 changed files with 19 additions and 18 deletions
|
@ -191,27 +191,28 @@ pub trait StrUtils {
|
||||||
|
|
||||||
impl StrUtils for str {
|
impl StrUtils for str {
|
||||||
fn purify(&self) -> &Self {
|
fn purify(&self) -> &Self {
|
||||||
let line = if self.as_bytes().first() == Some(&b'#') {
|
let mut line = self;
|
||||||
// Ignore if '#' is at the beginning of line
|
for (n, _) in self
|
||||||
&self[..0]
|
.as_bytes()
|
||||||
} else {
|
.iter()
|
||||||
let mut line = self;
|
.enumerate()
|
||||||
for (n, _) in self
|
.filter(|(_, c)| **c == b'#')
|
||||||
.as_bytes()
|
{
|
||||||
.iter()
|
// Ignore the content after '#'
|
||||||
.enumerate()
|
// only if it is preceded by at least one whitespace
|
||||||
.rev()
|
match self[..n].chars().last() {
|
||||||
.filter(|(_, c)| **c == b'#')
|
Some(c) if c.is_whitespace() => {
|
||||||
{
|
line = &self[..n - c.len_utf8()];
|
||||||
// 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;
|
break;
|
||||||
}
|
}
|
||||||
|
None => {
|
||||||
|
// n == 0
|
||||||
|
line = &self[..0];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
line
|
}
|
||||||
};
|
|
||||||
line.trim()
|
line.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue