Skip to content

Commit 234e31f

Browse files
sylvestrecakebaker
andauthored
simplify the code
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
1 parent e68955b commit 234e31f

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

src/uu/date/src/date.rs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -147,30 +147,20 @@ fn strip_parenthesized_comments(input: &str) -> Cow<'_, str> {
147147
}
148148

149149
let mut result = String::with_capacity(input.len());
150-
let mut chars = input.chars();
151-
152-
while let Some(c) = chars.next() {
153-
if c == '(' {
154-
// Look for matching closing parenthesis
155-
let mut depth = 1;
156-
for inner_c in chars.by_ref() {
157-
if inner_c == '(' {
158-
depth += 1;
159-
} else if inner_c == ')' {
160-
depth -= 1;
161-
if depth == 0 {
162-
break;
163-
}
164-
}
165-
}
150+
let mut depth = 0;
166151

167-
// If unmatched opening paren (depth > 0), stop processing entirely
168-
if depth > 0 {
169-
break;
152+
for c in input.chars() {
153+
match c {
154+
'(' => {
155+
depth += 1;
170156
}
171-
// If balanced, the parentheses and their content are skipped (comment)
172-
} else {
173-
result.push(c);
157+
')' if depth > 0 => {
158+
depth -= 1;
159+
}
160+
_ if depth == 0 => {
161+
result.push(c);
162+
}
163+
_ => {}
174164
}
175165
}
176166

0 commit comments

Comments
 (0)