This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch feature/674-improve-properties
in repository https://gitbox.apache.org/repos/asf/celix.git

commit 6843859f2acccb8c352d44f9fda283ff4ea610d7
Author: Pepijn Noltes <[email protected]>
AuthorDate: Sun Jan 7 15:53:28 2024 +0100

    Add missing convert utils doxygen and fix unit tests
---
 libs/utils/gtest/src/ConvertUtilsTestSuite.cc | 132 ++++++++++++++
 libs/utils/include/celix_convert_utils.h      | 145 +++++++++++++--
 libs/utils/src/celix_convert_utils.c          | 242 ++++++++++++++++++--------
 3 files changed, 439 insertions(+), 80 deletions(-)

diff --git a/libs/utils/gtest/src/ConvertUtilsTestSuite.cc 
b/libs/utils/gtest/src/ConvertUtilsTestSuite.cc
index 7afc3900..16551926 100644
--- a/libs/utils/gtest/src/ConvertUtilsTestSuite.cc
+++ b/libs/utils/gtest/src/ConvertUtilsTestSuite.cc
@@ -307,6 +307,8 @@ TEST_F(ConvertUtilsTestSuite, ConvertToLongArrayTest) {
     celix_status_t convertState = 
celix_utils_convertStringToLongArrayList("1,2,3", nullptr, &result);
     EXPECT_EQ(CELIX_SUCCESS, convertState);
     EXPECT_TRUE(result != nullptr);
+    EXPECT_EQ(3, celix_arrayList_size(result));
+    EXPECT_EQ(2L, celix_arrayList_getLong(result, 1));
     celix_arrayList_destroy(result);
 
     convertState = celix_utils_convertStringToLongArrayList("invalid", 
nullptr, &result);
@@ -357,3 +359,133 @@ TEST_F(ConvertUtilsTestSuite, LongArrayToStringTest) {
     EXPECT_STREQ("1", result);
     free(result);
 }
+
+TEST_F(ConvertUtilsTestSuite, ConvertToDoubleArrayList) {
+    celix_array_list_t* result;
+    celix_status_t convertState = 
celix_utils_convertStringToDoubleArrayList("0.1,2.0,3.1,4,5", nullptr, &result);
+    EXPECT_EQ(CELIX_SUCCESS, convertState);
+    EXPECT_TRUE(result != nullptr);
+    EXPECT_EQ(5, celix_arrayList_size(result));
+    EXPECT_DOUBLE_EQ(2.0, celix_arrayList_getDouble(result, 1));
+    EXPECT_DOUBLE_EQ(5.0, celix_arrayList_getDouble(result, 4));
+    celix_arrayList_destroy(result);
+
+    // NOTE celix_utils_convertStringToDoubleArrayList uses the same generic 
function as is used in
+    // celix_utils_convertStringToLongArrayList and because 
celix_utils_convertStringToLongArrayList is already
+    // tested, we only test a few cases here.
+}
+
+TEST_F(ConvertUtilsTestSuite, DoubleArrayToStringTest) {
+    celix_autoptr(celix_array_list_t) list = celix_arrayList_create();
+    celix_arrayList_addDouble(list, 0.1);
+    celix_arrayList_addDouble(list, 2.0);
+    celix_arrayList_addDouble(list, 3.3);
+
+    char* result = celix_utils_doubleArrayListToString(list); //note result is 
not limited to 2 decimals, so using strstr
+    EXPECT_TRUE(strstr(result, "0.1") != nullptr);
+    EXPECT_TRUE(strstr(result, "2.0") != nullptr);
+    EXPECT_TRUE(strstr(result, "3.3") != nullptr);
+    free(result);
+
+    // NOTE celix_utils_doubleArrayListToString uses the same generic function 
as is used in
+    // celix_utils_longArrayListToString and because 
celix_utils_longArrayListToString is already
+    // tested, we only test a few cases here.
+}
+
+TEST_F(ConvertUtilsTestSuite, ConvertToBoolArrayList) {
+    celix_array_list_t* result;
+    celix_status_t convertState = 
celix_utils_convertStringToBoolArrayList("true,false,true", nullptr, &result);
+    EXPECT_EQ(CELIX_SUCCESS, convertState);
+    EXPECT_TRUE(result != nullptr);
+    EXPECT_EQ(3, celix_arrayList_size(result));
+    EXPECT_TRUE(celix_arrayList_getBool(result, 0));
+    EXPECT_FALSE(celix_arrayList_getBool(result, 1));
+    EXPECT_TRUE(celix_arrayList_getBool(result, 2));
+    celix_arrayList_destroy(result);
+
+    // NOTE celix_utils_convertStringToBoolArrayList uses the same generic 
function as is used in
+    // celix_utils_convertStringToLongArrayList and because 
celix_utils_convertStringToLongArrayList is already
+    // tested, we only test a few cases here.
+}
+
+TEST_F(ConvertUtilsTestSuite, BoolArrayToStringTest) {
+    celix_autoptr(celix_array_list_t) list = celix_arrayList_create();
+    celix_arrayList_addBool(list, true);
+    celix_arrayList_addBool(list, false);
+    celix_arrayList_addBool(list, true);
+
+    char* result = celix_utils_boolArrayListToString(list);
+    EXPECT_STREQ("true, false, true", result);
+    free(result);
+
+    // NOTE celix_utils_boolArrayListToString uses the same generic function 
as is used in
+    // celix_utils_longArrayListToString and because 
celix_utils_longArrayListToString is already
+    // tested, we only test a few cases here.
+}
+
+TEST_F(ConvertUtilsTestSuite, ConvertToStringArrayList) {
+    celix_array_list_t* result;
+    celix_status_t convertState = 
celix_utils_convertStringToStringArrayList("a,b,c", nullptr, &result);
+    EXPECT_EQ(CELIX_SUCCESS, convertState);
+    EXPECT_TRUE(result != nullptr);
+    EXPECT_EQ(3, celix_arrayList_size(result));
+    EXPECT_STREQ("a", (char*)celix_arrayList_get(result, 0));
+    EXPECT_STREQ("b", (char*)celix_arrayList_get(result, 1));
+    EXPECT_STREQ("c", (char*)celix_arrayList_get(result, 2));
+    celix_arrayList_destroy(result);
+
+    // NOTE celix_utils_convertStringToStringArrayList uses the same generic 
function as is used in
+    // celix_utils_convertStringToLongArrayList and because 
celix_utils_convertStringToLongArrayList is already
+    // tested, we only test a few cases here.
+}
+
+TEST_F(ConvertUtilsTestSuite, StringArrayToStringTest) {
+    celix_autoptr(celix_array_list_t) list = celix_arrayList_create();
+    celix_arrayList_add(list, (void*)"a");
+    celix_arrayList_add(list, (void*)"b");
+    celix_arrayList_add(list, (void*)"c");
+
+    char* result = celix_utils_stringArrayListToString(list);
+    EXPECT_STREQ("a, b, c", result);
+    free(result);
+
+    // NOTE celix_utils_stringArrayListToString uses the same generic function 
as is used in
+    // celix_utils_longArrayListToString and because 
celix_utils_longArrayListToString is already
+    // tested, we only test a few cases here.
+}
+
+TEST_F(ConvertUtilsTestSuite, ConvertToVersionArrayList) {
+    celix_array_list_t* result;
+    celix_status_t convertState = 
celix_utils_convertStringToVersionArrayList("1.2.3,2.3.4,3.4.5.qualifier", 
nullptr, &result);
+    EXPECT_EQ(CELIX_SUCCESS, convertState);
+    EXPECT_TRUE(result != nullptr);
+    EXPECT_EQ(3, celix_arrayList_size(result));
+    checkVersion((celix_version_t*)celix_arrayList_get(result, 0), 1, 2, 3, 
nullptr);
+    checkVersion((celix_version_t*)celix_arrayList_get(result, 1), 2, 3, 4, 
nullptr);
+    checkVersion((celix_version_t*)celix_arrayList_get(result, 2), 3, 4, 5, 
"qualifier");
+    celix_arrayList_destroy(result);
+
+    // NOTE celix_utils_convertStringToVersionArrayList uses the same generic 
function as is used in
+    // celix_utils_convertStringToLongArrayList and because 
celix_utils_convertStringToLongArrayList is already
+    // tested, we only test a few cases here.
+}
+
+TEST_F(ConvertUtilsTestSuite, VersionArrayToStringTest) {
+    celix_autoptr(celix_version_t) v1 = celix_version_create(1, 2, 3, nullptr);
+    celix_autoptr(celix_version_t) v2 = celix_version_create(2, 3, 4, nullptr);
+    celix_autoptr(celix_version_t) v3 = celix_version_create(3, 4, 5, 
"qualifier");
+    celix_autoptr(celix_array_list_t) list = celix_arrayList_create();
+    celix_arrayList_add(list, v1);
+    celix_arrayList_add(list, v2);
+    celix_arrayList_add(list, v3);
+
+    char* result = celix_utils_versionArrayListToString(list);
+    EXPECT_STREQ("1.2.3, 2.3.4, 3.4.5.qualifier", result);
+    free(result);
+
+    // NOTE celix_utils_versionArrayListToString uses the same generic 
function as is used in
+    // celix_utils_longArrayListToString and because 
celix_utils_longArrayListToString is already
+    // tested, we only test a few cases here.
+}
+
+
diff --git a/libs/utils/include/celix_convert_utils.h 
b/libs/utils/include/celix_convert_utils.h
index 360b3214..8fc73f6e 100644
--- a/libs/utils/include/celix_convert_utils.h
+++ b/libs/utils/include/celix_convert_utils.h
@@ -20,11 +20,12 @@
 #ifndef CELIX_CELIX_CONVERT_UTILS_H
 #define CELIX_CELIX_CONVERT_UTILS_H
 
+#include <stdbool.h>
+
 #include "celix_array_list.h"
 #include "celix_errno.h"
 #include "celix_utils_export.h"
 #include "celix_version.h"
-#include <stdbool.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -38,6 +39,9 @@ extern "C" {
 /**
  * @brief Convert a string to a boolean.
  *
+ * Converts a string to a boolean. White space is ignored and the following 
values are considered booleans (case
+ * insensitive): "true', "false".
+ *
  * @param[in] val The string to convert.
  * @param[in] defaultValue The default value if the string is not a valid 
boolean.
  * @param[out] converted If not NULL, will be set to true if the string is a 
valid boolean, otherwise false.
@@ -75,24 +79,143 @@ CELIX_UTILS_EXPORT long 
celix_utils_convertStringToLong(const char* val, long de
  * @param[in] defaultValue The default value if the string is not a valid 
celix_version_t.
  * @param[out] version The converted version. If the string is not a valid 
version, the version will be set to a copy of
  *                     the defaultValue.
- * @return CELIX_SUCCESS if the string is a valid version, 
CELIX_ILLEGAL_ARGUMENT if the string is not a valid version and
- * CELIX_ENOMEM if memory could not be allocated. Note that on a 
CELIX_ILLEGAL_ARGUMENT the version will be set to a copy
- * of the defaultValue.
+ * @return CELIX_SUCCESS if the string is a valid version, 
CELIX_ILLEGAL_ARGUMENT if the string is not a valid version
+ * and CELIX_ENOMEM if memory could not be allocated. Note that on a 
CELIX_ILLEGAL_ARGUMENT the version will be set to a
+ * copy of the defaultValue.
  */
-CELIX_UTILS_EXPORT celix_status_t
-celix_utils_convertStringToVersion(const char* val, const celix_version_t* 
defaultValue, celix_version_t** version);
+CELIX_UTILS_EXPORT celix_status_t celix_utils_convertStringToVersion(const 
char* val,
+                                                                     const 
celix_version_t* defaultValue,
+                                                                     
celix_version_t** version);
 
-//TODO
+/**
+ * @brief Convert a string to a celix_array_list_t* with long entries.
+ *
+ * The expected format of the string is a "," separated list of longs. 
Whitespace is ignored.
+ * Long entries are created using celix_utils_convertStringToLong.
+ *
+ * @param[in] val The string to convert.
+ * @param[in] defaultValue The default value if the string is not a valid "," 
separated list of longs.
+ * @param[out] list The converted list. If the string is not a valid list, the 
list will be set to a copy of the
+ * defaultValue.
+ */
 CELIX_UTILS_EXPORT
-celix_status_t
-celix_utils_convertStringToLongArrayList(const char* val, const 
celix_array_list_t* defaultValue, celix_array_list_t** list);
+celix_status_t celix_utils_convertStringToLongArrayList(const char* val,
+                                                        const 
celix_array_list_t* defaultValue,
+                                                        celix_array_list_t** 
list);
 
-//TODO
+/**
+ * @brief Convert a celix_array_list_t* with long entries to a string.
+ *
+ * @param[in] list The list to convert.
+ * @return The string representation of the list. The returned string is 
allocated and should be freed.
+ */
 CELIX_UTILS_EXPORT
 char* celix_utils_longArrayListToString(const celix_array_list_t* list);
 
+/**
+ * @brief Convert a string to a celix_array_list_t* with double entries.
+ *
+ * The expected format of the string is a "," separated list of doubles. 
Whitespace is ignored.
+ * Double entries are created using celix_utils_convertStringToDouble.
+ *
+ * @param[in] val The string to convert.
+ * @param[in] defaultValue The default value if the string is not a valid "," 
separated list of doubles.
+ * @param[out] list The converted list. If the string is not a valid list, the 
list will be set to a copy of the
+ * defaultValue.
+ */
+CELIX_UTILS_EXPORT
+celix_status_t celix_utils_convertStringToDoubleArrayList(const char* val,
+                                                          const 
celix_array_list_t* defaultValue,
+                                                          celix_array_list_t** 
list);
+
+/**
+ * @brief Convert a celix_array_list_t* with double entries to a string.
+ *
+ * @param[in] list The list to convert.
+ * @return The string representation of the list. The returned string is 
allocated and should be freed.
+ */
+CELIX_UTILS_EXPORT
+char* celix_utils_doubleArrayListToString(const celix_array_list_t* list);
+
+/**
+ * @brief Convert a string to a celix_array_list_t* with boolean entries.
+ *
+ * The expected format of the string is a "," separated list of booleans. 
Whitespace is ignored.
+ * Boolean entries are converted using celix_utils_convertStringToBool.
+ *
+ * @param[in] val The string to convert.
+ * @param[in] defaultValue The default value if the string is not a valid "," 
separated list of booleans.
+ * @param[out] list The converted list. If the string is not a valid list, the 
list will be set to a copy of the
+ * defaultValue.
+ */
+CELIX_UTILS_EXPORT
+celix_status_t celix_utils_convertStringToBoolArrayList(const char* val,
+                                                        const 
celix_array_list_t* defaultValue,
+                                                        celix_array_list_t** 
list);
+
+/**
+ * @brief Convert a celix_array_list_t* with boolean entries to a string.
+ *
+ * @param[in] list The list to convert.
+ * @return The string representation of the list. The returned string is 
allocated and should be freed.
+ */
+CELIX_UTILS_EXPORT
+char* celix_utils_boolArrayListToString(const celix_array_list_t* list);
+
+/**
+ * @brief Convert a string to a celix_array_list_t* with string entries.
+ *
+ * The expected format of the string is a "," separated list of strings. 
Whitespace is preserved.
+ * String entries are copied and the returned list will be configured to call 
free when entries are removed.
+ *
+ * @param[in] val The string to convert.
+ * @param[in] defaultValue The default value if the string is not a valid "," 
separated list of strings.
+ * @param[out] list The converted list. If the string is not a valid list, the 
list will be set to a copy of the
+ * defaultValue.
+ */
+CELIX_UTILS_EXPORT
+celix_status_t celix_utils_convertStringToStringArrayList(const char* val,
+                                                          const 
celix_array_list_t* defaultValue,
+                                                          celix_array_list_t** 
list);
+
+/**
+ * @brief Convert a celix_array_list_t* with string entries to a string.
+ *
+ * @param[in] list The list to convert.
+ * @return The string representation of the list. The returned string is 
allocated and should be freed.
+ */
+CELIX_UTILS_EXPORT
+char* celix_utils_stringArrayListToString(const celix_array_list_t* list);
+
+/**
+ * @brief Convert a string to a celix_array_list_t* with celix_version_t* 
entries.
+ *
+ * The expected format of the string is a "," separated list of 
celix_version_t* entries. Whitespace is ignored.
+ * Version entries are created using celix_utils_convertStringToVersion and 
the returned list will be configured to call
+ * celix_version_destroy when entries are removed.
+ *
+ * @param[in] val The string to convert.
+ * @param[in] defaultValue The default value if the string is not a valid "," 
separated list of string parseable to
+ *                         celix_version_t entries.
+ * @param[out] list The converted list. If the string is not a valid list, the 
list will be set to a copy of the
+ * defaultValue.
+ */
+CELIX_UTILS_EXPORT
+celix_status_t celix_utils_convertStringToVersionArrayList(const char* val,
+                                                           const 
celix_array_list_t* defaultValue,
+                                                           
celix_array_list_t** list);
+
+/**
+ * @brief Convert a celix_array_list_t* with version entries to a string.
+ *
+ * @param[in] list The list to convert.
+ * @return The string representation of the list. The returned string is 
allocated and should be freed.
+ */
+CELIX_UTILS_EXPORT
+char* celix_utils_versionArrayListToString(const celix_array_list_t* list);
+
 #ifdef __cplusplus
 }
 #endif
 
-#endif //CELIX_CELIX_CONVERT_UTILS_H
+#endif // CELIX_CELIX_CONVERT_UTILS_H
diff --git a/libs/utils/src/celix_convert_utils.c 
b/libs/utils/src/celix_convert_utils.c
index d6ba9093..eb3eb5c4 100644
--- a/libs/utils/src/celix_convert_utils.c
+++ b/libs/utils/src/celix_convert_utils.c
@@ -26,9 +26,9 @@
 #include <string.h>
 
 #include "celix_array_list.h"
-#include "celix_utils.h"
-#include "celix_stdio_cleanup.h"
 #include "celix_err.h"
+#include "celix_stdio_cleanup.h"
+#include "celix_utils.h"
 
 static bool celix_utils_isEndptrEndOfStringOrOnlyContainsWhitespaces(const 
char* endptr) {
     bool result = false;
@@ -80,7 +80,7 @@ double celix_utils_convertStringToDouble(const char* val, 
double defaultValue, b
         *converted = false;
     }
     if (val != NULL) {
-        char *endptr;
+        char* endptr;
         double d = strtod(val, &endptr);
         if (endptr != val && 
celix_utils_isEndptrEndOfStringOrOnlyContainsWhitespaces(endptr)) {
             result = d;
@@ -98,7 +98,7 @@ long celix_utils_convertStringToLong(const char* val, long 
defaultValue, bool* c
         *converted = false;
     }
     if (val != NULL) {
-        char *endptr;
+        char* endptr;
         long l = strtol(val, &endptr, 10);
         if (endptr != val && 
celix_utils_isEndptrEndOfStringOrOnlyContainsWhitespaces(endptr)) {
             result = l;
@@ -110,7 +110,8 @@ long celix_utils_convertStringToLong(const char* val, long 
defaultValue, bool* c
     return result;
 }
 
-celix_status_t celix_utils_convertStringToVersion(const char* val, const 
celix_version_t* defaultValue, celix_version_t** version) {
+celix_status_t
+celix_utils_convertStringToVersion(const char* val, const celix_version_t* 
defaultValue, celix_version_t** version) {
     assert(version != NULL);
     if (!val && defaultValue) {
         *version = celix_version_copy(defaultValue);
@@ -130,52 +131,138 @@ celix_status_t celix_utils_convertStringToVersion(const 
char* val, const celix_v
     return status;
 }
 
-celix_status_t celix_utils_convertStringToLongArrayList(const char* val, const 
celix_array_list_t* defaultValue, celix_array_list_t** list) {
-        assert(list != NULL);
-        *list = NULL;
+/**
+ * @brief Convert the provided string to an array list using the provided 
addEntry callback to convert the string
+ * to a specific type and add it to the list.
+ */
+static celix_status_t celix_utils_convertStringToArrayList(const char* val,
+                                                           const 
celix_array_list_t* defaultValue,
+                                                           
celix_array_list_t** list,
+                                                           void 
(*freeCb)(void*),
+                                                           celix_status_t 
(*addEntry)(celix_array_list_t*,
+                                                                               
       const char*)) {
+    assert(list != NULL);
+    *list = NULL;
 
-        if (!val && defaultValue) {
-            *list = celix_arrayList_copy(defaultValue);
-            return *list ? CELIX_ILLEGAL_ARGUMENT : CELIX_ENOMEM;
-        } else if (!val) {
-            return CELIX_ILLEGAL_ARGUMENT;
-        }
+    if (!val && defaultValue) {
+        *list = celix_arrayList_copy(defaultValue);
+        return *list ? CELIX_ILLEGAL_ARGUMENT : CELIX_ENOMEM;
+    } else if (!val) {
+        return CELIX_ILLEGAL_ARGUMENT;
+    }
 
-        celix_autoptr(celix_array_list_t) result = celix_arrayList_create();
-        if (!result) {
-            return CELIX_ENOMEM;
-        }
+    celix_array_list_create_options_t opts = 
CELIX_EMPTY_ARRAY_LIST_CREATE_OPTIONS;
+    opts.simpleRemovedCallback = freeCb;
+    celix_autoptr(celix_array_list_t) result = 
celix_arrayList_createWithOptions(&opts);
+    if (!result) {
+        return CELIX_ENOMEM;
+    }
 
-        celix_status_t status = CELIX_SUCCESS;
-        if (val) {
-                char buf[256];
-                char* valCopy = celix_utils_writeOrCreateString(buf, 
sizeof(buf), "%s", val);
-                char* savePtr = NULL;
-                char* token = strtok_r(valCopy, ",", &savePtr);
-                while (token != NULL) {
-                    bool converted;
-                    long l = celix_utils_convertStringToLong(token, 0L, 
&converted);
-                    if (!converted) {
-                        status =  CELIX_ILLEGAL_ARGUMENT;
-                        break;
-                    }
-                    status = celix_arrayList_addLong(result, l);
-                    if (status != CELIX_SUCCESS) {
-                        break;
-                    }
-                    token = strtok_r(NULL, ",", &savePtr);
-                }
-                celix_utils_freeStringIfNotEqual(buf, valCopy);
-        }
-        if (status == CELIX_ILLEGAL_ARGUMENT) {
-            if (defaultValue) {
-                *list = celix_arrayList_copy(defaultValue);
-                return *list ? status : CELIX_ENOMEM;
-            }
-            return status;
+    char buf[256];
+    char* valCopy = celix_utils_writeOrCreateString(buf, sizeof(buf), "%s", 
val);
+    if (!valCopy) {
+        return CELIX_ENOMEM;
+    }
+
+    celix_status_t status = CELIX_SUCCESS;
+    char* savePtr = NULL;
+    char* token = strtok_r(valCopy, ",", &savePtr);
+    while (token != NULL) {
+        status = addEntry(result, token);
+        if (status != CELIX_SUCCESS) {
+            break;
         }
+        token = strtok_r(NULL, ",", &savePtr);
+    }
+    celix_utils_freeStringIfNotEqual(buf, valCopy);
+
+    if (status == CELIX_SUCCESS) {
         *list = celix_steal_ptr(result);
+    } else if (status == CELIX_ILLEGAL_ARGUMENT) {
+        if (defaultValue) {
+            *list = celix_arrayList_copy(defaultValue);
+            return *list ? status : CELIX_ENOMEM;
+        }
         return status;
+    }
+    return status;
+}
+
+celix_status_t celix_utils_addLongEntry(celix_array_list_t* list, const char* 
entry) {
+    bool converted;
+    long l = celix_utils_convertStringToLong(entry, 0L, &converted);
+    if (!converted) {
+        return CELIX_ILLEGAL_ARGUMENT;
+    }
+    return celix_arrayList_addLong(list, l);
+}
+
+celix_status_t celix_utils_convertStringToLongArrayList(const char* val,
+                                                        const 
celix_array_list_t* defaultValue,
+                                                        celix_array_list_t** 
list) {
+    return celix_utils_convertStringToArrayList(val, defaultValue, list, NULL, 
celix_utils_addLongEntry);
+}
+
+celix_status_t celix_utils_addDoubleEntry(celix_array_list_t* list, const 
char* entry) {
+    bool converted;
+    double d = celix_utils_convertStringToDouble(entry, 0.0, &converted);
+    if (!converted) {
+        return CELIX_ILLEGAL_ARGUMENT;
+    }
+    return celix_arrayList_addDouble(list, d);
+}
+
+celix_status_t celix_utils_convertStringToDoubleArrayList(const char* val,
+                                                          const 
celix_array_list_t* defaultValue,
+                                                          celix_array_list_t** 
list) {
+    return celix_utils_convertStringToArrayList(val, defaultValue, list, NULL, 
celix_utils_addDoubleEntry);
+}
+
+celix_status_t celix_utils_addBoolEntry(celix_array_list_t* list, const char* 
entry) {
+    bool converted;
+    bool b = celix_utils_convertStringToBool(entry, 0.0, &converted);
+    if (!converted) {
+        return CELIX_ILLEGAL_ARGUMENT;
+    }
+    return celix_arrayList_addBool(list, b);
+}
+
+celix_status_t celix_utils_convertStringToBoolArrayList(const char* val,
+                                                          const 
celix_array_list_t* defaultValue,
+                                                          celix_array_list_t** 
list) {
+    return celix_utils_convertStringToArrayList(val, defaultValue, list, NULL, 
celix_utils_addBoolEntry);
+}
+
+celix_status_t celix_utils_addStringEntry(celix_array_list_t* list, const 
char* entry) {
+    char* copy = celix_utils_strdup(entry);
+    if (!copy) {
+            return CELIX_ENOMEM;
+    }
+    return celix_arrayList_add(list, copy);
+}
+
+celix_status_t celix_utils_convertStringToStringArrayList(const char* val,
+                                                          const 
celix_array_list_t* defaultValue,
+                                                          celix_array_list_t** 
list) {
+    return celix_utils_convertStringToArrayList(val, defaultValue, list, free, 
celix_utils_addStringEntry);
+}
+
+static celix_status_t celix_utils_addVersionEntry(celix_array_list_t* list, 
const char* entry) {
+    celix_version_t* version;
+    celix_status_t convertStatus = celix_utils_convertStringToVersion(entry, 
NULL, &version);
+    if (convertStatus == CELIX_SUCCESS) {
+        return celix_arrayList_add(list, version);
+    }
+    return convertStatus;
+}
+
+static void celix_utils_destroyVersionEntry(void* entry) { 
celix_version_destroy(entry); }
+
+celix_status_t celix_utils_convertStringToVersionArrayList(const char* val,
+                                                           const 
celix_array_list_t* defaultValue,
+                                                           
celix_array_list_t** list) {
+    return celix_utils_convertStringToArrayList(
+        val, defaultValue, list, celix_utils_destroyVersionEntry, 
celix_utils_addVersionEntry);
 }
 
 /**
@@ -187,7 +274,8 @@ celix_status_t 
celix_utils_convertStringToLongArrayList(const char* val, const c
  * @param printCb The callback to use for printing the list entries.
  * @return The string representation of the list or NULL if an error occurred.
  */
-static char* celix_utils_arrayListToString(const celix_array_list_t *list, int 
(*printCb)(FILE* stream, const celix_array_list_entry_t* entry)) {
+static char* celix_utils_arrayListToString(const celix_array_list_t* list,
+                                           int (*printCb)(FILE* stream, const 
celix_array_list_entry_t* entry)) {
     char* result = NULL;
     size_t len;
     celix_autoptr(FILE) stream = open_memstream(&result, &len);
@@ -216,30 +304,46 @@ static int celix_utils_printLongEntry(FILE* stream, const 
celix_array_list_entry
     return fprintf(stream, "%li", entry->longVal);
 }
 
-//static int celix_properties_printDoubleEntry(FILE* stream, const 
celix_array_list_entry_t* entry) {
-//    return fprintf(stream, "%lf", entry->doubleVal);
-//}
-//
-//static int celix_properties_printBoolEntry(FILE* stream, const 
celix_array_list_entry_t* entry) {
-//    return fprintf(stream, "%s", entry->boolVal ? "true" : "false");
-//}
-//
-//static int celix_properties_printStrEntry(FILE* stream, const 
celix_array_list_entry_t* entry) {
-//    return fprintf(stream, "%s", (const char*)entry->voidPtrVal);
-//}
-
 char* celix_utils_longArrayListToString(const celix_array_list_t* list) {
     return celix_utils_arrayListToString(list, celix_utils_printLongEntry);
 }
 
-//static char* celix_properties_doubleArrayListToString(const 
celix_array_list_t* list) {
-//    return celix_properties_arrayListToString(list, 
celix_properties_printDoubleEntry);
-//}
-//
-//static char* celix_properties_boolArrayListToString(const 
celix_array_list_t* list) {
-//    return celix_properties_arrayListToString(list, 
celix_properties_printBoolEntry);
-//}
-//
-//static char* celix_properties_stringArrayListToString(const 
celix_array_list_t* list) {
-//    return celix_properties_arrayListToString(list, 
celix_properties_printStrEntry);
-//}
\ No newline at end of file
+static int celix_utils_printDoubleEntry(FILE* stream, const 
celix_array_list_entry_t* entry) {
+    return fprintf(stream, "%lf", entry->doubleVal);
+}
+
+char* celix_utils_doubleArrayListToString(const celix_array_list_t* list) {
+    return celix_utils_arrayListToString(list, celix_utils_printDoubleEntry);
+}
+
+static int celix_utils_printBoolEntry(FILE* stream, const 
celix_array_list_entry_t* entry) {
+    return fprintf(stream, "%s", entry->boolVal ? "true" : "false");
+}
+
+char* celix_utils_boolArrayListToString(const celix_array_list_t* list) {
+    return celix_utils_arrayListToString(list, celix_utils_printBoolEntry);
+}
+
+static int celix_utils_printStrEntry(FILE* stream, const 
celix_array_list_entry_t* entry) {
+    return fprintf(stream, "%s", (const char*)entry->voidPtrVal);
+}
+
+char* celix_utils_stringArrayListToString(const celix_array_list_t* list) {
+    return celix_utils_arrayListToString(list, celix_utils_printStrEntry);
+}
+
+static int celix_utils_printVersionEntry(FILE* stream, const 
celix_array_list_entry_t* entry) {
+    celix_version_t* version = entry->voidPtrVal;
+    int major = celix_version_getMajor(version);
+    int minor = celix_version_getMinor(version);
+    int micro = celix_version_getMicro(version);
+    const char* q = celix_version_getQualifier(version);
+    if (celix_utils_isStringNullOrEmpty(q)) {
+        return fprintf(stream, "%i.%i.%i", major, minor, micro);
+    }
+    return fprintf(stream, "%i.%i.%i.%s", major, minor, micro, q);
+}
+
+char* celix_utils_versionArrayListToString(const celix_array_list_t* list) {
+    return celix_utils_arrayListToString(list, celix_utils_printVersionEntry);
+}

Reply via email to