Function yaml_scalar_event_initialize

Synopsis

#include <include/yaml.h>

int yaml_scalar_event_initialize(yaml_event_t *event, const yaml_char_t *anchor, const yaml_char_t *tag, const yaml_char_t *value, int length, int plain_implicit, int quoted_implicit, yaml_scalar_style_t style)

Description

Create a SCALAR event.

The style argument may be ignored by the emitter.

Either the tag attribute or one of the plain_implicit and quoted_implicit flags must be set.

Parameters:

[ out ] event - An empty event object.

[ in ] anchor - The scalar anchor or NULL.

[ in ] tag - The scalar tag or NULL.

[ in ] value - The scalar value.

[ in ] length - The length of the scalar value.

[ in ] plain_implicit - If the tag may be omitted for the plain style.

[ in ] quoted_implicit - If the tag may be omitted for any non-plain style.

[ in ] style - The scalar style.

Return
1 if the function succeeded, 0 on error.
Create SCALAR.

Source

Lines 820-868 in src/api.c. Line 580 in include/yaml.h.

YAML_DECLARE(int)
yaml_scalar_event_initialize(yaml_event_t *event,
        const yaml_char_t *anchor, const yaml_char_t *tag,
        const yaml_char_t *value, int length,
        int plain_implicit, int quoted_implicit,
        yaml_scalar_style_t style)
{
    yaml_mark_t mark = { 0, 0, 0 };
    yaml_char_t *anchor_copy = NULL;
    yaml_char_t *tag_copy = NULL;
    yaml_char_t *value_copy = NULL;

    assert(event);      /* Non-NULL event object is expected. */
    assert(value);      /* Non-NULL anchor is expected. */

    if (anchor) {
        if (!yaml_check_utf8(anchor, strlen((char *)anchor))) goto error;
        anchor_copy = yaml_strdup(anchor);
        if (!anchor_copy) goto error;
    }

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

    if (length < 0) {
        length = strlen((char *)value);
    }

    if (!yaml_check_utf8(value, length)) goto error;
    value_copy = YAML_MALLOC(length+1);
    if (!value_copy) goto error;
    memcpy(value_copy, value, length);
    value_copy[length] = '\0';

    SCALAR_EVENT_INIT(*event, anchor_copy, tag_copy, value_copy, length,
            plain_implicit, quoted_implicit, style, mark, mark);

    return 1;

error:
    yaml_free(anchor_copy);
    yaml_free(tag_copy);
    yaml_free(value_copy);

    return 0;
}





Add Discussion as Guest

Log in to DocsForge