From c8b36a80bad4a1fe488927af4da0ecbcf10079bb Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Sun, 22 Mar 2026 19:16:51 +0100 Subject: Add OpenStep coercion support for non-OpenStep plist types - Use PLIST_OPT_COERCE option to coerce PLIST_BOOLEAN, PLIST_DATE, PLIST_UID, and PLIST_NULL to OpenStep-compatible types (1 or 0, ISO 8601 strings, integers, and 'NULL' string) - Add plist_to_openstep_with_options() function to allow passing coercion option (and others) - Update plist_write_to_string() and plist_write_to_stream() accordingly --- include/plist/plist.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'include/plist/plist.h') diff --git a/include/plist/plist.h b/include/plist/plist.h index bd35c53..94930b8 100644 --- a/include/plist/plist.h +++ b/include/plist/plist.h @@ -978,6 +978,30 @@ extern "C" */ PLIST_API plist_err_t plist_to_openstep(plist_t plist, char **plist_openstep, uint32_t* length, int prettify); + /** + * Export the #plist_t structure to OpenStep format with extended options. + * + * When \a PLIST_OPT_COMPACT is set in \a options, the resulting OpenStep output + * will be non-prettified. + * + * When \a PLIST_OPT_COERCE is set in \a options, plist types that have + * no native OpenStep representation are converted to OpenStep-compatible types + * instead of returning #PLIST_ERR_FORMAT: + * - #PLIST_BOOLEAN is serialized as a 1 or 0 + * - #PLIST_DATE is serialized as an ISO 8601 date string + * - #PLIST_NULL is serialized as string 'NULL' + * - #PLIST_UID is serialized as an integer + * + * @param plist the root node to export + * @param plist_openstep a pointer to a char* buffer. This function allocates the memory, + * caller is responsible for freeing it. + * @param length a pointer to an uint32_t variable. Represents the length of the allocated buffer. + * @param options One or more bitwise ORed values of #plist_write_options_t. + * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure + * @note Use plist_mem_free() to free the allocated memory. + */ + PLIST_API plist_err_t plist_to_openstep_with_options(plist_t plist, char **plist_openstep, uint32_t* length, plist_write_options_t options); + /** * Import the #plist_t structure from XML format. -- cgit v1.1-32-gdbae