diff options
author | Urs Fleisch <ufleisch@users.sourceforge.net> | 2020-12-13 12:37:20 +0100 |
---|---|---|
committer | Urs Fleisch <ufleisch@users.sourceforge.net> | 2020-12-13 12:37:20 +0100 |
commit | 61d5bcfd5b35df7f647d8d172d4089cf79be469c (patch) | |
tree | c76a04bbcd4d74dc6b0a32c4aaaec2eb0aef8a6a /taglib/mp4 | |
parent | 91b00b17b253dad0d7037232ef7033c88bdd28bd (diff) |
MP4: Remove item when empty string is set (#929)
This will make the behavior for MP4 tags compliant to the API
documentation and consistent with other tag formats.
Diffstat (limited to 'taglib/mp4')
-rw-r--r-- | taglib/mp4/mp4tag.cpp | 20 | ||||
-rw-r--r-- | taglib/mp4/mp4tag.h | 7 |
2 files changed, 22 insertions, 5 deletions
diff --git a/taglib/mp4/mp4tag.cpp b/taglib/mp4/mp4tag.cpp index bc95ad10..de41c58d 100644 --- a/taglib/mp4/mp4tag.cpp +++ b/taglib/mp4/mp4tag.cpp @@ -775,31 +775,41 @@ MP4::Tag::track() const void MP4::Tag::setTitle(const String &value) { - d->items["\251nam"] = StringList(value); + setTextItem("\251nam", value); } void MP4::Tag::setArtist(const String &value) { - d->items["\251ART"] = StringList(value); + setTextItem("\251ART", value); } void MP4::Tag::setAlbum(const String &value) { - d->items["\251alb"] = StringList(value); + setTextItem("\251alb", value); } void MP4::Tag::setComment(const String &value) { - d->items["\251cmt"] = StringList(value); + setTextItem("\251cmt", value); } void MP4::Tag::setGenre(const String &value) { - d->items["\251gen"] = StringList(value); + setTextItem("\251gen", value); +} + +void +MP4::Tag::setTextItem(const String &key, const String &value) +{ + if (!value.isEmpty()) { + d->items[key] = StringList(value); + } else { + d->items.erase(key); + } } void diff --git a/taglib/mp4/mp4tag.h b/taglib/mp4/mp4tag.h index e5b70af3..ccee8e06 100644 --- a/taglib/mp4/mp4tag.h +++ b/taglib/mp4/mp4tag.h @@ -106,6 +106,13 @@ namespace TagLib { void removeUnsupportedProperties(const StringList& properties); PropertyMap setProperties(const PropertyMap &properties); + protected: + /*! + * Sets the value of \a key to \a value, overwriting any previous value. + * If \a value is empty, the item is removed. + */ + void setTextItem(const String &key, const String &value); + private: AtomDataList parseData2(const Atom *atom, int expectedFlags = -1, bool freeForm = false); |