Function yaml_document_add_sequence

Synopsis

#include <include/yaml.h>

int yaml_document_add_sequence(yaml_document_t *document, const yaml_char_t *tag, yaml_sequence_style_t style)

Description

Create a SEQUENCE node and attach it to the document.

The style argument may be ignored by the emitter.

Parameters:

[ in,out ] document - A document object.

[ in ] tag - The sequence tag.

[ in ] style - The sequence style.

Return
the node id or 0 on error.
Add a sequence node to a document.

Source

Lines 1244-1283 in src/api.c. Line 915 in include/yaml.h.

YAML_DECLARE(int)
yaml_document_add_sequence(yaml_document_t *document,
        const yaml_char_t *tag, yaml_sequence_style_t style)
{
    struct {
        yaml_error_type_t error;
    } context;
    yaml_mark_t mark = { 0, 0, 0 };
    yaml_char_t *tag_copy = NULL;
    struct {
        yaml_node_item_t *start;
        yaml_node_item_t *end;
        yaml_node_item_t *top;
    } items = { NULL, NULL, NULL };
    yaml_node_t node;

    assert(document);   /* Non-NULL document object is expected. */

    if (!tag) {
        tag = (yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG;
    }

    if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error;
    tag_copy = yaml_strdup(tag);
    if (!tag_copy) goto error;

    if (!STACK_INIT(&context, items, yaml_node_item_t*)) goto error;

    SEQUENCE_NODE_INIT(node, tag_copy, items.start, items.end,
            style, mark, mark);
    if (!PUSH(&context, document->nodes, node)) goto error;

    return document->nodes.top - document->nodes.start;

error:
    STACK_DEL(&context, items);
    yaml_free(tag_copy);

    return 0;
}





Add Discussion as Guest

Log in to DocsForge