summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Schafft <lion@lion.leolix.org>2017-07-24 14:13:02 +0000
committerPhilipp Schafft <lion@lion.leolix.org>2017-07-24 14:13:02 +0000
commitd8daafedcc5e3f467e8ff321b90cbdc621f82579 (patch)
tree0faaf367114b62978982e8e7101c73e9f1f9ce16
parented677ec711e9a95ae06365d076325232a3bc19a6 (diff)
downloadlibvorbis-git-d8daafedcc5e3f467e8ff321b90cbdc621f82579.tar.gz
Feature: Added functions to remove comments from vorbis_comment structure
This adds two new functions: * vorbis_comment_rm * vorbis_comment_rm_tag These allow the removal of tags from a vorbis_comment structure. vorbis_comment_rm allows to remove a tag selected by a provided string in format "KEY=Value". vorbis_comment_rm_tag implements removal using seperate strings for key and value. If no value is given the first comment using the key is removed.
-rw-r--r--include/vorbis/codec.h3
-rw-r--r--lib/info.c72
2 files changed, 75 insertions, 0 deletions
diff --git a/include/vorbis/codec.h b/include/vorbis/codec.h
index 42aa2913..402cc4fa 100644
--- a/include/vorbis/codec.h
+++ b/include/vorbis/codec.h
@@ -168,6 +168,9 @@ extern void vorbis_comment_init(vorbis_comment *vc);
extern void vorbis_comment_add(vorbis_comment *vc, const char *comment);
extern void vorbis_comment_add_tag(vorbis_comment *vc,
const char *tag, const char *contents);
+extern void vorbis_comment_rm(vorbis_comment *vc, const char *comment);
+extern void vorbis_comment_rm_tag(vorbis_comment *vc,
+ const char *tag, const char *contents);
extern char *vorbis_comment_query(vorbis_comment *vc, const char *tag, int count);
extern int vorbis_comment_query_count(vorbis_comment *vc, const char *tag);
extern void vorbis_comment_clear(vorbis_comment *vc);
diff --git a/lib/info.c b/lib/info.c
index 971f004a..4fb6bd03 100644
--- a/lib/info.c
+++ b/lib/info.c
@@ -85,6 +85,78 @@ static int tagcompare(const char *s1, const char *s2, int n){
return 0;
}
+void vorbis_comment_rm(vorbis_comment *vc, const char *comment){
+ long i;
+ size_t taglen;
+ const char *eq;
+
+ eq = strchr(comment, '=');
+ if (eq) {
+ eq++; /* Move to what is behind '='. */
+ taglen = eq - comment;
+ } else {
+ taglen = strlen(comment);
+ }
+
+ for(i=0;i<vc->comments;i++){
+ if (tagcompare(vc->user_comments[i], comment, taglen)) {
+ /* Tag name does not match -> try next comment. */
+ continue;
+ }
+
+ if (eq) {
+ /* As we already know that we share the same tag name it is safe to asume
+ * the comment is at least taglen long ('\0' not counted). */
+ if (strcmp(vc->user_comments[i] + taglen, eq)) {
+ /* Tag value does not match -> try next comment. */
+ continue;
+ }
+ }
+
+ /* At this point we found a matching tag. Now let's remove it. */
+ _ogg_free(vc->user_comments[i]);
+ memmove(&(vc->user_comments[i]), &(vc->user_comments[i+1]),
+ sizeof(vc->user_comments[i])*(vc->comments - i - 1));
+ vc->comments--;
+ return;
+ }
+}
+
+void vorbis_comment_rm_tag(vorbis_comment *vc, const char *tag, const char *contents){
+ long i;
+ size_t taglen = strlen(tag);
+
+ for(i=0;i<vc->comments;i++){
+ if (tagcompare(vc->user_comments[i], tag, taglen)) {
+ /* Tag name does not match -> try next comment. */
+ continue;
+ }
+
+ /* As we already know that we share the same tag name it is safe to asume
+ * the comment is at least taglen long ('\0' not counted). */
+
+ if (vc->user_comments[i][taglen] != '=') {
+ /* The tag in our comment does not end at the same position as
+ * the provided tag does -> try next comment. */
+ continue;
+ }
+
+ if (contents) {
+ if (strcmp(vc->user_comments[i] + taglen + 1, contents)) {
+ /* Tag value does not match -> try next comment. */
+ continue;
+ }
+ }
+
+ /* At this point we found a matching tag. Now let's remove it. */
+ _ogg_free(vc->user_comments[i]);
+ memmove(&(vc->user_comments[i]), &(vc->user_comments[i+1]),
+ sizeof(vc->user_comments[i])*(vc->comments - i - 1));
+ vc->comments--;
+ return;
+ }
+}
+
char *vorbis_comment_query(vorbis_comment *vc, const char *tag, int count){
long i;
int found = 0;