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

Function split_top_level_parens

nodedb-spatial/src/wkt.rs:221–241  ·  view source on GitHub ↗

Split by commas at the top level of parentheses nesting. "(...), (...)" → ["(...)", "(...)"]

(s: &str)

Source from the content-addressed store, hash-verified

219/// Split by commas at the top level of parentheses nesting.
220/// "(...), (...)" → ["(...)", "(...)"]
221fn split_top_level_parens(s: &str) -> Option<Vec<String>> {
222 let mut parts = Vec::new();
223 let mut depth = 0;
224 let mut start = 0;
225
226 for (i, ch) in s.char_indices() {
227 match ch {
228 '(' => depth += 1,
229 ')' => depth -= 1,
230 ',' if depth == 0 => {
231 parts.push(s[start..i].to_string());
232 start = i + 1;
233 }
234 _ => {}
235 }
236 }
237 if start < s.len() {
238 parts.push(s[start..].to_string());
239 }
240 if parts.is_empty() { None } else { Some(parts) }
241}
242
243/// Split geometry collection items by top-level commas, handling nested parens.
244fn split_top_level_items(s: &str) -> Vec<String> {

Callers 4

parse_polygonFunction · 0.85
parse_multipointFunction · 0.85
parse_multilinestringFunction · 0.85
parse_multipolygonFunction · 0.85

Calls 4

to_stringMethod · 0.80
pushMethod · 0.45
lenMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected