From e2f71f509fde010e4d0f175014fd4219b7dc7681 Mon Sep 17 00:00:00 2001 From: Kevin Mitchell Date: Sat, 23 Dec 2017 19:14:16 -0700 Subject: tags: add mp_tags_remove This removes all tags matching the provided key. This will be used for removing metadata tags during encoding. --- common/tags.c | 19 +++++++++++++++++++ common/tags.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/common/tags.c b/common/tags.c index 29459d09e3..ffedab9b24 100644 --- a/common/tags.c +++ b/common/tags.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "tags.h" #include "misc/bstr.h" @@ -44,6 +45,24 @@ void mp_tags_set_bstr(struct mp_tags *tags, bstr key, bstr value) tags->num_keys++; } +void mp_tags_remove_str(struct mp_tags *tags, const char *key) +{ + mp_tags_remove_bstr(tags, bstr0(key)); +} + +void mp_tags_remove_bstr(struct mp_tags *tags, bstr key) +{ + for (int n = 0; n < tags->num_keys; n++) { + if (bstrcasecmp0(key, tags->keys[n]) == 0) { + talloc_free(tags->keys[n]); + talloc_free(tags->values[n]); + int num_keys = tags->num_keys; // copy so it's only decremented once + MP_TARRAY_REMOVE_AT(tags->keys, num_keys, n); + MP_TARRAY_REMOVE_AT(tags->values, tags->num_keys, n); + } + } +} + char *mp_tags_get_str(struct mp_tags *tags, const char *key) { return mp_tags_get_bstr(tags, bstr0(key)); diff --git a/common/tags.h b/common/tags.h index dc8539d98f..3e538e7b76 100644 --- a/common/tags.h +++ b/common/tags.h @@ -11,6 +11,8 @@ struct mp_tags { void mp_tags_set_str(struct mp_tags *tags, const char *key, const char *value); void mp_tags_set_bstr(struct mp_tags *tags, bstr key, bstr value); +void mp_tags_remove_str(struct mp_tags *tags, const char *key); +void mp_tags_remove_bstr(struct mp_tags *tags, bstr key); char *mp_tags_get_str(struct mp_tags *tags, const char *key); char *mp_tags_get_bstr(struct mp_tags *tags, bstr key); void mp_tags_clear(struct mp_tags *tags); -- cgit v1.2.3