Skip to content

Commit 72c434a

Browse files
committed
strcmp removals
Signed-off-by: Rosen Penev <[email protected]>
1 parent c2d9146 commit 72c434a

File tree

5 files changed

+28
-27
lines changed

5 files changed

+28
-27
lines changed

src/convert.cpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
namespace {
4545
#if defined EXV_HAVE_ICONV
4646
// Convert string charset with iconv.
47-
bool convertStringCharsetIconv(std::string& str, const char* from, const char* to);
47+
bool convertStringCharsetIconv(std::string& str, std::string_view from, std::string_view to);
4848
#elif defined _WIN32
4949
// Convert string charset with Windows functions.
50-
bool convertStringCharsetWindows(std::string& str, const char* from, const char* to);
50+
bool convertStringCharsetWindows(std::string& str, std::string_view from, std::string_view to);
5151
#endif
5252
/*!
5353
@brief Get the text value of an XmpDatum \em pos.
@@ -1393,12 +1393,12 @@ namespace {
13931393
using namespace Exiv2;
13941394

13951395
#if defined EXV_HAVE_ICONV
1396-
bool convertStringCharsetIconv(std::string& str, const char* from, const char* to) {
1397-
if (strcmp(from, to) == 0)
1396+
bool convertStringCharsetIconv(std::string& str, std::string_view from, std::string_view to) {
1397+
if (from == to)
13981398
return true; // nothing to do
13991399

14001400
bool ret = true;
1401-
auto cd = iconv_open(to, from);
1401+
auto cd = iconv_open(to.data(), from.data());
14021402
if (cd == iconv_t(-1)) {
14031403
#ifndef SUPPRESS_WARNINGS
14041404
EXV_WARNING << "iconv_open: " << strError() << "\n";
@@ -1551,11 +1551,11 @@ bool asciiToUtf8(std::string& /*str*/) {
15511551
using ConvFct = bool (*)(std::string&);
15521552

15531553
struct ConvFctList {
1554-
bool operator==(const std::pair<const char*, const char*>& fromTo) const {
1555-
return 0 == strcmp(from_, fromTo.first) && 0 == strcmp(to_, fromTo.second);
1554+
bool operator==(const std::pair<std::string_view, std::string_view>& fromTo) const {
1555+
return from_ == fromTo.first && to_ == fromTo.second;
15561556
}
1557-
const char* from_;
1558-
const char* to_;
1557+
std::string_view from_;
1558+
std::string_view to_;
15591559
ConvFct convFct_;
15601560
};
15611561

@@ -1567,18 +1567,19 @@ constexpr ConvFctList convFctList[] = {
15671567
// Update the convertStringCharset() documentation if you add more here!
15681568
};
15691569

1570-
[[maybe_unused]] bool convertStringCharsetWindows(std::string& str, const char* from, const char* to) {
1570+
bool convertStringCharsetWindows(std::string& str, std::string_view from, std::string_view to) {
15711571
bool ret = false;
15721572
std::string tmpstr = str;
15731573
if (auto p = Exiv2::find(convFctList, std::pair(from, to)))
15741574
ret = p->convFct_(tmpstr);
15751575
#ifndef SUPPRESS_WARNINGS
15761576
else {
1577-
EXV_WARNING << "No Windows function to map character string from " << from << " to " << to << " available.\n";
1577+
EXV_WARNING << "No Windows function to map character string from " << from.data() << " to " << to.data()
1578+
<< " available.\n";
15781579
}
15791580
#endif
15801581
if (ret)
1581-
str = tmpstr;
1582+
str = std::move(tmpstr);
15821583
return ret;
15831584
}
15841585

src/nikonmn_int.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -2114,7 +2114,9 @@ std::ostream& Nikon3MakerNote::printLensId(std::ostream& os, const Value& value,
21142114

21152115
static constexpr struct FMntLens {
21162116
unsigned char lid, stps, focs, focl, aps, apl, lfw, ltype, tcinfo, dblid, mid;
2117-
const char *manuf, *lnumber, *lensname;
2117+
std::string_view manuf;
2118+
std::string_view lnumber;
2119+
std::string_view lensname;
21182120

21192121
bool operator==(unsigned char l) const {
21202122
return lid == l;
@@ -3273,8 +3275,8 @@ std::ostream& Nikon3MakerNote::printLensId(std::ostream& os, const Value& value,
32733275

32743276
if (raw[0] == f.lid
32753277
// stps varies with focal length for some Sigma zoom lenses.
3276-
&& (raw[1] == f.stps || strcmp(f.manuf, "Sigma") == 0) && raw[2] == f.focs && raw[3] == f.focl &&
3277-
raw[4] == f.aps && raw[5] == f.apl && raw[6] == f.lfw && raw[7] == f.ltype) {
3278+
&& (raw[1] == f.stps || f.manuf == "Sigma") && raw[2] == f.focs && raw[3] == f.focl && raw[4] == f.aps &&
3279+
raw[5] == f.apl && raw[6] == f.lfw && raw[7] == f.ltype) {
32783280
// Lens found in database
32793281
return os << f.manuf << " " << f.lensname;
32803282
}

src/pngimage.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,7 @@ void PngImage::printStructure(std::ostream& out, PrintStructureOption option, si
184184
throw Error(ErrorCode::kerNotAnImage, "PNG");
185185
}
186186

187-
char chType[5];
188-
chType[0] = 0;
189-
chType[4] = 0;
187+
std::string chType(4, 0);
190188

191189
if (option == kpsBasic || option == kpsXMP || option == kpsIccProfile || option == kpsRecursive) {
192190
const auto xmpKey = upper("XML:com.adobe.xmp");
@@ -206,7 +204,7 @@ void PngImage::printStructure(std::ostream& out, PrintStructureOption option, si
206204
const size_t imgSize = io_->size();
207205
DataBuf cheaderBuf(8);
208206

209-
while (!io_->eof() && ::strcmp(chType, "IEND") != 0) {
207+
while (!io_->eof() && chType != "IEND") {
210208
const size_t address = io_->tell();
211209

212210
size_t bufRead = io_->read(cheaderBuf.data(), cheaderBuf.size());
@@ -260,11 +258,11 @@ void PngImage::printStructure(std::ostream& out, PrintStructureOption option, si
260258
}
261259

262260
// chunk type
263-
bool tEXt = std::strcmp(chType, "tEXt") == 0;
264-
bool zTXt = std::strcmp(chType, "zTXt") == 0;
265-
bool iCCP = std::strcmp(chType, "iCCP") == 0;
266-
bool iTXt = std::strcmp(chType, "iTXt") == 0;
267-
bool eXIf = std::strcmp(chType, "eXIf") == 0;
261+
bool tEXt = chType == "tEXt";
262+
bool zTXt = chType == "zTXt";
263+
bool iCCP = chType == "iCCP";
264+
bool iTXt = chType == "iTXt";
265+
bool eXIf = chType == "eXIf";
268266

269267
// for XMP, ICC etc: read and format data
270268
const auto dataStringU = upper(dataString);

src/tiffcomposite_int.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ size_t fillGap(Exiv2::Internal::IoWrapper& ioWrapper, size_t curr, size_t tobe);
2828
// class member definitions
2929
namespace Exiv2::Internal {
3030
bool TiffMappingInfo::operator==(const TiffMappingInfo::Key& key) const {
31-
return (0 == strcmp("*", make_) || key.m_.starts_with(make_)) &&
32-
(Tag::all == extendedTag_ || key.e_ == extendedTag_) && key.g_ == group_;
31+
return (make_ == "*" || key.m_.starts_with(make_)) && (Tag::all == extendedTag_ || key.e_ == extendedTag_) &&
32+
key.g_ == group_;
3333
}
3434

3535
IoWrapper::IoWrapper(BasicIo& io, const byte* pHeader, size_t size, OffsetWriter* pow) :

src/tiffcomposite_int.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ struct TiffMappingInfo {
356356
}
357357

358358
// DATA
359-
const char* make_; //!< Camera make for which these mapping functions apply
359+
std::string_view make_; //!< Camera make for which these mapping functions apply
360360
uint32_t extendedTag_; //!< Tag (32 bit so that it can contain special tags)
361361
IfdId group_; //!< Group that contains the tag
362362
DecoderFct decoderFct_; //!< Decoder function for matching tags

0 commit comments

Comments
 (0)