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

Function yaml_document_add_scalar

xs/tools/yaml/api.c:1219–1263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1217 */
1218
1219YAML_DECLARE(int)
1220yaml_document_add_scalar(yaml_document_t *document,
1221 yaml_char_t *tag, yaml_char_t *value, int length,
1222 yaml_scalar_style_t style)
1223{
1224 struct {
1225 yaml_error_type_t error;
1226 } context;
1227 yaml_mark_t mark = { 0, 0, 0 };
1228 yaml_char_t *tag_copy = NULL;
1229 yaml_char_t *value_copy = NULL;
1230 yaml_node_t node;
1231
1232 assert(document); /* Non-NULL document object is expected. */
1233 assert(value); /* Non-NULL value is expected. */
1234
1235 if (!tag) {
1236 tag = (yaml_char_t *)YAML_DEFAULT_SCALAR_TAG;
1237 }
1238
1239 if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error;
1240 tag_copy = yaml_strdup(tag);
1241 if (!tag_copy) goto error;
1242
1243 if (length < 0) {
1244 length = (int)strlen((char *)value);
1245 }
1246
1247 if (!yaml_check_utf8(value, length)) goto error;
1248 value_copy = yaml_malloc(length+1);
1249 if (!value_copy) goto error;
1250 memcpy(value_copy, value, length);
1251 value_copy[length] = '\0';
1252
1253 SCALAR_NODE_INIT(node, tag_copy, value_copy, length, style, mark, mark);
1254 if (!PUSH(&context, document->nodes, node)) goto error;
1255
1256 return (int)(document->nodes.top - document->nodes.start);
1257
1258error:
1259 yaml_free(tag_copy);
1260 yaml_free(value_copy);
1261
1262 return 0;
1263}
1264
1265/*
1266 * Add a sequence node to a document.

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected