diff --git a/taglib/toolkit/tpropertymap.cpp b/taglib/toolkit/tpropertymap.cpp index 08b94ba7..00aeca88 100644 --- a/taglib/toolkit/tpropertymap.cpp +++ b/taglib/toolkit/tpropertymap.cpp @@ -43,7 +43,11 @@ bool PropertyMap::insert(const String &key, const StringList &values) if (realKey.isNull()) return false; - supertype::operator[](realKey).append(values); + Iterator result = supertype::find(realKey); + if (result == end()) + supertype::insert(realKey, values); + else + supertype::operator[](realKey).append(values); return true; } @@ -102,13 +106,14 @@ const StringList &PropertyMap::operator[](const String &key) const StringList &PropertyMap::operator[](const String &key) { String realKey = prepareKey(key); - if (realKey.isNull()) - return supertype::operator[](realKey); // invalid case - if (!supertype::contains(realKey)) - supertype::insert(realKey, StringList()); return supertype::operator[](realKey); } +StringList &PropertyMap::unsupportedData() +{ + return unsupported; +} + String PropertyMap::prepareKey(const String &proposed) const { if (proposed.isEmpty()) return String::null; diff --git a/taglib/toolkit/tpropertymap.h b/taglib/toolkit/tpropertymap.h index f82a7dfb..2025873d 100644 --- a/taglib/toolkit/tpropertymap.h +++ b/taglib/toolkit/tpropertymap.h @@ -41,7 +41,7 @@ namespace TagLib { * */ - class PropertyMap: public Map + class TAGLIB_EXPORT PropertyMap: public Map { public: @@ -93,25 +93,38 @@ namespace TagLib { /*! * Returns a reference to the value associated with \a key. * - * \note: This has undefined behavior if the key is not valid. + * \note: This has undefined behavior if the key is not valid or not + * present in the map. */ const StringList &operator[](const String &key) const; /*! * Returns a reference to the value associated with \a key. * - * If \a key is not present in the map, an empty list is inserted and - * returned. - * - * \note: This has undefined behavior if the key is not valid. + * \note: This has undefined behavior if the key is not valid or not + * present in the map. */ StringList &operator[](const String &key); + /*! + * If a PropertyMap is read from a File object using File::properties(), + * the StringList returned from this function will represent metadata + * that could not be parsed into the PropertyMap representation. This could + * be e.g. binary data, unknown ID3 frames, etc. + * You can remove items from the returned list, which tells TagLib to remove + * those unsupported elements if you call File::setProperties() with the + * same PropertyMap as argument. + */ + StringList &unsupportedData(); + + private: + /*! * Converts \a proposed into another String suitable to be used as * a key, or returns String::null if this is not possible. */ String prepareKey(const String &proposed) const; + StringList unsupported; }; }