external_files: deduplicate bstr functions

This commit is contained in:
Kevin Mitchell 2015-11-06 23:40:34 -08:00
parent 03bbaad686
commit 434512827f
1 changed files with 4 additions and 20 deletions

View File

@ -40,25 +40,9 @@ static int test_ext(bstr ext)
return -1;
}
static struct bstr strip_ext(struct bstr str)
{
int dotpos = bstrrchr(str, '.');
if (dotpos < 0)
return str;
return (struct bstr){str.start, dotpos};
}
static struct bstr get_ext(struct bstr s)
{
int dotpos = bstrrchr(s, '.');
if (dotpos < 0)
return (struct bstr){NULL, 0};
return bstr_splice(s, dotpos + 1, s.len);
}
bool mp_might_be_subtitle_file(const char *filename)
{
return test_ext(get_ext(bstr0(filename))) == STREAM_SUB;
return test_ext(bstr_get_ext(bstr0(filename))) == STREAM_SUB;
}
static int compare_sub_filename(const void *a, const void *b)
@ -113,7 +97,7 @@ static void append_dir_subtitles(struct mpv_global *global,
goto out;
struct bstr f_fname = bstr0(mp_basename(fname));
struct bstr f_fname_noext = bstrdup(tmpmem, strip_ext(f_fname));
struct bstr f_fname_noext = bstrdup(tmpmem, bstr_strip_ext(f_fname));
bstr_lower(f_fname_noext);
struct bstr f_fname_trim = bstr_strip(f_fname_noext);
@ -132,9 +116,9 @@ static void append_dir_subtitles(struct mpv_global *global,
void *tmpmem2 = talloc_new(tmpmem);
// retrieve various parts of the filename
struct bstr tmp_fname_noext = bstrdup(tmpmem2, strip_ext(dename));
struct bstr tmp_fname_noext = bstrdup(tmpmem2, bstr_strip_ext(dename));
bstr_lower(tmp_fname_noext);
struct bstr tmp_fname_ext = get_ext(dename);
struct bstr tmp_fname_ext = bstr_get_ext(dename);
struct bstr tmp_fname_trim = bstr_strip(tmp_fname_noext);
// check what it is (most likely)