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

Function oa_scalar

internal/cbm/openapi.c:69–96  ·  view source on GitHub ↗

A scalar's text (quotes dropped) into out: its length, 0 for none. */

Source from the content-addressed store, hash-verified

67
68/* A scalar's text (quotes dropped) into out: its length, 0 for none. */
69static size_t oa_scalar(const CBMExtractCtx *ctx, TSNode n, char *out, size_t cap) {
70 for (int k = 0; k < OA_UNWRAP_MAX && (oa_is(n, "flow_node") || oa_is(n, "block_node")); k++) {
71 n = ts_node_named_child(n, 0);
72 }
73 if (ts_node_is_null(n) || !ts_node_is_null(oa_mapping(n)) || oa_is(n, "block_sequence") ||
74 oa_is(n, "flow_sequence") || oa_is(n, "array")) {
75 out[0] = '\0';
76 return 0;
77 }
78 uint32_t b = ts_node_start_byte(n);
79 uint32_t e = ts_node_end_byte(n);
80 const char *s = ctx->source + b;
81 size_t len = e - b;
82 while (len && isspace((unsigned char)s[len - SKIP_ONE])) {
83 len--;
84 }
85 if (len >= PAIR_LEN && (s[0] == '"' || s[0] == '\'') && s[len - SKIP_ONE] == s[0]) {
86 s++;
87 len -= PAIR_LEN;
88 }
89 if (len >= cap) {
90 out[0] = '\0';
91 return 0; /* longer than any key or reference read here */
92 }
93 memcpy(out, s, len);
94 out[len] = '\0';
95 return len;
96}
97
98/* The value of `key` in a mapping; a null node for none. */
99static TSNode oa_get(const CBMExtractCtx *ctx, TSNode map, const char *key) {

Callers 3

oa_getFunction · 0.85
oa_dup_scalarFunction · 0.85
cbm_extract_openapiFunction · 0.85

Calls 2

oa_isFunction · 0.85
oa_mappingFunction · 0.85

Tested by

no test coverage detected