mirror of https://github.com/mpv-player/mpv
command: add helper function to split property paths
We've just checked whether a sub-path started with "name/", but that changes behavior whether the property name has a trailing '/' or not. Using a helper function to split of path components avoids this problem.
This commit is contained in:
parent
7cc985f3d0
commit
5cd20c7320
|
@ -232,6 +232,20 @@ int m_property_do(struct mp_log *log, const m_option_t *prop_list,
|
|||
}
|
||||
}
|
||||
|
||||
bool m_property_split_path(const char *path, bstr *prefix, char **rem)
|
||||
{
|
||||
char *next = strchr(path, '/');
|
||||
if (next) {
|
||||
*prefix = bstr_splice(bstr0(path), 0, next - path);
|
||||
*rem = next + 1;
|
||||
return true;
|
||||
} else {
|
||||
*prefix = bstr0(path);
|
||||
*rem = "";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static int m_property_do_bstr(const m_option_t *prop_list, bstr name,
|
||||
int action, void *arg, void *ctx)
|
||||
{
|
||||
|
|
|
@ -122,6 +122,12 @@ enum mp_property_return {
|
|||
int m_property_do(struct mp_log *log, const struct m_option* prop_list,
|
||||
const char* property_name, int action, void* arg, void *ctx);
|
||||
|
||||
// Given a path of the form "a/b/c", this function will set *prefix to "a",
|
||||
// and rem to "b/c", and return true.
|
||||
// If there is no '/' in the path, set prefix to path, and rem to "", and
|
||||
// return false.
|
||||
bool m_property_split_path(const char *path, bstr *prefix, char **rem);
|
||||
|
||||
// Print a list of properties.
|
||||
void m_properties_print_help_list(struct mp_log *log,
|
||||
const struct m_option* list);
|
||||
|
|
|
@ -853,16 +853,19 @@ static int tag_property(m_option_t *prop, int action, void *arg,
|
|||
}
|
||||
case M_PROPERTY_KEY_ACTION: {
|
||||
struct m_property_action_arg *ka = arg;
|
||||
bstr key = bstr0(ka->key);
|
||||
if (bstr_eatstart0(&key, "list/")) {
|
||||
bstr key;
|
||||
char *rem;
|
||||
m_property_split_path(ka->key, &key, &rem);
|
||||
if (bstr_equals0(key, "list")) {
|
||||
struct m_property_action_arg nka = *ka;
|
||||
nka.key = key.start; // ok because slice ends with \0
|
||||
nka.key = rem;
|
||||
return m_property_read_list(action, &nka, tags->num_keys,
|
||||
get_tag_entry, tags);
|
||||
}
|
||||
// Direct access without this prefix is allowed for compatibility.
|
||||
bstr_eatstart0(&key, "by-key/");
|
||||
char *meta = mp_tags_get_bstr(tags, key);
|
||||
bstr k = bstr0(ka->key);
|
||||
bstr_eatstart0(&k, "by-key/");
|
||||
char *meta = mp_tags_get_bstr(tags, k);
|
||||
if (!meta)
|
||||
return M_PROPERTY_UNKNOWN;
|
||||
switch (ka->action) {
|
||||
|
|
Loading…
Reference in New Issue