ucx/cx/properties.h

changeset 888
af685cc9d623
parent 854
1c8401ece69e
--- a/ucx/cx/properties.h	Sun Aug 31 14:39:13 2025 +0200
+++ b/ucx/cx/properties.h	Sat Nov 08 23:06:11 2025 +0100
@@ -94,8 +94,7 @@
 /**
  * Default properties configuration.
  */
-cx_attr_export
-extern const CxPropertiesConfig cx_properties_config_default;
+CX_EXPORT extern const CxPropertiesConfig cx_properties_config_default;
 
 /**
  * Status codes for the properties interface.
@@ -122,7 +121,7 @@
      * You can use this enumerator to check for all "good" status results
      * by checking if the status is less than @c CX_PROPERTIES_OK.
      *
-     * A "good" status means, that you can refill data and continue parsing.
+     * A "good" status means that you can refill data and continue parsing.
      */
     CX_PROPERTIES_OK,
     /**
@@ -130,11 +129,11 @@
      */
     CX_PROPERTIES_NULL_INPUT,
     /**
-     * The line contains a delimiter, but no key.
+     * The line contains a delimiter but no key.
      */
     CX_PROPERTIES_INVALID_EMPTY_KEY,
     /**
-     * The line contains data, but no delimiter.
+     * The line contains data but no delimiter.
      */
     CX_PROPERTIES_INVALID_MISSING_DELIMITER,
     /**
@@ -200,7 +199,7 @@
 /**
  * A function that consumes a k/v-pair in a sink.
  *
- * The sink could be e.g. a map and the sink function would be calling
+ * The sink could be a map, and the sink function would be calling
  * a map function to store the k/v-pair.
  *
  * @param prop the properties interface that wants to sink a k/v-pair
@@ -210,7 +209,6 @@
  * @retval zero success
  * @retval non-zero sinking the k/v-pair failed
  */
-cx_attr_nonnull
 typedef int(*cx_properties_sink_func)(
         CxProperties *prop,
         CxPropertiesSink *sink,
@@ -257,7 +255,6 @@
  * @retval zero success
  * @retval non-zero reading the data failed
  */
-cx_attr_nonnull
 typedef int(*cx_properties_read_func)(
         CxProperties *prop,
         CxPropertiesSource *src,
@@ -272,7 +269,6 @@
  * @retval zero initialization was successful
  * @retval non-zero otherwise
  */
-cx_attr_nonnull
 typedef int(*cx_properties_read_init_func)(
         CxProperties *prop,
         CxPropertiesSource *src
@@ -284,7 +280,6 @@
  * @param prop the properties interface that wants to read from the source
  * @param src the source
  */
-cx_attr_nonnull
 typedef void(*cx_properties_read_clean_func)(
         CxProperties *prop,
         CxPropertiesSource *src
@@ -297,7 +292,7 @@
     /**
      * The source object.
      *
-     * For example a file stream or a string.
+     * For example, a file stream or a string.
      */
     void *src;
     /**
@@ -331,38 +326,32 @@
  * @see cxPropertiesInitDefault()
  */
 cx_attr_nonnull
-cx_attr_export
-void cxPropertiesInit(CxProperties *prop, CxPropertiesConfig config);
+CX_EXPORT void cxPropertiesInit(CxProperties *prop, CxPropertiesConfig config);
 
 /**
  * Destroys the properties interface.
  *
  * @note Even when you are certain that you did not use the interface in a
  * way that caused a memory allocation, you should call this function anyway.
- * Future versions of the library might add features that need additional memory
- * and you really don't want to search the entire code where you might need
- * add call to this function.
+ * Future versions of the library might add features that need additional memory,
+ * and you really don't want to search the entire code where you might need to
+ * add a call to this function.
  *
  * @param prop the properties interface
  */
 cx_attr_nonnull
-cx_attr_export
-void cxPropertiesDestroy(CxProperties *prop);
+CX_EXPORT void cxPropertiesDestroy(CxProperties *prop);
 
 /**
  * Destroys and re-initializes the properties interface.
  *
- * You might want to use this, to reset the parser after
+ * You might want to use this to reset the parser after
  * encountering a syntax error.
  *
  * @param prop the properties interface
  */
 cx_attr_nonnull
-static inline void cxPropertiesReset(CxProperties *prop) {
-    CxPropertiesConfig config = prop->config;
-    cxPropertiesDestroy(prop);
-    cxPropertiesInit(prop, config);
-}
+CX_EXPORT void cxPropertiesReset(CxProperties *prop);
 
 /**
  * Initialize a properties parser with the default configuration.
@@ -371,7 +360,7 @@
  * @see cxPropertiesInit()
  */
 #define cxPropertiesInitDefault(prop) \
-    cxPropertiesInit(prop, cx_properties_config_default)
+        cxPropertiesInit(prop, cx_properties_config_default)
 
 /**
  * Fills the input buffer with data.
@@ -394,44 +383,22 @@
  * @retval non-zero a memory allocation was necessary but failed
  * @see cxPropertiesFill()
  */
+cx_attr_nonnull cx_attr_access_r(2, 3)
+CX_EXPORT int cxPropertiesFilln(CxProperties *prop, const char *buf, size_t len);
+
+/**
+ * Internal function, do not use.
+ *
+ * @param prop the properties interface
+ * @param str the text to fill in
+ * @retval zero success
+ * @retval non-zero a memory allocation was necessary but failed
+ */
 cx_attr_nonnull
-cx_attr_access_r(2, 3)
-cx_attr_export
-int cxPropertiesFilln(
-        CxProperties *prop,
-        const char *buf,
-        size_t len
-);
-
-#ifdef __cplusplus
-} // extern "C"
-cx_attr_nonnull
-static inline int cxPropertiesFill(
-        CxProperties *prop,
-        cxstring str
-) {
+CX_INLINE int cx_properties_fill(CxProperties *prop, cxstring str) {
     return cxPropertiesFilln(prop, str.ptr, str.length);
 }
 
-cx_attr_nonnull
-static inline int cxPropertiesFill(
-        CxProperties *prop,
-        cxmutstr str
-) {
-    return cxPropertiesFilln(prop, str.ptr, str.length);
-}
-
-cx_attr_nonnull
-cx_attr_cstr_arg(2)
-static inline int cxPropertiesFill(
-        CxProperties *prop,
-        const char *str
-) {
-    return cxPropertiesFilln(prop, str, strlen(str));
-}
-
-extern "C" {
-#else // __cplusplus
 /**
  * Fills the input buffer with data.
  *
@@ -452,62 +419,17 @@
  * @retval non-zero a memory allocation was necessary but failed
  * @see cxPropertiesFilln()
  */
-#define cxPropertiesFill(prop, str) _Generic((str), \
-    cxstring: cx_properties_fill_cxstr,             \
-    cxmutstr: cx_properties_fill_mutstr,            \
-    char*: cx_properties_fill_str,                  \
-    const char*: cx_properties_fill_str)            \
-    (prop, str)
-
-/**
- * @copydoc cxPropertiesFill()
- */
-cx_attr_nonnull
-static inline int cx_properties_fill_cxstr(
-        CxProperties *prop,
-        cxstring str
-) {
-    return cxPropertiesFilln(prop, str.ptr, str.length);
-}
+#define cxPropertiesFill(prop, str) cx_properties_fill(prop, cx_strcast(str))
 
 /**
- * @copydoc cxPropertiesFill()
- */
-cx_attr_nonnull
-static inline int cx_properties_fill_mutstr(
-        CxProperties *prop,
-        cxmutstr str
-) {
-    return cxPropertiesFilln(prop, str.ptr, str.length);
-}
-
-/**
- * @copydoc cxPropertiesFill()
- */
-cx_attr_nonnull
-cx_attr_cstr_arg(2)
-static inline int cx_properties_fill_str(
-        CxProperties *prop,
-        const char *str
-) {
-    return cxPropertiesFilln(prop, str, strlen(str));
-}
-#endif
-
-/**
- * Specifies stack memory that shall be used as internal buffer.
+ * Specifies stack memory that shall be used as an internal buffer.
  *
  * @param prop the properties interface
  * @param buf a pointer to stack memory
  * @param capacity the capacity of the stack memory
  */
 cx_attr_nonnull
-cx_attr_export
-void cxPropertiesUseStack(
-        CxProperties *prop,
-        char *buf,
-        size_t capacity
-);
+CX_EXPORT void cxPropertiesUseStack(CxProperties *prop, char *buf, size_t capacity);
 
 /**
  * Retrieves the next key/value-pair.
@@ -539,31 +461,25 @@
  * @retval CX_PROPERTIES_INVALID_MISSING_DELIMITER the properties data contains a line without delimiter
  * @retval CX_PROPERTIES_BUFFER_ALLOC_FAILED an internal allocation was necessary but failed
  */
-cx_attr_nonnull
-cx_attr_nodiscard
-cx_attr_export
-CxPropertiesStatus cxPropertiesNext(
-        CxProperties *prop,
-        cxstring *key,
-        cxstring *value
-);
+cx_attr_nonnull cx_attr_nodiscard
+CX_EXPORT CxPropertiesStatus cxPropertiesNext(CxProperties *prop, cxstring *key, cxstring *value);
 
 /**
  * Creates a properties sink for an UCX map.
  *
- * The values stored in the map will be pointers to strings allocated
- * by #cx_strdup_a().
- * The default stdlib allocator will be used, unless you specify a custom
- * allocator in the optional @c data of the sink.
+ * The values stored in the map will be pointers to freshly allocated,
+ * zero-terminated C strings (@c char*), which means the @p map should have been
+ * created with #CX_STORE_POINTERS.
+ *
+ * The cxDefaultAllocator will be used unless you specify a custom
+ * allocator in the optional @c data field of the returned sink.
  *
  * @param map the map that shall consume the k/v-pairs.
  * @return the sink
  * @see cxPropertiesLoad()
  */
-cx_attr_nonnull
-cx_attr_nodiscard
-cx_attr_export
-CxPropertiesSink cxPropertiesMapSink(CxMap *map);
+cx_attr_nonnull cx_attr_nodiscard
+CX_EXPORT CxPropertiesSink cxPropertiesMapSink(CxMap *map);
 
 /**
  * Creates a properties source based on an UCX string.
@@ -573,8 +489,7 @@
  * @see cxPropertiesLoad()
  */
 cx_attr_nodiscard
-cx_attr_export
-CxPropertiesSource cxPropertiesStringSource(cxstring str);
+CX_EXPORT CxPropertiesSource cxPropertiesStringSource(cxstring str);
 
 /**
  * Creates a properties source based on C string with the specified length.
@@ -584,11 +499,8 @@
  * @return the properties source
  * @see cxPropertiesLoad()
  */
-cx_attr_nonnull
-cx_attr_nodiscard
-cx_attr_access_r(1, 2)
-cx_attr_export
-CxPropertiesSource cxPropertiesCstrnSource(const char *str, size_t len);
+cx_attr_nonnull cx_attr_nodiscard cx_attr_access_r(1, 2)
+CX_EXPORT CxPropertiesSource cxPropertiesCstrnSource(const char *str, size_t len);
 
 /**
  * Creates a properties source based on a C string.
@@ -600,11 +512,8 @@
  * @return the properties source
  * @see cxPropertiesLoad()
  */
-cx_attr_nonnull
-cx_attr_nodiscard
-cx_attr_cstr_arg(1)
-cx_attr_export
-CxPropertiesSource cxPropertiesCstrSource(const char *str);
+cx_attr_nonnull cx_attr_nodiscard cx_attr_cstr_arg(1)
+CX_EXPORT CxPropertiesSource cxPropertiesCstrSource(const char *str);
 
 /**
  * Creates a properties source based on an FILE.
@@ -615,11 +524,8 @@
  * @return the properties source
  * @see cxPropertiesLoad()
  */
-cx_attr_nonnull
-cx_attr_nodiscard
-cx_attr_access_r(1)
-cx_attr_export
-CxPropertiesSource cxPropertiesFileSource(FILE *file, size_t chunk_size);
+cx_attr_nonnull cx_attr_nodiscard cx_attr_access_r(1)
+CX_EXPORT CxPropertiesSource cxPropertiesFileSource(FILE *file, size_t chunk_size);
 
 
 /**
@@ -651,12 +557,8 @@
  * @retval CX_PROPERTIES_BUFFER_ALLOC_FAILED an internal allocation was necessary but failed
  */
 cx_attr_nonnull
-cx_attr_export
-CxPropertiesStatus cxPropertiesLoad(
-        CxProperties *prop,
-        CxPropertiesSink sink,
-        CxPropertiesSource source
-);
+CX_EXPORT CxPropertiesStatus cxPropertiesLoad(CxProperties *prop,
+        CxPropertiesSink sink, CxPropertiesSource source);
 
 #ifdef __cplusplus
 } // extern "C"

mercurial