misc/path_utils: add mp_basename_bstr()
This will be used by bstr_get_ext() and bstr_split_ext() without allocating memory.
This commit is contained in:
1 parent
9bfdb3d67f
commit
29c26b5bc5
2 files changed
+19
-11
No files matched your search
+18
-11
@@ -39,22 +39,29 @@
|
||||
#include <pathcch.h>
|
||||
#endif
|
||||
|
||||
const char *mp_basename(const char *path)
|
||||
bstr mp_basename_bstr(bstr path)
|
||||
{
|
||||
const char *s;
|
||||
int separator_pos;
|
||||
|
||||
#if HAVE_DOS_PATHS
|
||||
if (!mp_is_url(bstr0(path))) {
|
||||
s = strrchr(path, '\\');
|
||||
if (s)
|
||||
path = s + 1;
|
||||
s = strrchr(path, ':');
|
||||
if (s)
|
||||
path = s + 1;
|
||||
if (!mp_is_url(path)) {
|
||||
separator_pos = bstrrchr(path, '\\');
|
||||
if (separator_pos >= 0)
|
||||
path = bstr_splice(path, separator_pos + 1, path.len);
|
||||
separator_pos = bstrrchr(path, ':');
|
||||
if (separator_pos >= 0)
|
||||
path = bstr_splice(path, separator_pos + 1, path.len);
|
||||
}
|
||||
#endif
|
||||
s = strrchr(path, '/');
|
||||
return s ? s + 1 : path;
|
||||
separator_pos = bstrrchr(path, '/');
|
||||
if (separator_pos < 0)
|
||||
return path;
|
||||
return bstr_splice(path, separator_pos + 1, path.len);
|
||||
}
|
||||
|
||||
const char *mp_basename(const char *path)
|
||||
{
|
||||
return mp_basename_bstr(bstr0(path)).start;
|
||||
}
|
||||
|
||||
struct bstr mp_dirname(const char *path)
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
// Return pointer to filename part of path
|
||||
|
||||
const char *mp_basename(const char *path);
|
||||
bstr mp_basename_bstr(bstr path);
|
||||
|
||||
/* Return file extension, excluding the '.'. If root is not NULL, set it to the
|
||||
* part of the path without extension. So: path == root + "." + extension
|
||||
|
||||
Reference in new issue
Block a user