MCPcopy Create free account
hub / github.com/enowdev/enowX-Coder / extract_braced_json_candidates

Function extract_braced_json_candidates

src-tauri/src/agents/runner.rs:2290–2348  ·  view source on GitHub ↗
(text: &str)

Source from the content-addressed store, hash-verified

2288}
2289
2290fn extract_braced_json_candidates(text: &str) -> Vec<String> {
2291 let chars: Vec<char> = text.chars().collect();
2292 let mut out = Vec::new();
2293 let mut starts = Vec::new();
2294 let mut depth: usize = 0;
2295 let mut in_string = false;
2296 let mut escaped = false;
2297
2298 for (index, ch) in chars.iter().enumerate() {
2299 if in_string {
2300 if escaped {
2301 escaped = false;
2302 continue;
2303 }
2304
2305 if *ch == '\\' {
2306 escaped = true;
2307 continue;
2308 }
2309
2310 if *ch == '"' {
2311 in_string = false;
2312 }
2313
2314 continue;
2315 }
2316
2317 if *ch == '"' {
2318 in_string = true;
2319 continue;
2320 }
2321
2322 if *ch == '{' {
2323 if depth == 0 {
2324 starts.push(index);
2325 }
2326 depth = depth.saturating_add(1);
2327 continue;
2328 }
2329
2330 if *ch == '}' {
2331 if depth == 0 {
2332 continue;
2333 }
2334
2335 depth -= 1;
2336 if depth == 0 {
2337 if let Some(start) = starts.pop() {
2338 let candidate: String = chars[start..=index].iter().collect();
2339 if candidate.contains("\"subagents\"") {
2340 out.push(candidate);
2341 }
2342 }
2343 }
2344 }
2345 }
2346
2347 out

Callers 1

parse_subagent_tasksFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected