MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / strip_outer_parens

Function strip_outer_parens

nodedb-sql/src/ddl_ast/parse/rls.rs:126–150  ·  view source on GitHub ↗

Strip at most one matched pair of outer parentheses.

(s: &str)

Source from the content-addressed store, hash-verified

124
125/// Strip at most one matched pair of outer parentheses.
126fn 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)`).

Callers 1

parse_create_rls_policyFunction · 0.85

Calls 2

to_stringMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected