ref: dd86214d77a4abf9ac160c2c63ae1bb448a5ba2d
parent: e5535fad320c9ba0e75f419117ab2ae6c0bcbb09
author: Sigrid <ftrvxmtrx@gmail.com>
date: Thu Apr 29 20:20:39 EDT 2021
libtags: trim text tags and ignore empty values
--- a/sys/src/cmd/audio/libtags/tags.c
+++ b/sys/src/cmd/audio/libtags/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/sys/src/cmd/audio/libtags/tagspriv.h
+++ b/sys/src/cmd/audio/libtags/tagspriv.h
@@ -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)