From e55a3f1af84f9abd1b2ea89ef4ade90378bf9278 Mon Sep 17 00:00:00 2001 From: Vincent Torri Date: Wed, 29 Apr 2015 07:52:31 +0200 Subject: [PATCH] Eina: fix eina_file_split on Windows and update unit test @fix Signed-off-by: Jean-Philippe Andre --- src/lib/eina/eina_file_win32.c | 37 ++++++++++++++++----------------- src/tests/eina/eina_test_file.c | 4 ++-- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/lib/eina/eina_file_win32.c b/src/lib/eina/eina_file_win32.c index 01d0c9fa4c..c912ce3768 100644 --- a/src/lib/eina/eina_file_win32.c +++ b/src/lib/eina/eina_file_win32.c @@ -387,6 +387,16 @@ _eina_file_map_close(Eina_File_Map *map) free(map); } +static char * +_eina_file_sep_find(char *s) +{ + for (; *s != '\0'; ++s) + if ((*s == '\\') || (*s == '/')) + return s; + + return NULL; +} + /** * @endcond */ @@ -521,28 +531,17 @@ eina_file_split(char *path) if (!ea) return NULL; - current = path; - while (*current) + for (current = _eina_file_sep_find(path); + current; + path = current + 1, current = _eina_file_sep_find(path)) { - if ((*current == '\\') || (*current == '/')) - { - if (((*current == '\\') && (current[1] == '\\')) || - ((*current == '/') && (current[1] == '/'))) - { - *current = '\0'; - goto next_char; - } + length = current - path; - length = current - path; - if (length <= 0) - goto next_char; + if (length <= 0) + continue; - eina_array_push(ea, path); - *current = '\0'; - path = current + 1; - } - next_char: - current++; + eina_array_push(ea, path); + *current = '\0'; } if (*path != '\0') diff --git a/src/tests/eina/eina_test_file.c b/src/tests/eina/eina_test_file.c index 8dc123a4ab..c9ac36f089 100644 --- a/src/tests/eina/eina_test_file.c +++ b/src/tests/eina/eina_test_file.c @@ -101,7 +101,7 @@ START_TEST(eina_file_split_simple) #endif #ifdef _WIN32 - ea = eina_file_split(strdup("\\this\\is\\a\\small\\test")); + ea = eina_file_split(strdup("\\this/is\\a/small/test")); #else ea = eina_file_split(strdup("/this/is/a/small/test")); #endif @@ -119,7 +119,7 @@ START_TEST(eina_file_split_simple) #ifdef _WIN32 ea = eina_file_split(strdup( - "this\\\\is\\\\\\a \\more\\complex\\\\\\case\\\\\\")); + "this\\/\\is\\//\\\\a \\more/\\complex///case\\\\\\")); #else ea = eina_file_split(strdup("this//is///a /more/complex///case///")); #endif