From 143a1fbbe27c9c8121d08a600ee77b0ed7275585 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 27 Apr 2021 00:00:02 -0700 Subject: [PATCH] clang-tidy: don't use string compare Found with readability-string-compare Signed-off-by: Rosen Penev --- samples/conntest.cpp | 2 +- samples/exiv2json.cpp | 7 ++----- src/actions.cpp | 2 +- src/basicio.cpp | 6 +++--- src/exiv2.cpp | 2 +- src/futils.cpp | 2 +- src/jpgimage.cpp | 16 ++++++++-------- 7 files changed, 17 insertions(+), 20 deletions(-) diff --git a/samples/conntest.cpp b/samples/conntest.cpp index 17cd0829..b2640af6 100644 --- a/samples/conntest.cpp +++ b/samples/conntest.cpp @@ -41,7 +41,7 @@ void httpcon(const std::string& url, bool useHttp1_0 = false) { if (!useHttp1_0) request["version"] = "1.1"; int serverCode = Exiv2::http(request,response,errors); - if (serverCode < 0 || serverCode >= 400 || errors.compare("") != 0) { + if (serverCode < 0 || serverCode >= 400 || errors != "") { throw Exiv2::Error(Exiv2::kerTiffDirectoryTooLarge, "Server", serverCode); } } diff --git a/samples/exiv2json.cpp b/samples/exiv2json.cpp index 6d6e885b..a2c0341f 100644 --- a/samples/exiv2json.cpp +++ b/samples/exiv2json.cpp @@ -147,15 +147,12 @@ Jzon::Node& objectForKey(const std::string& Key,Jzon::Object& root,std::string& bool isObject(std::string& value) { - return !value.compare(std::string("type=\"Struct\"")); + return value == std::string("type=\"Struct\""); } bool isArray(std::string& value) { - return !value.compare(std::string("type=\"Seq\"")) - || !value.compare(std::string("type=\"Bag\"")) - || !value.compare(std::string("type=\"Alt\"")) - ; + return value == "type=\"Seq\"" || value == "type=\"Bag\"" || value == "type=\"Alt\""; } #define STORE(node,key,value) \ diff --git a/src/actions.cpp b/src/actions.cpp index ce5d8536..7d084e2f 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -519,7 +519,7 @@ namespace Action { bool result=Params::instance().keys_.empty(); for (auto k = Params::instance().keys_.begin(); !result && k != Params::instance().keys_.end(); ++k) { - result = key.compare(*k) == 0; + result = key == *k; } return result ; } diff --git a/src/basicio.cpp b/src/basicio.cpp index 65b19dfb..5e4f19cd 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -2072,7 +2072,7 @@ namespace Exiv2 { request["port"] = hostInfo_.Port; request["verb"] = "HEAD"; int serverCode = http(request, response, errors); - if (serverCode < 0 || serverCode >= 400 || errors.compare("") != 0) { + if (serverCode < 0 || serverCode >= 400 || errors != "") { throw Error(kerFileOpenFailed, "http",Exiv2::Internal::stringFormat("%d",serverCode), hostInfo_.Path); } @@ -2097,7 +2097,7 @@ namespace Exiv2 { } int serverCode = http(request, responseDic, errors); - if (serverCode < 0 || serverCode >= 400 || errors.compare("") != 0) { + if (serverCode < 0 || serverCode >= 400 || errors != "") { throw Error(kerFileOpenFailed, "http",Exiv2::Internal::stringFormat("%d",serverCode), hostInfo_.Path); } response = responseDic["body"]; @@ -2150,7 +2150,7 @@ namespace Exiv2 { request["header"] = ss.str(); int serverCode = http(request, response, errors); - if (serverCode < 0 || serverCode >= 400 || errors.compare("") != 0) { + if (serverCode < 0 || serverCode >= 400 || errors != "") { throw Error(kerFileOpenFailed, "http",Exiv2::Internal::stringFormat("%d",serverCode), hostInfo_.Path); } } diff --git a/src/exiv2.cpp b/src/exiv2.cpp index 4e76dc08..08b7c8da 100644 --- a/src/exiv2.cpp +++ b/src/exiv2.cpp @@ -1316,7 +1316,7 @@ namespace { for (auto&& filename : cmdFiles) { try { std::ifstream file(filename.c_str()); - bool bStdin = filename.compare("-") == 0; + bool bStdin = filename == "-"; if (!file && !bStdin) { std::cerr << filename << ": " << _("Failed to open command file for reading\n"); return false; diff --git a/src/futils.cpp b/src/futils.cpp index 1868b785..2fb64b40 100644 --- a/src/futils.cpp +++ b/src/futils.cpp @@ -277,7 +277,7 @@ namespace Exiv2 { bool fileExists(const std::string& path, bool ct) { // special case: accept "-" (means stdin) - if (path.compare("-") == 0 || fileProtocol(path) != pFile) { + if (path == "-" || fileProtocol(path) != pFile) { return true; } diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index 7cceebe7..0c0dd234 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -696,7 +696,7 @@ namespace Exiv2 { bufRead = size; done = !bExtXMP; } - } else if (option == kpsIccProfile && signature.compare(iccId_) == 0) { + } else if (option == kpsIccProfile && signature == iccId_) { // extract ICCProfile if (size > 0) { io_->seek(-bufRead, BasicIo::cur); // back to buffer (after marker) @@ -709,7 +709,7 @@ namespace Exiv2 { #endif bufRead = size; } - } else if (option == kpsIptcErase && signature.compare("Photoshop 3.0") == 0) { + } else if (option == kpsIptcErase && signature == "Photoshop 3.0") { // delete IPTC data segment from JPEG if (size > 0) { io_->seek(-bufRead, BasicIo::cur); @@ -720,7 +720,7 @@ namespace Exiv2 { const size_t start = size > 0 ? 2 : 0; const size_t end = start + (size > 32 ? 32 : size); out << "| " << Internal::binaryToString(makeSlice(buf, start, end)); - if (signature.compare(iccId_) == 0) { + if (signature == iccId_) { // extract the chunk information from the buffer // // the buffer looks like this in this branch @@ -739,10 +739,10 @@ namespace Exiv2 { // for MPF: http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/MPF.html // for FLIR: http://owl.phy.queensu.ca/~phil/exiftool/TagNames/FLIR.html - bool bFlir = option == kpsRecursive && marker == (app0_ + 1) && signature.compare("FLIR") == 0; - bool bExif = option == kpsRecursive && marker == (app0_ + 1) && signature.compare("Exif") == 0; - bool bMPF = option == kpsRecursive && marker == (app0_ + 2) && signature.compare("MPF") == 0; - bool bPS = option == kpsRecursive && signature.compare("Photoshop 3.0") == 0; + bool bFlir = option == kpsRecursive && marker == (app0_ + 1) && signature == "FLIR"; + bool bExif = option == kpsRecursive && marker == (app0_ + 1) && signature == "Exif"; + bool bMPF = option == kpsRecursive && marker == (app0_ + 2) && signature == "MPF"; + bool bPS = option == kpsRecursive && signature == "Photoshop 3.0"; if (bFlir || bExif || bMPF || bPS) { // extract Exif data block which is tiff formatted if (size > 0) { @@ -755,7 +755,7 @@ namespace Exiv2 { // copy the data to memory io_->seek(-bufRead, BasicIo::cur); io_->read(exif, size); - uint32_t start = signature.compare("Exif") == 0 ? 8 : 6; + uint32_t start = signature == "Exif" ? 8 : 6; uint32_t max = (uint32_t)size - 1; // is this an fff block?