From dd86214d77a4abf9ac160c2c63ae1bb448a5ba2d Mon Sep 17 00:00:00 2001 From: Sigrid Date: Fri, 30 Apr 2021 00:20:39 +0200 Subject: [PATCH] libtags: trim text tags and ignore empty values --- sys/src/cmd/audio/libtags/tags.c | 15 +++++++++++++-- sys/src/cmd/audio/libtags/tagspriv.h | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/sys/src/cmd/audio/libtags/tags.c b/sys/src/cmd/audio/libtags/tags.c index e6fa85962..e46e0c474 100644 --- a/sys/src/cmd/audio/libtags/tags.c +++ b/sys/src/cmd/audio/libtags/tags.c @@ -36,13 +36,24 @@ static const Getter g[] = }; 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<num++; } - ctx->tag(ctx, type, k, s, offset, size, f); + if(*s) + ctx->tag(ctx, type, k, s, offset, size, f); } int diff --git a/sys/src/cmd/audio/libtags/tagspriv.h b/sys/src/cmd/audio/libtags/tagspriv.h index f8ed4d1ad..f77a21651 100644 --- a/sys/src/cmd/audio/libtags/tagspriv.h +++ b/sys/src/cmd/audio/libtags/tagspriv.h @@ -39,6 +39,6 @@ int cp437toutf8(char *o, int osz, const char *s, int sz); */ 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)