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); free(map);
} }
static char *
_eina_file_sep_find(char *s)
{
for (; *s != '\0'; ++s)
if ((*s == '\\') || (*s == '/'))
return s;
return NULL;
}
/** /**
* @endcond * @endcond
*/ */
@ -521,28 +531,17 @@ eina_file_split(char *path)
if (!ea) if (!ea)
return NULL; return NULL;
current = path; for (current = _eina_file_sep_find(path);
while (*current) current;
path = current + 1, current = _eina_file_sep_find(path))
{ {
if ((*current == '\\') || (*current == '/')) length = current - path;
{
if (((*current == '\\') && (current[1] == '\\')) ||
((*current == '/') && (current[1] == '/')))
{
*current = '\0';
goto next_char;
}
length = current - path; if (length <= 0)
if (length <= 0) continue;
goto next_char;
eina_array_push(ea, path); eina_array_push(ea, path);
*current = '\0'; *current = '\0';
path = current + 1;
}
next_char:
current++;
} }
if (*path != '\0') if (*path != '\0')

View File

@ -101,7 +101,7 @@ START_TEST(eina_file_split_simple)
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
ea = eina_file_split(strdup("\\this\\is\\a\\small\\test")); ea = eina_file_split(strdup("\\this/is\\a/small/test"));
#else #else
ea = eina_file_split(strdup("/this/is/a/small/test")); ea = eina_file_split(strdup("/this/is/a/small/test"));
#endif #endif
@ -119,7 +119,7 @@ START_TEST(eina_file_split_simple)
#ifdef _WIN32 #ifdef _WIN32
ea = ea =
eina_file_split(strdup( eina_file_split(strdup(
"this\\\\is\\\\\\a \\more\\complex\\\\\\case\\\\\\")); "this\\/\\is\\//\\\\a \\more/\\complex///case\\\\\\"));
#else #else
ea = eina_file_split(strdup("this//is///a /more/complex///case///")); ea = eina_file_split(strdup("this//is///a /more/complex///case///"));
#endif #endif