MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / agent_json_find_entry

Function agent_json_find_entry

src/cli/agent_clients.c:996–1029  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

994}
995
996static int agent_json_find_entry(const char *document, size_t length, const char *section,
997 size_t *entry_start, size_t *entry_end) {
998 size_t bom = length >= 3U && (unsigned char)document[0] == 0xefU &&
999 (unsigned char)document[1] == 0xbbU && (unsigned char)document[2] == 0xbfU
1000 ? 3U
1001 : 0U;
1002 agent_json_scanner_t scanner = {.data = document, .length = length, .position = bom};
1003 if (agent_json_skip_space(&scanner) != 0) {
1004 return -1;
1005 }
1006 size_t root_start = scanner.position;
1007 if (agent_json_scan_value(&scanner, 0U) != 0 || agent_json_skip_space(&scanner) != 0 ||
1008 scanner.position != length || document[root_start] != '{') {
1009 return -1;
1010 }
1011 size_t object_start = root_start;
1012 size_t object_end = scanner.position;
1013 if (section) {
1014 size_t section_start = 0U;
1015 size_t section_end = 0U;
1016 int section_result = agent_json_find_member(document, root_start, object_end, section,
1017 &section_start, &section_end);
1018 if (section_result != 0) {
1019 return section_result;
1020 }
1021 if (document[section_start] != '{') {
1022 return -1;
1023 }
1024 object_start = section_start;
1025 object_end = section_end;
1026 }
1027 return agent_json_find_member(document, object_start, object_end, AGENT_ENTRY_KEY, entry_start,
1028 entry_end);
1029}
1030
1031static char *agent_json_escape(const char *value) {
1032 size_t length = strlen(value);

Callers 1

agent_json_editFunction · 0.85

Calls 3

agent_json_skip_spaceFunction · 0.85
agent_json_scan_valueFunction · 0.85
agent_json_find_memberFunction · 0.85

Tested by

no test coverage detected