Skip to content

unify functions to get and strip file extensions#17531

Open
guidocella wants to merge 8 commits intompv-player:masterfrom
guidocella:gpu-next-strip-ext
Open

unify functions to get and strip file extensions#17531
guidocella wants to merge 8 commits intompv-player:masterfrom
guidocella:gpu-next-strip-ext

Conversation

@guidocella
Copy link
Copy Markdown
Contributor

video/out/vo_gpu_next: use bstr_strip_ext()

This is simpler and will allow making mp_splitext() static.

misc/path_utils: add mp_get_ext()

This is easier to understand than mp_splitext(s, NULL);

various: use mp_get_ext()

misc/path_utils: make mp_splitpath() static

It is no longer used anywhere. Also rename it to mp_split_path().

@kasper93
Copy link
Copy Markdown
Member

kasper93 commented Mar 10, 2026

Why do we even have duplicated this functionally?

Why not call bstr_get_ext and bstr_strip_ext? Could have wrappers to make it transparent for the users, but the implementation should be common.

@guidocella
Copy link
Copy Markdown
Contributor Author

Yeah I wanted to make one wrap the other afterwards since only mp_splitpath handles multiple leading dots and backslash separators. Or we can just leave only the bstr functions.

@kasper93
Copy link
Copy Markdown
Member

Or we can just leave only the bstr functions.

Yes, that works. Unless it makes it complicated on calls, then can have simple wrapper.

@guidocella
Copy link
Copy Markdown
Contributor Author

Actually bstr_strip_ext and bstr_get_ext would have to allocate memory to call mp_splitext. Reimplementing that in bstr.c would also need to allocate memory to call mp_basename.

@guidocella guidocella force-pushed the gpu-next-strip-ext branch 5 times, most recently from 49d817e to bc8323f Compare March 27, 2026 17:29
@guidocella guidocella changed the title misc/path_utils: add mp_get_ext() unify functions to get and strip file extensions Mar 27, 2026
#if HAVE_DOS_PATHS
if (!mp_is_url(path)) {
separator_pos = bstrrchr(path, '\\');
if (separator_pos < 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check is inverted.

@guidocella guidocella force-pushed the gpu-next-strip-ext branch 2 times, most recently from f35f5d0 to 0b885f7 Compare March 27, 2026 21:40
Because it is simpler than mp_splitext(), and will allow removing
mp_splitext().
This will be used by bstr_get_ext() and bstr_split_ext() without
allocating memory.
This will be used by bstr_get_ext() and bstr_strip_ext() without
allocating memory.

Unlike in the C string version mp_assert(path.start) is not called
because it is not needed, and would make TEST_LANG_GUESS(NULL, "", -1, 0)
in test/language.c fail.
Move bstr_strip_ext() and bstr_get_ext() to path_utils.c making them use
split_ext(), which is better than the previous bstr.c implementation
because it doesn't consider . in the dirname or at the start of
basenames.
This will allow removing mp_strip_ext().
This will allow removing mp_splitext().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants