shithub: libtags

Download patch

ref: 173b32f09bc04f114dc22bdfd0315402667c5fa7
parent: 7996f8dba6494fdafc13564924fae575419c7c14
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Apr 29 18:25:17 EDT 2021

trim text tags and ignore empty values

--- a/tags.c
+++ b/tags.c
@@ -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/tagspriv.h
+++ b/tagspriv.h
@@ -52,6 +52,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)
--- a/xm.c
+++ b/xm.c
@@ -3,12 +3,11 @@
 int
 tagxm(Tagctx *ctx)
 {
-	char d[17+20+1], o[20*UTFmax+1], *s;
+	char d[17+20+1], o[20*UTFmax+1];
 
 	if(ctx->read(ctx, d, 17+20) != 17+20 || memcmp(d, "Extended Module: ", 17) != 0)
 		return -1;
 	d[17+20] = 0;
-	for(s = d+17; *s == ' '; s++);
 	if(cp437toutf8(o, sizeof(o), d+17, 20) > 0)
 		txtcb(ctx, Ttitle, "", o);