Skip to content

string related fixes#17668

Open
na-na-hi wants to merge 10 commits intompv-player:masterfrom
na-na-hi:misc-str
Open

string related fixes#17668
na-na-hi wants to merge 10 commits intompv-player:masterfrom
na-na-hi:misc-str

Conversation

@na-na-hi
Copy link
Copy Markdown
Contributor

Various string related fixes. Add bstr_find_in_list function to unify several similar handlings and also use it to fix --cover-art-whitelist priority.

These functions are used to load all external files, not only
subtitles.
Similar to the method used elsewhere in mpv.
The documentation says that the scripts are loaded in alphabetical order,
which indicates that the case is not sensitive. Use strcasecmp to satisfy
this requirement.
These functions always set endptr to non-null so there is no need to
check.
Prevents UB if the value cannot be represented.
misc/bstr.c Outdated
return true;
}

int bstr_find_in_list(bstr str, char **list, bool case_sensitive)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

shouldn't this be bstr str, bstr *list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Converting char ** list to bstr * list is bothersome and needs memory allocation, so I want to keep it accepting char ** for now. How about renaming it to bstr_find_in_list0?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think list0 would be consistent with other bstr function naming.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, changed the name.


bstr ext = bstr_get_ext(bstr0(path));
if (autocreate & AUTO_VIDEO && str_in_list(ext, p->mp_opts->video_exts))
if (autocreate & AUTO_VIDEO && bstr_in_list(ext, p->mp_opts->video_exts, false))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does it have to be false everywhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

All current uses are false, but future changes can use true. Because it is a general function, if the parameter is dropped the function needs to be renamed to something like bstr_case_in_list which is less general and not much less typing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All current uses are false, but future changes can use true.

When future uses use true it can be evaluated how to proceed with that.

In general I don't see why you would need case sensitive lookup like that, in most cases you want it to be insensitive, so I don't expect future uses to change that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed to always case insensitive for bstr_in_list0.

This will be used to unify several find in list handlings.
Rename it to bstr_in_list0 and implement it in bstr_find_in_list0.
Removes redundant find_list_bstr function.
Since cb56c2f, the priority of
--cover-art-auto and --cover-art-whitelist is unclear. Depending on the
number of elements in --cover-art-whitelist, the priority of
--cover-art-whitelist files can be lower, equal, or higher than
--cover-art-auto matches, creating unpredictable behavior.

Fix this by making --cover-art-whitelist priority always between "fuzzy"
and "all" priority. test_cover_filename now uses bstr_find_in_list0 to
return a negative priority value depending on the position in list.
The "all" priority is set to INT_MIN. Modify filter_subidx to use 0
priority as removal marker, since all files in the external files list
already have non-zero priority.
They are not considered potential external files.
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.

2 participants