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

Function yaml_document_add_sequence

xs/tools/yaml/api.c:1269–1308  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1267 */
1268
1269YAML_DECLARE(int)
1270yaml_document_add_sequence(yaml_document_t *document,
1271 yaml_char_t *tag, yaml_sequence_style_t style)
1272{
1273 struct {
1274 yaml_error_type_t error;
1275 } context;
1276 yaml_mark_t mark = { 0, 0, 0 };
1277 yaml_char_t *tag_copy = NULL;
1278 struct {
1279 yaml_node_item_t *start;
1280 yaml_node_item_t *end;
1281 yaml_node_item_t *top;
1282 } items = { NULL, NULL, NULL };
1283 yaml_node_t node;
1284
1285 assert(document); /* Non-NULL document object is expected. */
1286
1287 if (!tag) {
1288 tag = (yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG;
1289 }
1290
1291 if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error;
1292 tag_copy = yaml_strdup(tag);
1293 if (!tag_copy) goto error;
1294
1295 if (!STACK_INIT(&context, items, INITIAL_STACK_SIZE)) goto error;
1296
1297 SEQUENCE_NODE_INIT(node, tag_copy, items.start, items.end,
1298 style, mark, mark);
1299 if (!PUSH(&context, document->nodes, node)) goto error;
1300
1301 return (int)(document->nodes.top - document->nodes.start);
1302
1303error:
1304 STACK_DEL(&context, items);
1305 yaml_free(tag_copy);
1306
1307 return 0;
1308}
1309
1310/*
1311 * Add a mapping node to a document.

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