MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / yaml_document_add_mapping

Function yaml_document_add_mapping

xs/tools/yaml/api.c:1314–1353  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1312 */
1313
1314YAML_DECLARE(int)
1315yaml_document_add_mapping(yaml_document_t *document,
1316 yaml_char_t *tag, yaml_mapping_style_t style)
1317{
1318 struct {
1319 yaml_error_type_t error;
1320 } context;
1321 yaml_mark_t mark = { 0, 0, 0 };
1322 yaml_char_t *tag_copy = NULL;
1323 struct {
1324 yaml_node_pair_t *start;
1325 yaml_node_pair_t *end;
1326 yaml_node_pair_t *top;
1327 } pairs = { NULL, NULL, NULL };
1328 yaml_node_t node;
1329
1330 assert(document); /* Non-NULL document object is expected. */
1331
1332 if (!tag) {
1333 tag = (yaml_char_t *)YAML_DEFAULT_MAPPING_TAG;
1334 }
1335
1336 if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error;
1337 tag_copy = yaml_strdup(tag);
1338 if (!tag_copy) goto error;
1339
1340 if (!STACK_INIT(&context, pairs, INITIAL_STACK_SIZE)) goto error;
1341
1342 MAPPING_NODE_INIT(node, tag_copy, pairs.start, pairs.end,
1343 style, mark, mark);
1344 if (!PUSH(&context, document->nodes, node)) goto error;
1345
1346 return (int)(document->nodes.top - document->nodes.start);
1347
1348error:
1349 STACK_DEL(&context, pairs);
1350 yaml_free(tag_copy);
1351
1352 return 0;
1353}
1354
1355/*
1356 * Append an item to a sequence node.

Callers

nothing calls this directly

Calls 4

yaml_check_utf8Function · 0.85
yaml_strdupFunction · 0.85
yaml_freeFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected