aqhome: make delimiter a function argument instead of hardcoding "/".
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user