File tree Expand file tree Collapse file tree 1 file changed +12
-22
lines changed
Expand file tree Collapse file tree 1 file changed +12
-22
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments