MCPcopy Create free account
hub / github.com/ResearAI/AutoFigure / find_json_bounds

Function find_json_bounds

autofigure/generator.py:1392–1424  ·  view source on GitHub ↗
(text, start_pos=0)

Source from the content-addressed store, hash-verified

1390 continue
1391
1392 def find_json_bounds(text, start_pos=0):
1393 start = text.find('{', start_pos)
1394 if start == -1:
1395 return None, None
1396
1397 bracket_count = 0
1398 in_string = False
1399 escape_next = False
1400
1401 for i in range(start, len(text)):
1402 char = text[i]
1403
1404 if escape_next:
1405 escape_next = False
1406 continue
1407
1408 if char == '\\':
1409 escape_next = True
1410 continue
1411
1412 if char == '"' and not escape_next:
1413 in_string = not in_string
1414 continue
1415
1416 if not in_string:
1417 if char == '{':
1418 bracket_count += 1
1419 elif char == '}':
1420 bracket_count -= 1
1421 if bracket_count == 0:
1422 return start, i + 1
1423
1424 return None, None
1425
1426 start, end = find_json_bounds(response_text)
1427 if start is not None and end is not None:

Callers 1

extract_json_robustlyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected