Strip at most one matched pair of outer parentheses.
(s: &str)
| 124 | |
| 125 | /// Strip at most one matched pair of outer parentheses. |
| 126 | fn strip_outer_parens(s: &str) -> String { |
| 127 | let trimmed = s.trim(); |
| 128 | if trimmed.starts_with('(') && trimmed.ends_with(')') { |
| 129 | let inner = &trimmed[1..trimmed.len() - 1]; |
| 130 | let mut depth = 0i32; |
| 131 | let mut balanced = true; |
| 132 | for ch in inner.chars() { |
| 133 | match ch { |
| 134 | '(' => depth += 1, |
| 135 | ')' => { |
| 136 | depth -= 1; |
| 137 | if depth < 0 { |
| 138 | balanced = false; |
| 139 | break; |
| 140 | } |
| 141 | } |
| 142 | _ => {} |
| 143 | } |
| 144 | } |
| 145 | if balanced && depth == 0 { |
| 146 | return inner.trim().to_string(); |
| 147 | } |
| 148 | } |
| 149 | trimmed.to_string() |
| 150 | } |
| 151 | |
| 152 | /// Fallback: extract predicate text from the uppercased SQL string when |
| 153 | /// USING appears without space-separated parts matching (e.g. `USING(x=1)`). |
no test coverage detected