From b97d510a9dd3f7d220d8543a9087c554bf96d6ee Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Tue, 13 Mar 2007 22:22:31 +0100 Subject: Modified method Image::deleteIptcTag(...) to take into account the possibility for an IPTC tag to be repeatable. --- src/libpyexiv2.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/libpyexiv2.cpp') diff --git a/src/libpyexiv2.cpp b/src/libpyexiv2.cpp index 9ce4a9d..22c4063 100644 --- a/src/libpyexiv2.cpp +++ b/src/libpyexiv2.cpp @@ -281,18 +281,25 @@ namespace LibPyExiv2 throw Exiv2::Error(METADATA_NOT_READ); } - boost::python::tuple Image::deleteIptcTag(std::string key) + boost::python::tuple Image::deleteIptcTag(std::string key, unsigned int index=0) { - boost::python::tuple returnValue; if(_dataRead) { + boost::python::tuple returnValue; + unsigned int indexCounter = index; Exiv2::IptcKey iptcKey = Exiv2::IptcKey(key); - Exiv2::IptcMetadata::iterator i = _iptcData.findKey(iptcKey); - if(i != _iptcData.end()) + Exiv2::IptcMetadata::iterator dataIterator = _iptcData.findKey(iptcKey); + while ((indexCounter > 0) && (dataIterator != _iptcData.end())) { - Exiv2::Iptcdatum iptcDatum = _iptcData[key]; - returnValue = boost::python::make_tuple(iptcDatum.typeName(), iptcDatum.toString()); - _iptcData.erase(i); + dataIterator = std::find_if(++dataIterator, _iptcData.end(), + Exiv2::FindMetadatumById::FindMetadatumById(iptcKey.tag(), iptcKey.record())); + --indexCounter; + } + if (dataIterator != _iptcData.end()) + { + // The tag at given index already exists, delete it + returnValue = boost::python::make_tuple(dataIterator->typeName(), dataIterator->toString()); + _iptcData.erase(dataIterator); return returnValue; } else -- cgit