summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/tags.c19
-rw-r--r--common/tags.h2
2 files changed, 21 insertions, 0 deletions
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 <stddef.h>
#include <limits.h>
#include <strings.h>
+#include <assert.h>
#include <libavutil/dict.h>
#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);