| 1312 | */ |
| 1313 | |
| 1314 | YAML_DECLARE(int) |
| 1315 | yaml_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 | |
| 1348 | error: |
| 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. |
nothing calls this directly
no test coverage detected