MCPcopy Create free account
hub / github.com/F-Stack/f-stack / xo_format_value

Function xo_format_value

tools/libxo/libxo/libxo.c:4281–4626  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4279#endif /* 0 */
4280
4281static void
4282xo_format_value (xo_handle_t *xop, const char *name, ssize_t nlen,
4283 const char *value, ssize_t vlen,
4284 const char *fmt, ssize_t flen,
4285 const char *encoding, ssize_t elen, xo_xff_flags_t flags)
4286{
4287 int pretty = XOF_ISSET(xop, XOF_PRETTY);
4288 int quote;
4289
4290 /*
4291 * Before we emit a value, we need to know that the frame is ready.
4292 */
4293 xo_stack_t *xsp = &xop->xo_stack[xop->xo_depth];
4294
4295 if (flags & XFF_LEAF_LIST) {
4296 /*
4297 * Check if we've already started to emit normal leafs
4298 * or if we're not in a leaf list.
4299 */
4300 if ((xsp->xs_flags & (XSF_EMIT | XSF_EMIT_KEY))
4301 || !(xsp->xs_flags & XSF_EMIT_LEAF_LIST)) {
4302 char nbuf[nlen + 1];
4303 memcpy(nbuf, name, nlen);
4304 nbuf[nlen] = '\0';
4305
4306 ssize_t rc = xo_transition(xop, 0, nbuf, XSS_EMIT_LEAF_LIST);
4307 if (rc < 0)
4308 flags |= XFF_DISPLAY_ONLY | XFF_ENCODE_ONLY;
4309 else
4310 xop->xo_stack[xop->xo_depth].xs_flags |= XSF_EMIT_LEAF_LIST;
4311 }
4312
4313 xsp = &xop->xo_stack[xop->xo_depth];
4314 if (xsp->xs_name) {
4315 name = xsp->xs_name;
4316 nlen = strlen(name);
4317 }
4318
4319 } else if (flags & XFF_KEY) {
4320 /* Emitting a 'k' (key) field */
4321 if ((xsp->xs_flags & XSF_EMIT) && !(flags & XFF_DISPLAY_ONLY)) {
4322 xo_failure(xop, "key field emitted after normal value field: '%.*s'",
4323 nlen, name);
4324
4325 } else if (!(xsp->xs_flags & XSF_EMIT_KEY)) {
4326 char nbuf[nlen + 1];
4327 memcpy(nbuf, name, nlen);
4328 nbuf[nlen] = '\0';
4329
4330 ssize_t rc = xo_transition(xop, 0, nbuf, XSS_EMIT);
4331 if (rc < 0)
4332 flags |= XFF_DISPLAY_ONLY | XFF_ENCODE_ONLY;
4333 else
4334 xop->xo_stack[xop->xo_depth].xs_flags |= XSF_EMIT_KEY;
4335
4336 xsp = &xop->xo_stack[xop->xo_depth];
4337 xsp->xs_flags |= XSF_EMIT_KEY;
4338 }

Callers 4

xo_format_contentFunction · 0.85
xo_do_emit_fieldsFunction · 0.85
xo_errorn_hvFunction · 0.85
xo_emit_warn_hcvFunction · 0.85

Calls 15

xo_transitionFunction · 0.85
xo_failureFunction · 0.85
xo_xml_leader_lenFunction · 0.85
xo_styleFunction · 0.85
xo_simple_fieldFunction · 0.85
xo_format_humanizeFunction · 0.85
xo_buf_append_divFunction · 0.85
xo_fix_encodingFunction · 0.85
xo_buf_indentFunction · 0.85
xo_data_appendFunction · 0.85
xo_data_escapeFunction · 0.85
xo_stack_set_flagsFunction · 0.85

Tested by

no test coverage detected