YATL
Loading...
Searching...
No Matches
Span Query

Functions for querying span content and properties. More...

Functions

const char * YATL_span_type_name (YATL_SpanType_t type)
 Get the string name of a span type.
YATL_Result_t YATL_span_keyval_slice (const YATL_Span_t *in_span, YATL_Span_t *key, YATL_Span_t *val)
 Slice a key-value span into separate key and value spans.
YATL_SpanType_t YATL_span_type (const YATL_Span_t *span)
 Get the type of a span.
YATL_Result_t YATL_span_text (const YATL_Span_t *in_span, const char **out_text, size_t *out_len)
 Get text content of a single-line span.
YATL_Result_t YATL_span_get_string (const YATL_Span_t *in_span, const char *key, const char **out_text, size_t *out_len)
 Convenience function to find a key and get its string value.

Detailed Description

Functions for querying span content and properties.

Function Documentation

◆ YATL_span_get_string()

YATL_Result_t YATL_span_get_string ( const YATL_Span_t * in_span,
const char * key,
const char ** out_text,
size_t * out_len )

Convenience function to find a key and get its string value.

Combines YATL_span_find_name(), YATL_span_keyval_slice(), and YATL_span_text() into a single call for simple key-value lookups.

Parameters
in_spanSpan to search within
keyKey name to find
out_textOutput pointer to value text (not null-terminated)
out_lenOutput length of value text
Returns
YATL_OK on success
YATL_ERR_NOT_FOUND if key not found
YATL_ERR_TYPE if value is multi-line or not a key-value
YATL_ERR_INVALID_ARG if any parameter is NULL/uninitialized
const char *host;
size_t len;
if (YATL_span_get_string(&table_span, "host", &host, &len) == YATL_OK) {
printf("Host: %.*s\n", (int)len, host);
}
@ YATL_OK
Definition yatl.h:233
YATL_Result_t YATL_span_get_string(const YATL_Span_t *in_span, const char *key, const char **out_text, size_t *out_len)
Convenience function to find a key and get its string value.

◆ YATL_span_keyval_slice()

YATL_Result_t YATL_span_keyval_slice ( const YATL_Span_t * in_span,
YATL_Span_t * key,
YATL_Span_t * val )

Slice a key-value span into separate key and value spans.

Given a span of type YATL_S_LEAF_KEYVAL, extracts the key and value as separate spans.

Parameters
in_spanInput key-value span (must be YATL_S_LEAF_KEYVAL type)
keyOutput span for the key portion
valOutput span for the value portion. The span type is set according to the value type (e.g., YATL_S_NODE_ARRAY for arrays, YATL_S_NODE_INLINE_TABLE for inline tables). For string values, the span text excludes quote delimiters.
Returns
YATL_OK on success
YATL_ERR_TYPE if span is not YATL_S_LEAF_KEYVAL
YATL_ERR_INVALID_ARG if any parameter is NULL/uninitialized

◆ YATL_span_text()

YATL_Result_t YATL_span_text ( const YATL_Span_t * in_span,
const char ** out_text,
size_t * out_len )

Get text content of a single-line span.

Returns a pointer to the text content of a span that fits on a single line. For multi-line spans, use YATL_span_iter_line().

Parameters
in_spanSpan to get text from
out_textOutput pointer to text (not null-terminated)
out_lenOutput length of text
Returns
YATL_OK on success
YATL_ERR_TYPE if span is multi-line
YATL_ERR_INVALID_ARG if any parameter is NULL/uninitialized
Note
The returned pointer is into the document's internal buffer and becomes invalid if the document is modified or freed.

◆ YATL_span_type()

YATL_SpanType_t YATL_span_type ( const YATL_Span_t * span)

Get the type of a span.

Parameters
spanSpan to query
Returns
Span type, or YATL_S_NONE if span is NULL/uninitialized

◆ YATL_span_type_name()

const char * YATL_span_type_name ( YATL_SpanType_t type)

Get the string name of a span type.

Returns a human-readable string for the span type.

Parameters
typeSpan type value
Returns
String representation (e.g., "YATL_S_NODE_TABLE")