forked from enlightenment/efl
eina: new API: eina_file_path_basename
This commit is contained in:
parent
f8235ff5c1
commit
68282f8c42
|
@ -415,6 +415,22 @@ EAPI Eina_Iterator *eina_file_direct_ls(const char *dir) EINA_WARN_UNUSED_RESULT
|
|||
*/
|
||||
EAPI char *eina_file_path_sanitize(const char *path);
|
||||
|
||||
/**
|
||||
* @brief When given a path, delete everything up to last slash and return
|
||||
* the result.
|
||||
*
|
||||
* @param path The path string
|
||||
* @param suffix An optional suffix to strip out
|
||||
*
|
||||
* @return an allocated string with the base name.
|
||||
*
|
||||
* When @c suffix is not NULL, it's stripped out from the final path. When
|
||||
* the suffix doesn't match the actual suffix of the base name, nothing is
|
||||
* stripped. Path delimiters used depend on the operating system.
|
||||
*
|
||||
* @since 1.11
|
||||
*/
|
||||
EAPI char *eina_file_path_basename(const char *path, const char *suffix);
|
||||
|
||||
/**
|
||||
* @typedef Eina_File_Copy_Progress
|
||||
|
|
|
@ -361,6 +361,33 @@ eina_file_path_sanitize(const char *path)
|
|||
return _eina_file_escape(eina_file_cleanup(result), len);
|
||||
}
|
||||
|
||||
EAPI char *
|
||||
eina_file_path_basename(const char *path, const char *suffix)
|
||||
{
|
||||
char *str = eina_file_path_sanitize(path), *fname, *ret;
|
||||
Eina_Array *arr = eina_file_split(str);
|
||||
if (!arr)
|
||||
{
|
||||
free(str);
|
||||
return NULL;
|
||||
}
|
||||
fname = eina_array_data_get(arr, eina_array_count_get(arr) - 1);
|
||||
if (suffix && suffix[0])
|
||||
{
|
||||
size_t flen = strlen(fname);
|
||||
size_t slen = strlen(suffix);
|
||||
if (slen <= flen)
|
||||
{
|
||||
char *sf = fname + flen - slen;
|
||||
if (!strcmp(suffix, sf)) *sf = '\0';
|
||||
}
|
||||
}
|
||||
ret = strdup(fname);
|
||||
free(str);
|
||||
eina_array_free(arr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
EAPI Eina_File *
|
||||
eina_file_virtualize(const char *virtual_name, const void *data, unsigned long long length, Eina_Bool copy)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue