@@ -1156,6 +1156,43 @@ skip_unknown_yaml (yaml_parser_t *parser, GError **error);
11561156 EMIT_KEY_VALUE_FULL (emitter, error, key, value, YAML_PLAIN_SCALAR_STYLE)
11571157
11581158
1159+ /**
1160+ * EMIT_KEY_VALUE_STRING:
1161+ * @emitter: (inout): A libyaml emitter object positioned where a scalar
1162+ * belongs in the YAML document.
1163+ * @error: (out): A #GError that will return the reason for an output error.
1164+ * @key: (in): The key (string) to be written.
1165+ * @value: (in): The scalar (string) to be written.
1166+ *
1167+ * Emits key/value pair (@key: @value) using YAML_DOUBLE_QUOTED_SCALAR_STYLE
1168+ * style for number-like keys/values, YAML_PLAIN_SCALAR_STYLE otherwise.
1169+ *
1170+ * NOTE: This macro outputs both a key and a value for that key, thus it must
1171+ * only be used from within a YAML mapping.
1172+ *
1173+ * Returns: Continues on if the YAML key/value pair was written successfully.
1174+ * Returns FALSE if an error occurred and sets @error appropriately.
1175+ *
1176+ * Since: 2.15
1177+ */
1178+ #define EMIT_KEY_VALUE_STRING (emitter , error , key , value ) \
1179+ do \
1180+ { \
1181+ if ((value) == NULL) \
1182+ { \
1183+ g_set_error ((error), \
1184+ MODULEMD_YAML_ERROR, \
1185+ MMD_YAML_ERROR_EMIT, \
1186+ "Value for key %s was NULL on emit", \
1187+ (key)); \
1188+ return FALSE; \
1189+ } \
1190+ EMIT_SCALAR_STRING ((emitter), (error), (key)); \
1191+ EMIT_SCALAR_STRING ((emitter), (error), (value)); \
1192+ } \
1193+ while (0)
1194+
1195+
11591196/**
11601197 * EMIT_KEY_VALUE_IF_SET:
11611198 * @emitter: (inout): A libyaml emitter object positioned where a scalar
@@ -1164,7 +1201,8 @@ skip_unknown_yaml (yaml_parser_t *parser, GError **error);
11641201 * @key: (in): The key (string) to be written.
11651202 * @value: (in): The scalar (string) to be written.
11661203 *
1167- * Emits key/value pair (@key: @value) only if @value is not NULL.
1204+ * Emits key/value pair (@key: @value) only if @value is not NULL. The
1205+ * emission is performed in YAML_PLAIN_SCALAR_STYLE style.
11681206 *
11691207 * NOTE: This macro outputs both a key and a value for that key, thus it must
11701208 * only be used from within a YAML mapping.
@@ -1178,13 +1216,46 @@ skip_unknown_yaml (yaml_parser_t *parser, GError **error);
11781216#define EMIT_KEY_VALUE_IF_SET (emitter , error , key , value ) \
11791217 do \
11801218 { \
1181- if (value != NULL) \
1219+ if (( value) != NULL) \
11821220 { \
1183- EMIT_KEY_VALUE (emitter, error, key, value); \
1221+ EMIT_KEY_VALUE (( emitter), ( error), ( key), ( value)); \
11841222 } \
11851223 } \
11861224 while (0)
11871225
1226+
1227+ /**
1228+ * EMIT_KEY_VALUE_STRING_IF_SET:
1229+ * @emitter: (inout): A libyaml emitter object positioned where a scalar
1230+ * belongs in the YAML document.
1231+ * @error: (out): A #GError that will return the reason for an output error.
1232+ * @key: (in): The key (string) to be written.
1233+ * @value: (in): The scalar (string) to be written.
1234+ *
1235+ * Emits key/value pair (@key: @value) only if @value is not NULL. The
1236+ * emission is performed in YAML_DOUBLE_QUOTED_SCALAR_STYLE style if the
1237+ * key/value looks like a number, otherwise in YAML_PLAIN_SCALAR_STYLE style.
1238+ *
1239+ * NOTE: This macro outputs both a key and a value for that key, thus it must
1240+ * only be used from within a YAML mapping.
1241+ *
1242+ * Returns: Continues on if @value is NULL or the YAML key/value pair was
1243+ * written successfully. Returns FALSE if an error occurred and sets @error
1244+ * appropriately.
1245+ *
1246+ * Since: 2.15
1247+ */
1248+ #define EMIT_KEY_VALUE_STRING_IF_SET (emitter , error , key , value ) \
1249+ do \
1250+ { \
1251+ if ((value) != NULL) \
1252+ { \
1253+ EMIT_KEY_VALUE_STRING ((emitter), (error), (key), (value)); \
1254+ } \
1255+ } \
1256+ while (0)
1257+
1258+
11881259/**
11891260 * EMIT_MAPPING_START_WITH_STYLE:
11901261 * @emitter: (inout): A libyaml emitter object that is positioned at the start
@@ -1472,7 +1543,7 @@ skip_unknown_yaml (yaml_parser_t *parser, GError **error);
14721543#define EMIT_STRING_SET_FULL (emitter , error , key , table , sequence_style ) \
14731544 do \
14741545 { \
1475- EMIT_SCALAR (emitter, error, key); \
1546+ EMIT_SCALAR_STRING (emitter, error, key); \
14761547 EMIT_SEQUENCE_START_WITH_STYLE (emitter, error, sequence_style); \
14771548 gsize i; \
14781549 g_autoptr (GPtrArray) keys = \
0 commit comments