From 3e5bff90d1853624d4329696f678c6707cdad6bf Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Wed, 8 May 2024 00:41:14 +0200 Subject: [PATCH] aqhome: make delimiter a function argument instead of hardcoding "/". --- aqhome/data/path-t.c | 28 +++++++++++++++++++++++++--- aqhome/data/path.c | 4 ++-- aqhome/data/path.h | 2 +- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/aqhome/data/path-t.c b/aqhome/data/path-t.c index 9335caf..8aa214d 100644 --- a/aqhome/data/path-t.c +++ b/aqhome/data/path-t.c @@ -33,6 +33,7 @@ struct PATH_TEST_ENTRY { static int GWENHYWFAR_CB test1(GWEN_TEST_MODULE *mod); static int GWENHYWFAR_CB test2(GWEN_TEST_MODULE *mod); static int GWENHYWFAR_CB test3(GWEN_TEST_MODULE *mod); +static int GWENHYWFAR_CB test4(GWEN_TEST_MODULE *mod); static void *_cbTestElement(const char *element, void *data, int idx, uint32_t flags); @@ -53,6 +54,7 @@ int AQH_Path_AddTests(GWEN_TEST_MODULE *mod) GWEN_Test_Module_AddTest(newMod, "test 1: path with index", test1, NULL); GWEN_Test_Module_AddTest(newMod, "test 2: path without index", test2, NULL); GWEN_Test_Module_AddTest(newMod, "test 3: path with backspace escape", test3, NULL); + GWEN_Test_Module_AddTest(newMod, "test 4: path with index and different delimiter", test4, NULL); return 0; } @@ -69,7 +71,7 @@ int test1(GWEN_UNUSED GWEN_TEST_MODULE *mod) {NULL, 0, 0} }; - if (AQH_Path_Handle(path, expected, AQH_PATH_FLAGS_PARSEIDX, _cbTestElement)==NULL) { + if (AQH_Path_Handle(path, expected, AQH_PATH_FLAGS_PARSEIDX, "/", _cbTestElement)==NULL) { DBG_ERROR(NULL, "Error handling patch \"%s\"", path); return GWEN_ERROR_GENERIC; } @@ -89,7 +91,7 @@ int test2(GWEN_UNUSED GWEN_TEST_MODULE *mod) {NULL, 0, 0} }; - if (AQH_Path_Handle(path, expected, 0, _cbTestElement)==NULL) { + if (AQH_Path_Handle(path, expected, 0, "/", _cbTestElement)==NULL) { DBG_ERROR(NULL, "Error handling patch \"%s\"", path); return GWEN_ERROR_GENERIC; } @@ -109,7 +111,27 @@ int test3(GWEN_UNUSED GWEN_TEST_MODULE *mod) {NULL, 0, 0} }; - if (AQH_Path_Handle(path, expected, AQH_PATH_FLAGS_PARSEIDX, _cbTestElement)==NULL) { + if (AQH_Path_Handle(path, expected, AQH_PATH_FLAGS_PARSEIDX, "/", _cbTestElement)==NULL) { + DBG_ERROR(NULL, "Error handling patch \"%s\"", path); + return GWEN_ERROR_GENERIC; + } + + return 0; +} + + + +int test4(GWEN_UNUSED GWEN_TEST_MODULE *mod) +{ + static char path[]="test1:test2[3]:test3[2]"; + static PATH_TEST_ENTRY expected[]={ + {"test1", 0, AQH_PATH_FLAGS_PARSEIDX}, + {"test2", 3, AQH_PATH_FLAGS_PARSEIDX}, + {"test3", 2, AQH_PATH_FLAGS_PARSEIDX | AQH_PATH_FLAGS_LAST}, + {NULL, 0, 0} + }; + + if (AQH_Path_Handle(path, expected, AQH_PATH_FLAGS_PARSEIDX, ":", _cbTestElement)==NULL) { DBG_ERROR(NULL, "Error handling patch \"%s\"", path); return GWEN_ERROR_GENERIC; } diff --git a/aqhome/data/path.c b/aqhome/data/path.c index 6c0f239..dfce77a 100644 --- a/aqhome/data/path.c +++ b/aqhome/data/path.c @@ -36,7 +36,7 @@ static void *_handleElement(const char *element, void *data, uint32_t flags, AQH * ------------------------------------------------------------------------------------------------ */ -void *AQH_Path_Handle(const char *path, void *data, uint32_t flags, AQH_PATH_HANDLERFN fn) +void *AQH_Path_Handle(const char *path, void *data, uint32_t flags, const char *delimiters, AQH_PATH_HANDLERFN fn) { if (path && *path) { GWEN_STRINGLIST *elementList; @@ -48,7 +48,7 @@ void *AQH_Path_Handle(const char *path, void *data, uint32_t flags, AQH_PATH_HAN flags|=AQH_PATH_FLAGS_ROOT; path++; } - elementList=GWEN_StringList_fromString2(path, "/", 0, GWEN_TEXT_FLAGS_CHECK_BACKSLASH | GWEN_TEXT_FLAGS_DEL_QUOTES); + elementList=GWEN_StringList_fromString2(path, delimiters, 0, GWEN_TEXT_FLAGS_CHECK_BACKSLASH | GWEN_TEXT_FLAGS_DEL_QUOTES); if (elementList) { GWEN_STRINGLISTENTRY *se; diff --git a/aqhome/data/path.h b/aqhome/data/path.h index 4ae1f39..421e946 100644 --- a/aqhome/data/path.h +++ b/aqhome/data/path.h @@ -34,7 +34,7 @@ typedef void *(*AQH_PATH_HANDLERFN)(const char *entry, void *data, int idx, uint -AQHOME_API void *AQH_Path_Handle(const char *path, void *data, uint32_t flags, AQH_PATH_HANDLERFN fn); +AQHOME_API void *AQH_Path_Handle(const char *path, void *data, uint32_t flags, const char *delimiters, AQH_PATH_HANDLERFN fn);