Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find changes #2462

Merged
merged 2 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions app/exiv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,19 @@ constexpr auto emptyYodAdjust_ = std::array{
};

//! List of all command identifiers and corresponding strings
constexpr auto cmdIdAndString = std::array{
std::pair(CmdId::add, "add"),
std::pair(CmdId::set, "set"),
std::pair(CmdId::del, "del"),
std::pair(CmdId::reg, "reg"),
std::pair(CmdId::invalid, "invalidCmd"), // End of list marker
constexpr struct CmdIdAndString {
CmdId cmdId_;
const char* string_;
//! Comparison operator for \em string
bool operator==(const std::string& string) const {
return string == string_;
}
} cmdIdAndString[] = {
{CmdId::add, "add"},
{CmdId::set, "set"},
{CmdId::del, "del"},
{CmdId::reg, "reg"},
{CmdId::invalid, "invalidCmd"}, // End of list marker
};

// Return a command Id for a command string
Expand Down Expand Up @@ -1433,8 +1440,8 @@ bool parseLine(ModifyCmd& modifyCmd, const std::string& line, int num) {
} // parseLine

CmdId commandId(const std::string& cmdString) {
auto it = std::find_if(cmdIdAndString.begin(), cmdIdAndString.end(), [&](auto cs) { return cs.second == cmdString; });
return it != cmdIdAndString.end() ? it->first : CmdId::invalid;
auto it = Exiv2::find(cmdIdAndString, cmdString);
return it ? it->cmdId_ : CmdId::invalid;
}

std::string parseEscapes(const std::string& input) {
Expand Down
13 changes: 5 additions & 8 deletions src/asfvideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ void AsfVideo::readMetadata() {
void AsfVideo::decodeBlock() {
DataBuf buf(BUFF_MIN_SIZE + 1);
uint64_t size = 0;
const Internal::TagVocabulary* tv;
uint64_t cur_pos = io_->tell();

byte guidBuf[GUI_SIZE];
Expand All @@ -278,12 +277,11 @@ void AsfVideo::decodeBlock() {

char GUID[GUID_SIZE] = ""; // the getGUID function write the GUID[36],

getGUID(guidBuf, GUID);
tv = find(GUIDReferenceTags, GUID);

io_->read(buf.data(), BUFF_MIN_SIZE);
size = Util::getUint64_t(buf);

getGUID(guidBuf, GUID);
auto tv = Exiv2::find(GUIDReferenceTags, GUID);
if (tv) {
auto tagDecoder = [&](const Internal::TagVocabulary* tv, uint64_t size) {
uint64_t cur_pos = io_->tell();
Expand Down Expand Up @@ -392,7 +390,7 @@ void AsfVideo::contentDescription(uint64_t size) {
io_->read(buf.data(), length[i]);
if (io_->error() || io_->eof())
throw Error(ErrorCode::kerFailedToReadImageData);
const TagDetails* td = find(contentDescriptionTags, i);
auto td = Exiv2::find(contentDescriptionTags, i);
assert(td);
std::string str(reinterpret_cast<const char*>(buf.data()), length[i]);
if (convertStringCharset(str, "UCS-2LE", "UTF-8")) {
Expand All @@ -414,8 +412,7 @@ void AsfVideo::streamProperties() {
char streamType[GUID_SIZE] = "";

getGUID(guidBuf, streamType);
const TagVocabulary* tv;
tv = find(GUIDReferenceTags, streamType);
auto tv = Exiv2::find(GUIDReferenceTags, streamType);
io_->read(guidBuf, GUI_SIZE);

if (compareTag(exvGettext(tv->label_), "Audio_Media"))
Expand Down Expand Up @@ -632,7 +629,7 @@ void AsfVideo::fileProperties() {
const TagDetails* td;

while (count--) {
td = find(filePropertiesTags, (count + 1));
td = Exiv2::find(filePropertiesTags, (count + 1));
io_->read(buf.data(), BUFF_MIN_SIZE);

if (count == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1553,8 +1553,8 @@ const ConvFctList convFctList[] = {

[[maybe_unused]] bool convertStringCharsetWindows(std::string& str, const char* from, const char* to) {
bool ret = false;
const ConvFctList* p = find(convFctList, std::pair(from, to));
std::string tmpstr = str;
auto p = Exiv2::find(convFctList, std::pair(from, to));
if (p)
ret = p->convFct_(tmpstr);
#ifndef SUPPRESS_WARNINGS
Expand Down
4 changes: 2 additions & 2 deletions src/epsimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ using namespace Exiv2::Internal;
constexpr auto dosEpsSignature = std::string_view("\xC5\xD0\xD3\xC6");

// first line of EPS
constexpr auto epsFirstLine = std::array<std::string_view, 3>{
constexpr std::string_view epsFirstLine[] = {
"%!PS-Adobe-3.0 EPSF-3.0",
"%!PS-Adobe-3.0 EPSF-3.0 ", // OpenOffice
"%!PS-Adobe-3.1 EPSF-3.0", // Illustrator
Expand Down Expand Up @@ -317,7 +317,7 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
#ifdef DEBUG
EXV_DEBUG << "readWriteEpsMetadata: First line: " << firstLine << "\n";
#endif
bool matched = std::find(epsFirstLine.begin(), epsFirstLine.end(), firstLine) != epsFirstLine.end();
auto matched = Exiv2::find(epsFirstLine, firstLine);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[discussion] auto here is taking the value of T *. Even though it is not needed, I normally find more readable to use auto * to declare the intention of using pointers. What do you think about this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like auto* mostly because of const. Eg.

auto = const char*
auto* = char*
const auto = const char* const
const auto* = const char*

Regular auto makes more sense IMO.

if (!matched) {
throw Error(ErrorCode::kerNotAnImage, "EPS");
}
Expand Down
4 changes: 2 additions & 2 deletions src/fujimn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ std::ostream& printFujiDriveSetting(std::ostream& os, const Value& value, const
auto byte3 = (value.toInt64() >> 16) & 0xff;
auto fps = value.toInt64() >> 24;

auto setting = find(fujiDriveSettingByte1, byte1);
auto setting = Exiv2::find(fujiDriveSettingByte1, byte1);
if (setting) {
os << exvGettext(setting->label_);
} else {
Expand Down Expand Up @@ -347,7 +347,7 @@ std::ostream& printFujiFaceElementTypes(std::ostream& os, const Value& value, co
longValue -= '0';
}

auto td = find(fujiFaceElementType, longValue);
auto td = Exiv2::find(fujiFaceElementType, longValue);
if (n != 0) {
os << " ";
}
Expand Down
84 changes: 47 additions & 37 deletions src/makernote_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ bool TiffMnRegistry::operator==(IfdId key) const {

TiffComponent* TiffMnCreator::create(uint16_t tag, IfdId group, const std::string& make, const byte* pData, size_t size,
ByteOrder byteOrder) {
auto tmr = std::find(std::begin(registry_), std::end(registry_), make);
if (tmr != std::end(registry_)) {
return tmr->newMnFct_(tag, group, tmr->mnGroup_, pData, size, byteOrder);
auto tmr = Exiv2::find(registry_, make);
if (!tmr) {
return nullptr;
}
return nullptr;
return tmr->newMnFct_(tag, group, tmr->mnGroup_, pData, size, byteOrder);
} // TiffMnCreator::create

TiffComponent* TiffMnCreator::create(uint16_t tag, IfdId group, IfdId mnGroup) {
auto tmr = std::find(std::begin(registry_), std::end(registry_), mnGroup);
if (tmr != std::end(registry_)) {
auto tmr = Exiv2::find(registry_, mnGroup);
if (tmr) {
if (tmr->newMnFct2_) {
return tmr->newMnFct2_(tag, group, mnGroup);
}
Expand Down Expand Up @@ -859,44 +859,55 @@ struct NikonArrayIdx {
#define NA ((uint32_t)-1)

//! Nikon binary array version lookup table
constexpr auto nikonArrayIdx = std::array{
constexpr NikonArrayIdx nikonArrayIdx[] = {
// NikonSi
NikonArrayIdx{0x0091, "0208", 0, 0, 4}, // D80
NikonArrayIdx{0x0091, "0209", 0, 1, 4}, // D40
NikonArrayIdx{0x0091, "0210", 5291, 2, 4}, // D300
NikonArrayIdx{0x0091, "0210", 5303, 3, 4}, // D300, firmware version 1.10
NikonArrayIdx{0x0091, "02", 0, 4, 4}, // Other v2.* (encrypted)
NikonArrayIdx{0x0091, "01", 0, 5, NA}, // Other v1.* (not encrypted)
{0x0091, "0208", 0, 0, 4}, // D80
{0x0091, "0209", 0, 1, 4}, // D40
{0x0091, "0210", 5291, 2, 4}, // D300
{0x0091, "0210", 5303, 3, 4}, // D300, firmware version 1.10
{0x0091, "02", 0, 4, 4}, // Other v2.* (encrypted)
{0x0091, "01", 0, 5, NA}, // Other v1.* (not encrypted)
// NikonCb
NikonArrayIdx{0x0097, "0100", 0, 0, NA}, NikonArrayIdx{0x0097, "0102", 0, 1, NA},
NikonArrayIdx{0x0097, "0103", 0, 4, NA}, NikonArrayIdx{0x0097, "0205", 0, 2, 4},
NikonArrayIdx{0x0097, "0209", 0, 5, 284}, NikonArrayIdx{0x0097, "0212", 0, 5, 284},
NikonArrayIdx{0x0097, "0214", 0, 5, 284}, NikonArrayIdx{0x0097, "02", 0, 3, 284},
{0x0097, "0100", 0, 0, NA},
{0x0097, "0102", 0, 1, NA},
{0x0097, "0103", 0, 4, NA},
{0x0097, "0205", 0, 2, 4},
{0x0097, "0209", 0, 5, 284},
{0x0097, "0212", 0, 5, 284},
{0x0097, "0214", 0, 5, 284},
{0x0097, "02", 0, 3, 284},
// NikonLd
NikonArrayIdx{0x0098, "0100", 0, 0, NA}, NikonArrayIdx{0x0098, "0101", 0, 1, NA},
NikonArrayIdx{0x0098, "0201", 0, 1, 4}, NikonArrayIdx{0x0098, "0202", 0, 1, 4},
NikonArrayIdx{0x0098, "0203", 0, 1, 4}, NikonArrayIdx{0x0098, "0204", 0, 2, 4},
NikonArrayIdx{0x0098, "0800", 0, 3, 4}, // for e.g. Z6/7
NikonArrayIdx{0x0098, "0801", 0, 3, 4}, // for e.g. Z6/7
NikonArrayIdx{0x0098, "0802", 0, 3, 4}, // for e.g. Z9
{0x0098, "0100", 0, 0, NA},
{0x0098, "0101", 0, 1, NA},
{0x0098, "0201", 0, 1, 4},
{0x0098, "0202", 0, 1, 4},
{0x0098, "0203", 0, 1, 4},
{0x0098, "0204", 0, 2, 4},
{0x0098, "0800", 0, 3, 4}, // for e.g. Z6/7
{0x0098, "0801", 0, 3, 4}, // for e.g. Z6/7
{0x0098, "0802", 0, 3, 4}, // for e.g. Z9
// NikonFl
NikonArrayIdx{0x00a8, "0100", 0, 0, NA}, NikonArrayIdx{0x00a8, "0101", 0, 0, NA},
NikonArrayIdx{0x00a8, "0102", 0, 1, NA}, NikonArrayIdx{0x00a8, "0103", 0, 2, NA},
NikonArrayIdx{0x00a8, "0104", 0, 2, NA}, NikonArrayIdx{0x00a8, "0105", 0, 2, NA},
NikonArrayIdx{0x00a8, "0106", 0, 3, NA}, NikonArrayIdx{0x00a8, "0107", 0, 4, NA},
NikonArrayIdx{0x00a8, "0108", 0, 4, NA},
{0x00a8, "0100", 0, 0, NA},
{0x00a8, "0101", 0, 0, NA},
{0x00a8, "0102", 0, 1, NA},
{0x00a8, "0103", 0, 2, NA},
{0x00a8, "0104", 0, 2, NA},
{0x00a8, "0105", 0, 2, NA},
{0x00a8, "0106", 0, 3, NA},
{0x00a8, "0107", 0, 4, NA},
{0x00a8, "0108", 0, 4, NA},
// NikonAf
NikonArrayIdx{0x00b7, "0100", 30, 0, NA}, // These sizes have been found in tiff headers of MN
NikonArrayIdx{0x00b7, "0101", 84, 1, NA}, // tag 0xb7 in sample image metadata for each version
{0x00b7, "0100", 30, 0, NA}, // These sizes have been found in tiff headers of MN
{0x00b7, "0101", 84, 1, NA}, // tag 0xb7 in sample image metadata for each version
};

int nikonSelector(uint16_t tag, const byte* pData, size_t size, TiffComponent* /*pRoot*/) {
if (size < 4)
return -1;

auto ix = NikonArrayIdx::Key(tag, reinterpret_cast<const char*>(pData), size);
auto it = std::find(nikonArrayIdx.begin(), nikonArrayIdx.end(), ix);
if (it == nikonArrayIdx.end())
auto it = Exiv2::find(nikonArrayIdx, ix);
if (!it)
return -1;

return it->idx_;
Expand All @@ -907,9 +918,8 @@ DataBuf nikonCrypt(uint16_t tag, const byte* pData, size_t size, TiffComponent*

if (size < 4)
return buf;
auto nci = std::find(nikonArrayIdx.begin(), nikonArrayIdx.end(),
NikonArrayIdx::Key(tag, reinterpret_cast<const char*>(pData), size));
if (nci == nikonArrayIdx.end() || nci->start_ == NA || size <= nci->start_)
auto nci = Exiv2::find(nikonArrayIdx, NikonArrayIdx::Key(tag, reinterpret_cast<const char*>(pData), size));
if (!nci || nci->start_ == NA || size <= nci->start_)
return buf;

// Find Exif.Nikon3.ShutterCount
Expand Down Expand Up @@ -955,12 +965,12 @@ int sonyCsSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/, Tif
return idx;
}
int sony2010eSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/, TiffComponent* pRoot) {
static constexpr auto models = std::array{
static constexpr const char* models[] = {
"SLT-A58", "SLT-A99", "ILCE-3000", "ILCE-3500", "NEX-3N", "NEX-5R", "NEX-5T",
"NEX-6", "VG30E", "VG900", "DSC-RX100", "DSC-RX1", "DSC-RX1R", "DSC-HX300",
"DSC-HX50V", "DSC-TX30", "DSC-WX60", "DSC-WX200", "DSC-WX300",
};
return std::find(models.begin(), models.end(), getExifModel(pRoot)) != models.end() ? 0 : -1;
return Exiv2::find(models, getExifModel(pRoot)) ? 0 : -1;
}

int sony2FpSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/, TiffComponent* pRoot) {
Expand Down
6 changes: 3 additions & 3 deletions src/minoltamn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ static bool inRange(long value, long min, long max) {
}

static std::ostream& resolvedLens(std::ostream& os, long lensID, long index) {
const TagDetails* td = find(minoltaSonyLensID, lensID);
auto td = Exiv2::find(minoltaSonyLensID, lensID);
std::vector<std::string> tokens = split(td[0].label_, "|");
return os << exvGettext(trim(tokens.at(index - 1)).c_str());
}
Expand Down Expand Up @@ -1606,7 +1606,7 @@ static std::ostream& resolveLens0xffff(std::ostream& os, const Value& value, con
std::string maxAperture = getKeyString("Exif.Photo.MaxApertureValue", metadata);

std::string F1_8 = "434/256";
static constexpr auto maxApertures = std::array{
static constexpr const char* maxApertures[] = {
"926/256", // F3.5
"1024/256", // F4
"1110/256", // F4.5
Expand All @@ -1626,7 +1626,7 @@ static std::ostream& resolveLens0xffff(std::ostream& os, const Value& value, con
} catch (...) {
}

if (model == "ILCE-6000" && std::find(maxApertures.begin(), maxApertures.end(), maxAperture) != maxApertures.end())
if (model == "ILCE-6000" && Exiv2::find(maxApertures, maxAperture))
try {
long focalLength = getKeyLong("Exif.Photo.FocalLength", metadata);
if (focalLength > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/nikonmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3791,7 +3791,7 @@ std::ostream& Nikon3MakerNote::print0x009e(std::ostream& os, const Value& value,
if (l != 0)
trim = false;
std::string d = s.empty() ? "" : "; ";
const TagDetails* td = find(nikonRetouchHistory, l);
auto td = Exiv2::find(nikonRetouchHistory, l);
if (td) {
s = std::string(exvGettext(td->label_)).append(d).append(s);
} else {
Expand Down
23 changes: 11 additions & 12 deletions src/pentaxmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ std::ostream& resolveLens0x32c(std::ostream& os, const Value& value, const ExifD

if (index > 0) {
const unsigned long lensID = 0x32c;
const TagDetails* td = find(pentaxLensType, lensID);
auto td = Exiv2::find(pentaxLensType, lensID);
os << exvGettext(td[index].label_);
return os;
}
Expand Down Expand Up @@ -1160,7 +1160,7 @@ std::ostream& resolveLens0x3ff(std::ostream& os, const Value& value, const ExifD

if (index > 0) {
const unsigned long lensID = 0x3ff;
const TagDetails* td = find(pentaxLensType, lensID);
auto td = Exiv2::find(pentaxLensType, lensID);
os << exvGettext(td[index].label_);
return os;
}
Expand All @@ -1187,7 +1187,7 @@ std::ostream& resolveLens0x8ff(std::ostream& os, const Value& value, const ExifD

if (index > 0) {
const unsigned long lensID = 0x8ff;
const TagDetails* td = find(pentaxLensType, lensID);
auto td = Exiv2::find(pentaxLensType, lensID);
os << exvGettext(td[index].label_);
return os;
}
Expand Down Expand Up @@ -1221,7 +1221,7 @@ std::ostream& resolveLens0x319(std::ostream& os, const Value& value, const ExifD

if (index > 0) {
const unsigned long lensID = 0x319;
const TagDetails* td = find(pentaxLensType, lensID);
auto td = Exiv2::find(pentaxLensType, lensID);
os << exvGettext(td[index].label_);
return os;
}
Expand All @@ -1245,12 +1245,11 @@ struct LensIdFct {
};

//! List of lens ids which require special treatment using resolveLensType
constexpr auto lensIdFct = std::array{
LensIdFct{0x0317, resolveLensType}, LensIdFct{0x0319, resolveLens0x319}, LensIdFct{0x031b, resolveLensType},
LensIdFct{0x031c, resolveLensType}, LensIdFct{0x031d, resolveLensType}, LensIdFct{0x031f, resolveLensType},
LensIdFct{0x0329, resolveLensType}, LensIdFct{0x032c, resolveLens0x32c}, LensIdFct{0x032e, resolveLensType},
LensIdFct{0x0334, resolveLensType}, LensIdFct{0x03ff, resolveLens0x3ff}, LensIdFct{0x041a, resolveLensType},
LensIdFct{0x042d, resolveLensType}, LensIdFct{0x08ff, resolveLens0x8ff},
constexpr LensIdFct lensIdFct[] = {
{0x0317, resolveLensType}, {0x0319, resolveLens0x319}, {0x031b, resolveLensType}, {0x031c, resolveLensType},
{0x031d, resolveLensType}, {0x031f, resolveLensType}, {0x0329, resolveLensType}, {0x032c, resolveLens0x32c},
{0x032e, resolveLensType}, {0x0334, resolveLensType}, {0x03ff, resolveLens0x3ff}, {0x041a, resolveLensType},
{0x042d, resolveLensType}, {0x08ff, resolveLens0x8ff},
};

//! A lens id and a pretty-print function for special treatment of the id.
Expand All @@ -1265,8 +1264,8 @@ std::ostream& printLensType(std::ostream& os, const Value& value, const ExifData
const auto index = value.toUint32(0) * 256 + value.toUint32(1);

// std::cout << std::endl << "printLensType value =" << value.toLong() << " index = " << index << std::endl;
auto lif = std::find(lensIdFct.begin(), lensIdFct.end(), index);
if (lif == lensIdFct.end())
auto lif = Exiv2::find(lensIdFct, index);
if (!lif)
return EXV_PRINT_COMBITAG_MULTI(pentaxLensType, 2, 1, 2)(os, value, metadata);
if (metadata && lif->fct_)
return lif->fct_(os, value, metadata);
Expand Down
2 changes: 1 addition & 1 deletion src/pentaxmn_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ std::ostream& printCombiTag(std::ostream& os, const Value& value, const ExifData
}
l += (value.toUint32(c) << ((count - c - 1) * 8));
}
const TagDetails* td = find(array, l);
auto td = Exiv2::find(array, l);
if (td) {
os << exvGettext(td->label_);
} else {
Expand Down
Loading