Use auto to reduce verbosity around code dealing with iterators
This commit is contained in:
parent
fde0f9e246
commit
9d8dd86945
@ -853,16 +853,12 @@ namespace Exiv2 {
|
||||
: str1.size() > str2.size() ? -1
|
||||
: 0
|
||||
;
|
||||
std::string::const_iterator c1 = str1.begin();
|
||||
std::string::const_iterator c2 = str2.begin();
|
||||
if ( result==0 ) for (
|
||||
; result==0 && c1 != str1.end()
|
||||
; ++c1, ++c2
|
||||
) {
|
||||
result = tolower(*c1) < tolower(*c2) ? 1
|
||||
: tolower(*c1) > tolower(*c2) ? -1
|
||||
: 0
|
||||
;
|
||||
if ( result==0 ) {
|
||||
for (auto c1 = str1.begin(), c2 = str2.begin() ; result==0 && c1 != str1.end() ; ++c1, ++c2 ) {
|
||||
result = tolower(*c1) < tolower(*c2) ? 1
|
||||
: tolower(*c1) > tolower(*c2) ? -1
|
||||
: 0 ;
|
||||
}
|
||||
}
|
||||
return result < 0 ;
|
||||
}
|
||||
@ -1543,8 +1539,7 @@ namespace Exiv2 {
|
||||
long ValueType<T>::copy(byte* buf, ByteOrder byteOrder) const
|
||||
{
|
||||
long offset = 0;
|
||||
typename ValueList::const_iterator end = value_.end();
|
||||
for (typename ValueList::const_iterator i = value_.begin(); i != end; ++i) {
|
||||
for (auto i = value_.begin(); i != value_.end(); ++i) {
|
||||
offset += toData(buf + offset, *i, byteOrder);
|
||||
}
|
||||
return offset;
|
||||
@ -1571,11 +1566,12 @@ namespace Exiv2 {
|
||||
template<typename T>
|
||||
std::ostream& ValueType<T>::write(std::ostream& os) const
|
||||
{
|
||||
typename ValueList::const_iterator end = value_.end();
|
||||
typename ValueList::const_iterator i = value_.begin();
|
||||
auto end = value_.end();
|
||||
auto i = value_.begin();
|
||||
while (i != end) {
|
||||
os << std::setprecision(15) << *i;
|
||||
if (++i != end) os << " ";
|
||||
if (++i != end)
|
||||
os << " ";
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
@ -1451,21 +1451,21 @@ namespace Action {
|
||||
Exiv2::XmpData& xmpData = pImage->xmpData();
|
||||
if (modifyCmd.metadataId_ == exif) {
|
||||
Exiv2::ExifData::iterator pos;
|
||||
Exiv2::ExifKey exifKey = Exiv2::ExifKey(modifyCmd.key_);
|
||||
const Exiv2::ExifKey exifKey(modifyCmd.key_);
|
||||
while((pos = exifData.findKey(exifKey)) != exifData.end()) {
|
||||
exifData.erase(pos);
|
||||
}
|
||||
}
|
||||
if (modifyCmd.metadataId_ == iptc) {
|
||||
Exiv2::IptcData::iterator pos;
|
||||
Exiv2::IptcKey iptcKey = Exiv2::IptcKey(modifyCmd.key_);
|
||||
const Exiv2::IptcKey iptcKey(modifyCmd.key_);
|
||||
while((pos = iptcData.findKey(iptcKey)) != iptcData.end()) {
|
||||
iptcData.erase(pos);
|
||||
}
|
||||
}
|
||||
if (modifyCmd.metadataId_ == xmp) {
|
||||
Exiv2::XmpData::iterator pos;
|
||||
Exiv2::XmpKey xmpKey = Exiv2::XmpKey(modifyCmd.key_);
|
||||
const Exiv2::XmpKey xmpKey (modifyCmd.key_);
|
||||
if((pos = xmpData.findKey(xmpKey)) != xmpData.end()) {
|
||||
xmpData.eraseFamily(pos);
|
||||
}
|
||||
|
||||
@ -729,15 +729,11 @@ namespace Exiv2 {
|
||||
|
||||
void CiffDirectory::doRemove(CrwDirs& crwDirs, uint16_t crwTagId)
|
||||
{
|
||||
const Components::iterator b = components_.begin();
|
||||
const Components::iterator e = components_.end();
|
||||
Components::iterator i;
|
||||
|
||||
if (!crwDirs.empty()) {
|
||||
CrwSubDir csd = crwDirs.top();
|
||||
crwDirs.pop();
|
||||
// Find the directory
|
||||
for (i = b; i != e; ++i) {
|
||||
for (auto i = components_.begin(); i != components_.end(); ++i) {
|
||||
if ((*i)->tag() == csd.crwDir_) {
|
||||
// Recursive call to next lower level directory
|
||||
(*i)->remove(crwDirs, crwTagId);
|
||||
@ -748,7 +744,7 @@ namespace Exiv2 {
|
||||
}
|
||||
else {
|
||||
// Find the tag
|
||||
for (i = b; i != e; ++i) {
|
||||
for (auto i = components_.begin(); i != components_.end(); ++i) {
|
||||
if ((*i)->tagId() == crwTagId) {
|
||||
// Remove the entry and abort the loop
|
||||
delete *i;
|
||||
|
||||
@ -791,12 +791,12 @@ namespace Exiv2 {
|
||||
{ pttIfd, "Thumbnail" }
|
||||
};
|
||||
bool delTags = false;
|
||||
ExifData::iterator pos;
|
||||
for (auto&& filteredPvTag : filteredPvTags) {
|
||||
switch (filteredPvTag.ptt_) {
|
||||
case pttLen:
|
||||
{
|
||||
delTags = false;
|
||||
pos = ed.findKey(ExifKey(filteredPvTag.key_));
|
||||
auto pos = ed.findKey(ExifKey(filteredPvTag.key_));
|
||||
if (pos != ed.end() && sumToLong(*pos) > 32768) {
|
||||
delTags = true;
|
||||
#ifndef SUPPRESS_WARNINGS
|
||||
@ -805,9 +805,11 @@ namespace Exiv2 {
|
||||
ed.erase(pos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case pttTag:
|
||||
{
|
||||
if (delTags) {
|
||||
pos = ed.findKey(ExifKey(filteredPvTag.key_));
|
||||
auto pos = ed.findKey(ExifKey(filteredPvTag.key_));
|
||||
if (pos != ed.end()) {
|
||||
#ifndef SUPPRESS_WARNINGS
|
||||
EXV_WARNING << "Exif tag " << pos->key() << " not encoded\n";
|
||||
@ -816,6 +818,7 @@ namespace Exiv2 {
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case pttIfd:
|
||||
if (delTags) {
|
||||
#ifndef SUPPRESS_WARNINGS
|
||||
|
||||
@ -31,7 +31,6 @@
|
||||
// + standard includes
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <fstream> // write the temporary file
|
||||
|
||||
// *****************************************************************************
|
||||
@ -514,9 +513,7 @@ namespace Exiv2 {
|
||||
std::copy(iptcData.begin(), iptcData.end(), std::back_inserter(sortedIptcData));
|
||||
std::stable_sort(sortedIptcData.begin(), sortedIptcData.end(), cmpIptcdataByRecord);
|
||||
|
||||
IptcData::const_iterator iter = sortedIptcData.begin();
|
||||
IptcData::const_iterator end = sortedIptcData.end();
|
||||
for ( ; iter != end; ++iter) {
|
||||
for (auto iter = sortedIptcData.cbegin() ; iter != sortedIptcData.cend(); ++iter) {
|
||||
// marker, record Id, dataset num
|
||||
*pWrite++ = marker_;
|
||||
*pWrite++ = static_cast<byte>(iter->record());
|
||||
|
||||
@ -1158,16 +1158,16 @@ namespace Exiv2 {
|
||||
{
|
||||
if ( ! metadata ) return os << "undefined" ;
|
||||
|
||||
auto dateIt = metadata->findKey(
|
||||
ExifKey("Exif.PentaxDng.Date"));
|
||||
auto dateIt = metadata->findKey(ExifKey("Exif.PentaxDng.Date"));
|
||||
if (dateIt == metadata->end()) {
|
||||
dateIt = metadata->findKey(ExifKey("Exif.Pentax.Date"));
|
||||
}
|
||||
auto timeIt = metadata->findKey(
|
||||
ExifKey("Exif.PentaxDng.Time"));
|
||||
|
||||
auto timeIt = metadata->findKey(ExifKey("Exif.PentaxDng.Time"));
|
||||
if (timeIt == metadata->end()) {
|
||||
timeIt = metadata->findKey(ExifKey("Exif.Pentax.Time"));
|
||||
}
|
||||
|
||||
if ( dateIt == metadata->end() || dateIt->size() != 4 ||
|
||||
timeIt == metadata->end() || timeIt->size() != 3 ||
|
||||
value.size() != 4) {
|
||||
@ -1219,11 +1219,11 @@ namespace Exiv2 {
|
||||
|
||||
// Throws std::exception if the LensInfo can't be found.
|
||||
static ExifData::const_iterator findLensInfo(const ExifData* metadata) {
|
||||
const ExifData::const_iterator dngLensInfo = metadata->findKey(ExifKey("Exif.PentaxDng.LensInfo"));
|
||||
const auto dngLensInfo = metadata->findKey(ExifKey("Exif.PentaxDng.LensInfo"));
|
||||
if (dngLensInfo != metadata->end()) {
|
||||
return dngLensInfo;
|
||||
}
|
||||
const ExifData::const_iterator lensInfo = metadata->findKey(ExifKey("Exif.Pentax.LensInfo"));
|
||||
const auto lensInfo = metadata->findKey(ExifKey("Exif.Pentax.LensInfo"));
|
||||
if (lensInfo != metadata->end()) {
|
||||
return lensInfo;
|
||||
}
|
||||
|
||||
@ -37,7 +37,6 @@
|
||||
// + standard includes
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
@ -4010,6 +4010,7 @@ namespace Exiv2 {
|
||||
void XmpProperties::unregisterNs()
|
||||
{
|
||||
std::lock_guard<std::mutex> scoped_write_lock(mutex_);
|
||||
/// \todo check if we are not unregistering the first NS
|
||||
auto i = nsRegistry_.begin();
|
||||
while (i != nsRegistry_.end()) {
|
||||
auto kill = i++;
|
||||
@ -4021,16 +4022,18 @@ namespace Exiv2 {
|
||||
{
|
||||
std::lock_guard<std::mutex> scoped_read_lock(mutex_);
|
||||
std::string ns2 = ns;
|
||||
if ( ns2.substr(ns2.size() - 1, 1) != "/"
|
||||
&& ns2.substr(ns2.size() - 1, 1) != "#") ns2 += "/";
|
||||
NsRegistry::const_iterator i = nsRegistry_.find(ns2);
|
||||
if (ns2.substr(ns2.size() - 1, 1) != "/" && ns2.substr(ns2.size() - 1, 1) != "#")
|
||||
ns2 += "/";
|
||||
|
||||
auto i = nsRegistry_.find(ns2);
|
||||
std::string p;
|
||||
if (i != nsRegistry_.end()) {
|
||||
p = i->second.prefix_;
|
||||
}
|
||||
else {
|
||||
const XmpNsInfo* xn = find(xmpNsInfo, XmpNsInfo::Ns(ns2));
|
||||
if (xn) p = std::string(xn->prefix_);
|
||||
if (xn)
|
||||
p = std::string(xn->prefix_);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
@ -1268,7 +1268,7 @@ namespace Exiv2 {
|
||||
|
||||
bool TiffReader::circularReference(const byte* start, IfdId group)
|
||||
{
|
||||
DirList::const_iterator pos = dirList_.find(start);
|
||||
auto pos = dirList_.find(start);
|
||||
if (pos != dirList_.end()) {
|
||||
#ifndef SUPPRESS_WARNINGS
|
||||
EXV_ERROR << groupName(group) << " pointer references previously read "
|
||||
|
||||
@ -654,10 +654,8 @@ namespace Exiv2 {
|
||||
XMP_Status result = 0 ;
|
||||
std::string out(buffer,bufferSize);
|
||||
|
||||
// remove blanks
|
||||
// http://stackoverflow.com/questions/83439/remove-spaces-from-stdstring-in-c
|
||||
std::string::iterator end_pos = std::remove(out.begin(), out.end(), ' ');
|
||||
out.erase(end_pos, out.end());
|
||||
// remove blanks: http://stackoverflow.com/questions/83439/remove-spaces-from-stdstring-in-c
|
||||
out.erase(std::remove_if(out.begin(), out.end(), std::isspace), out.end());
|
||||
|
||||
bool bURI = out.find("http://") != std::string::npos ;
|
||||
bool bNS = out.find(':') != std::string::npos && !bURI;
|
||||
|
||||
@ -390,7 +390,7 @@ TEST_F(stringSlice, mutateString)
|
||||
{
|
||||
Slice<std::string> is_a_mutable = makeSlice(this->sentence, 5, 10);
|
||||
|
||||
for (Slice<std::string>::iterator it = is_a_mutable.begin(); it < is_a_mutable.end(); ++it) {
|
||||
for (auto it = is_a_mutable.begin(); it < is_a_mutable.end(); ++it) {
|
||||
*it = ' ';
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user