diff options
author | Sigrid <ftrvxmtrx@gmail.com> | 2021-04-30 00:20:39 +0200 |
---|---|---|
committer | Sigrid <ftrvxmtrx@gmail.com> | 2021-04-30 00:20:39 +0200 |
commit | dd86214d77a4abf9ac160c2c63ae1bb448a5ba2d (patch) | |
tree | ee66c48a673939e78977cc51e6b2ece39d8edf7d | |
parent | e5535fad320c9ba0e75f419117ab2ae6c0bcbb09 (diff) | |
download | plan9front-dd86214d77a4abf9ac160c2c63ae1bb448a5ba2d.tar.xz |
libtags: trim text tags and ignore empty values
-rw-r--r-- | sys/src/cmd/audio/libtags/tags.c | 15 | ||||
-rw-r--r-- | 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<<type; ctx->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) |