shithub: plan9front

Download patch

ref: dd86214d77a4abf9ac160c2c63ae1bb448a5ba2d
parent: e5535fad320c9ba0e75f419117ab2ae6c0bcbb09
author: Sigrid <ftrvxmtrx@gmail.com>
date: Thu Apr 29 18:20:39 EDT 2021

libtags: trim text tags and ignore empty values

--- a/sys/src/cmd/audio/libtags/tags.c	Thu Apr 29 17:35:52 2021
+++ b/sys/src/cmd/audio/libtags/tags.c	Thu Apr 29 18:20:39 2021
@@ -36,13 +36,24 @@
 };
 
 void
-tagscallcb(Tagctx *ctx, int type, const char *k, const char *s, int offset, int size, Tagread f)
+tagscallcb(Tagctx *ctx, int type, const char *k, char *s, int offset, int size, Tagread f)
 {
+	char *e;
+
+	if(f == nil && size == 0){
+		while(*s <= ' ' && *s)
+			s++;
+		e = s + strlen(s);
+		while(e != s && e[-1] <= ' ')
+			e--;
+		*e = 0;
+	}
 	if(type != Tunknown){
 		ctx->found |= 1<<type;
 		ctx->num++;
 	}
-	ctx->tag(ctx, type, k, s, offset, size, f);
+	if(*s)
+		ctx->tag(ctx, type, k, s, offset, size, f);
 }
 
 int
--- a/sys/src/cmd/audio/libtags/tagspriv.h	Thu Apr 29 17:35:52 2021
+++ b/sys/src/cmd/audio/libtags/tagspriv.h	Thu Apr 29 18:20:39 2021
@@ -39,6 +39,6 @@
  */
 void cbvorbiscomment(Tagctx *ctx, char *k, char *v);
 
-void tagscallcb(Tagctx *ctx, int type, const char *k, const char *s, int offset, int size, Tagread f);
+void tagscallcb(Tagctx *ctx, int type, const char *k, char *s, int offset, int size, Tagread f);
 
 #define txtcb(ctx, type, k, s) tagscallcb(ctx, type, k, (const char*)s, 0, 0, nil)