16 #include <apr_buckets.h>
36 static void put_yaml_string(
40 static void convert_string_to_literal_style_yaml(
44 static void convert_string_to_yaml(
48 static void convert_integer_to_yaml(
52 static void convert_number_to_yaml(
56 static void convert_boolean_to_yaml(
60 static void convert_list_to_yaml(
64 static void convert_object_to_yaml(
68 static void convert_value_to_yaml(
77 wa->callback(wa->context, &ch, 1, wa->p, wa->xctx);
84 wa->callback(wa->context, s, strlen(s), wa->p, wa->xctx);
91 wa->callback(wa->context, buffer, size, wa->p, wa->xctx);
101 va_start(arg, format_z);
104 wa->callback(wa->context, s->s, s->len, wa->p, wa->xctx);
114 if (!wa->skip_next_ws) {
116 for (indent = 1; indent <= wa->indent; indent++) {
120 wa->skip_next_ws = 0;
136 void put_yaml_string(
160 impl_printf(wa,
"\\u%04x", c);
173 void convert_string_to_literal_style_yaml(
189 impl_printf(wa,
"%d", wa->indent);
193 if (s[len - 1] ==
'\n') {
233 void convert_string_to_yaml(
246 if (string->len > 0) {
247 for (c = string->s, end = c + string->len; c < end; c++)
250 convert_string_to_literal_style_yaml(wa,
string);
258 impl_write(wa, string->s, string->len);
265 void convert_integer_to_yaml(
279 void convert_number_to_yaml(
300 sprintf(s,
"%.23G", d);
303 strcpy(s,
"\"" AFW_JSON_Q_NAN
"\"");
305 else if (d <= DBL_MAX) {
306 strcpy(s,
"\"" AFW_JSON_Q_MINUS_INFINITY
"\"");
309 strcpy(s,
"\"" AFW_JSON_Q_INFINITY
"\"");
314 void convert_boolean_to_yaml(
320 AFW_JSON_Q_PRIMITIVE_BOOLEAN_TRUE);
324 AFW_JSON_Q_PRIMITIVE_BOOLEAN_FALSE);
328 void convert_list_to_yaml(
338 list_iterator = NULL;
343 convert_value_to_yaml(wa, next);
354 void convert_object_to_yaml(
364 property_iterator = NULL;
366 &property_name, wa->xctx);
371 wa->options, wa->p, wa->xctx);
374 put_yaml_string(wa, &afw_s__meta_);
377 convert_object_to_yaml(wa, meta);
389 put_yaml_string(wa, property_name);
393 convert_value_to_yaml(wa, next);
396 &property_iterator, &property_name, wa->xctx);
409 void convert_value_to_yaml(
425 "Unevaluated value encountered producing yaml "
444 convert_object_to_yaml(wa,
453 &AFW_JSON_S_PRIMITIVE_NULL))
455 impl_puts(wa, AFW_JSON_Q_PRIMITIVE_NULL);
460 &AFW_JSON_S_PRIMITIVE_STRING))
462 convert_string_to_yaml(wa, value);
467 &AFW_JSON_S_PRIMITIVE_NUMBER))
470 convert_integer_to_yaml(wa,
474 convert_number_to_yaml(wa,
479 "jsonPrimitive number not supported for this data type",
486 &AFW_JSON_S_PRIMITIVE_BOOLEAN))
488 convert_boolean_to_yaml(wa,
505 "Value type is invalid", wa->xctx);
511 extern void afw_yaml_internal_write_value(
521 wa = create_from_value_wa(p, xctx);
522 wa->options = options;
524 wa->skip_next_ws = 0;
525 wa->context = context;
526 wa->callback = callback;
529 impl_puts(wa,
"---");
533 convert_value_to_yaml(wa, value);
548 afw_yaml_internal_write_value(value, NULL,
549 writer->context, writer->callback, p, xctx);
Adaptive Framework Core API.
Header file for Adaptive Framework YAML.
#define afw_value_is_double(A_VALUE)
Macro to determine if value is evaluated double.
#define afw_value_is_integer(A_VALUE)
Macro to determine if value is evaluated integer.
#define afw_value_is_list(A_VALUE)
Macro to determine if value is evaluated list.
#define afw_value_is_object(A_VALUE)
Macro to determine if value is evaluated object.
#define AFW_UTF8_FMT_ARG(A_STRING)
Convenience Macro for use with AFW_UTF8_FMT to specify arg.
struct afw_iterator_s afw_iterator_t
#define AFW_UTF8_FMT_OPTIONAL_ARG(A_STRING)
Convenience Macro for use with AFW_UTF8_FMT to specify optional arg.
#define AFW_INTEGER_FMT
Format string specifier used for afw_integer_t.
unsigned char afw_byte_t
A byte of memory (unsigned).
#define AFW_UTF8_FMT
Format string specifier used for afw_utf8_t.
afw_utf8_octet_t afw_utf8_z_t
NFC normalized UTF-8 null terminated string.
char afw_utf8_octet_t
8 bits of utf-8 codepoint.
apr_size_t afw_size_t
size_t.
afw_size_t(* afw_write_cb_t)(void *context, const void *buffer, afw_size_t size, const afw_pool_t *p, afw_xctx_t *xctx)
Typedef for write callback function.
apr_int64_t afw_integer_t
typedef for big signed int.
#define AFW_THROW_ERROR_FZ(code, xctx, format_z,...)
Macro used to set error and 0 rv in xctx and throw it.
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
afw_json_utf8_string_create(const afw_utf8_t *string, const afw_pool_t *p, afw_xctx_t *xctx)
Create a json encoded quoted string.
#define afw_list_get_next_value(instance, iterator, p, xctx)
Call method get_next_value of interface afw_list.
afw_memory_writer_retrieve_and_release(const afw_memory_writer_t *writer, afw_xctx_t *xctx)
Retrieve memory as one chunk from memory writer and release writer.
afw_memory_create_writer(const afw_pool_t *p, afw_xctx_t *xctx)
Create a memory writer.
afw_boolean_t afw_number_is_NaN(double d)
Determine if double is not a number.
afw_boolean_t afw_number_is_finite(double d)
Determine if double is finite.
#define afw_object_get_next_property(instance, iterator, property_name, xctx)
Call method get_next_property of interface afw_object.
const afw_utf8_t * afw_utf8_from_raw(const afw_memory_t *raw, const afw_pool_t *p, afw_xctx_t *xctx)
Convert raw to a utf-8 NFC normalizing if necessary in specified pool.
afw_utf8_printf_v(const afw_utf8_z_t *format, va_list arg, const afw_pool_t *p, afw_xctx_t *xctx)
Create a utf-8 string using a c format string in specified pool.
afw_boolean_t afw_utf8_equal(const afw_utf8_t *s1, const afw_utf8_t *s2)
Check to see if a string equals another string.
#define afw_value_get_data_type(instance, xctx)
Call method get_data_type of interface afw_value.
#define afw_value_get_info(instance, info, p, xctx)
Call method get_info of interface afw_value.
afw_value_as_utf8(const afw_value_t *value, const afw_pool_t *p, afw_xctx_t *xctx)
#define afw_value_is_defined_and_evaluated(A_VALUE)
Macro to determine if value is defined and evaluated.
afw_value_null
Adaptive value null.
#define afw_xctx_calloc_type(type, xctx)
Macro to allocate cleared memory to hold type in xctx's pool.
const afw_utf8_t * afw_yaml_from_value(const afw_value_t *value, const afw_pool_t *p, afw_xctx_t *xctx)
Convert an adaptive value to YAML.
Interface afw_data_type public struct.
Interface afw_list public struct.
Struct for memory pointer and size.
Return value from afw_memory_create_writer().
Struct for object processing options.
Interface afw_object public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
struct for data type boolean values.
struct for data type double values.
Filled in by afw_value get_info method.
struct for data type integer values.
struct for data type list values.
struct for data type object values.
Interface afw_value public struct.
Interface afw_xctx public struct.