Eina: fix eina_file_split on Windows and update unit test

@fix

Signed-off-by: Jean-Philippe Andre <jp.andre@samsung.com>
This commit is contained in:
Vincent Torri 2015-04-29 07:52:31 +02:00 committed by Jean-Philippe Andre
parent 2e6e14dd73
commit e55a3f1af8
2 changed files with 20 additions and 21 deletions

View File

@ -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')

View File

@ -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