From 8b3da36f42f7bb68f871ce782dc97185d352615c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20D=C3=ADaz=20M=C3=A1s?= Date: Sat, 19 Feb 2022 17:27:29 +0100 Subject: [PATCH] Improvements from code review --- include/exiv2/bmffimage.hpp | 2 +- include/exiv2/bmpimage.hpp | 2 +- include/exiv2/cr2image.hpp | 2 +- include/exiv2/epsimage.hpp | 2 +- include/exiv2/futils.hpp | 2 +- include/exiv2/gifimage.hpp | 2 +- include/exiv2/image.hpp | 2 +- include/exiv2/jp2image.hpp | 2 +- include/exiv2/mrwimage.hpp | 2 +- include/exiv2/orfimage.hpp | 2 +- include/exiv2/psdimage.hpp | 2 +- include/exiv2/rafimage.hpp | 2 +- include/exiv2/rw2image.hpp | 2 +- include/exiv2/tgaimage.hpp | 2 +- include/exiv2/tiffimage.hpp | 2 +- include/exiv2/webpimage.hpp | 2 +- include/exiv2/xmpsidecar.hpp | 2 +- src/basicio.cpp | 2 +- src/bmffimage.cpp | 2 +- src/bmpimage.cpp | 2 +- src/cr2image.cpp | 2 +- src/epsimage.cpp | 2 +- src/futils.cpp | 4 ++-- src/gifimage.cpp | 2 +- src/image.cpp | 2 +- src/jp2image.cpp | 2 +- src/makernote_int.cpp | 3 ++- src/mrwimage.cpp | 2 +- src/orfimage.cpp | 2 +- src/psdimage.cpp | 2 +- src/rafimage.cpp | 2 +- src/rw2image.cpp | 2 +- src/tgaimage.cpp | 2 +- src/tiffimage.cpp | 2 +- src/webpimage.cpp | 2 +- src/xmpsidecar.cpp | 2 +- 36 files changed, 38 insertions(+), 37 deletions(-) diff --git a/include/exiv2/bmffimage.hpp b/include/exiv2/bmffimage.hpp index 94247a7f..e8f9e53e 100644 --- a/include/exiv2/bmffimage.hpp +++ b/include/exiv2/bmffimage.hpp @@ -128,7 +128,7 @@ namespace Exiv2 //@{ void readMetadata() override /* override */; void writeMetadata() override /* override */; - void setComment(const std::string_view comment) override /* override */; + void setComment(std::string_view comment) override /* override */; void printStructure(std::ostream& out, Exiv2::PrintStructureOption option, int depth) override; //@} diff --git a/include/exiv2/bmpimage.hpp b/include/exiv2/bmpimage.hpp index cb333904..4966ad9e 100644 --- a/include/exiv2/bmpimage.hpp +++ b/include/exiv2/bmpimage.hpp @@ -85,7 +85,7 @@ namespace Exiv2 { void setIptcData(const IptcData& iptcData) override; /// @throws Error(kerInvalidSettingForImage) - void setComment(const std::string_view comment) override; + void setComment(std::string_view comment) override; //@} //! @name Accessors diff --git a/include/exiv2/cr2image.hpp b/include/exiv2/cr2image.hpp index 79253c9d..9aaa4b8b 100644 --- a/include/exiv2/cr2image.hpp +++ b/include/exiv2/cr2image.hpp @@ -81,7 +81,7 @@ namespace Exiv2 { @brief Not supported. CR2 format does not contain a comment. Calling this function will throw an Error(kerInvalidSettingForImage). */ - void setComment(const std::string_view comment) override; + void setComment(std::string_view comment) override; //@} //! @name Accessors diff --git a/include/exiv2/epsimage.hpp b/include/exiv2/epsimage.hpp index f37c6d4f..ca4c498d 100644 --- a/include/exiv2/epsimage.hpp +++ b/include/exiv2/epsimage.hpp @@ -80,7 +80,7 @@ namespace Exiv2 @brief Not supported. Calling this function will throw an instance of Error(kerInvalidSettingForImage). */ - void setComment(const std::string_view comment) override; + void setComment(std::string_view comment) override; //@} //! @name Accessors diff --git a/include/exiv2/futils.hpp b/include/exiv2/futils.hpp index 96e0001b..ced26270 100644 --- a/include/exiv2/futils.hpp +++ b/include/exiv2/futils.hpp @@ -63,7 +63,7 @@ namespace Exiv2 @note Source: http://www.geekhideout.com/urlcode.shtml @todo This function can probably be hidden into the implementation details */ - EXIV2API std::string urlencode(const std::string_view& str); + EXIV2API std::string urlencode(std::string_view str); /*! @brief Like urlencode(char* str) but accept the input url in the std::string and modify it. diff --git a/include/exiv2/gifimage.hpp b/include/exiv2/gifimage.hpp index 88dac6c4..4f1f3d85 100644 --- a/include/exiv2/gifimage.hpp +++ b/include/exiv2/gifimage.hpp @@ -86,7 +86,7 @@ namespace Exiv2 { @brief Not supported. Calling this function will throw an instance of Error(kerInvalidSettingForImage). */ - void setComment(const std::string_view comment) override; + void setComment(std::string_view comment) override; //@} //! @name Accessors diff --git a/include/exiv2/image.hpp b/include/exiv2/image.hpp index 59c61856..8c5dc1e9 100644 --- a/include/exiv2/image.hpp +++ b/include/exiv2/image.hpp @@ -197,7 +197,7 @@ namespace Exiv2 { virtual void clearXmpData(); /// @brief Set the image comment. The comment is written to the image when writeMetadata() is called. - virtual void setComment(const std::string_view comment); + virtual void setComment(std::string_view comment); /*! @brief Erase any buffered comment. Comment is not removed diff --git a/include/exiv2/jp2image.hpp b/include/exiv2/jp2image.hpp index b53f92aa..2a0604db 100644 --- a/include/exiv2/jp2image.hpp +++ b/include/exiv2/jp2image.hpp @@ -80,7 +80,7 @@ namespace Exiv2 @brief Todo: Not supported yet(?). Calling this function will throw an instance of Error(kerInvalidSettingForImage). */ - void setComment(const std::string_view comment) override; + void setComment(std::string_view comment) override; //@} //! @name Accessors diff --git a/include/exiv2/mrwimage.hpp b/include/exiv2/mrwimage.hpp index d4d19387..edb9b386 100644 --- a/include/exiv2/mrwimage.hpp +++ b/include/exiv2/mrwimage.hpp @@ -89,7 +89,7 @@ namespace Exiv2 { @brief Not supported. MRW format does not contain a comment. Calling this function will throw an Error(kerInvalidSettingForImage). */ - void setComment(const std::string_view comment) override; + void setComment(std::string_view comment) override; //@} //! @name Accessors diff --git a/include/exiv2/orfimage.hpp b/include/exiv2/orfimage.hpp index 0f92a5f6..1b32d7be 100644 --- a/include/exiv2/orfimage.hpp +++ b/include/exiv2/orfimage.hpp @@ -76,7 +76,7 @@ namespace Exiv2 { @brief Not supported. ORF format does not contain a comment. Calling this function will throw an Error(kerInvalidSettingForImage). */ - void setComment(const std::string_view comment) override; + void setComment(std::string_view comment) override; //@} //! @name Accessors diff --git a/include/exiv2/psdimage.hpp b/include/exiv2/psdimage.hpp index fcd61db5..2863cfdc 100644 --- a/include/exiv2/psdimage.hpp +++ b/include/exiv2/psdimage.hpp @@ -70,7 +70,7 @@ namespace Exiv2 { /*! @brief Not supported. Calling this function will throw an Error(kerInvalidSettingForImage). */ - void setComment(const std::string_view comment) override; + void setComment(std::string_view comment) override; //@} //! @name Accessors diff --git a/include/exiv2/rafimage.hpp b/include/exiv2/rafimage.hpp index 50a08e10..0a0ce071 100644 --- a/include/exiv2/rafimage.hpp +++ b/include/exiv2/rafimage.hpp @@ -82,7 +82,7 @@ namespace Exiv2 { @brief Not supported. RAF format does not contain a comment. Calling this function will throw an Error(kerInvalidSettingForImage). */ - void setComment(const std::string_view comment) override; + void setComment(std::string_view comment) override; //@} //! @name Accessors diff --git a/include/exiv2/rw2image.hpp b/include/exiv2/rw2image.hpp index 84411edf..770132cc 100644 --- a/include/exiv2/rw2image.hpp +++ b/include/exiv2/rw2image.hpp @@ -80,7 +80,7 @@ namespace Exiv2 { @brief Not supported. RW2 format does not contain a comment. Calling this function will throw an Error(kerInvalidSettingForImage). */ - void setComment(const std::string_view comment) override; + void setComment(std::string_view comment) override; //@} //! @name Accessors diff --git a/include/exiv2/tgaimage.hpp b/include/exiv2/tgaimage.hpp index c19fc26c..12d87fe3 100644 --- a/include/exiv2/tgaimage.hpp +++ b/include/exiv2/tgaimage.hpp @@ -86,7 +86,7 @@ namespace Exiv2 { @brief Not supported. Calling this function will throw an instance of Error(kerInvalidSettingForImage). */ - void setComment(const std::string_view comment) override; + void setComment(std::string_view comment) override; //@} //! @name Accessors diff --git a/include/exiv2/tiffimage.hpp b/include/exiv2/tiffimage.hpp index 3364f267..75f0ec1e 100644 --- a/include/exiv2/tiffimage.hpp +++ b/include/exiv2/tiffimage.hpp @@ -77,7 +77,7 @@ namespace Exiv2 { @brief Not supported. TIFF format does not contain a comment. Calling this function will throw an Error(kerInvalidSettingForImage). */ - void setComment(const std::string_view comment) override; + void setComment(std::string_view comment) override; //@} //! @name Accessors diff --git a/include/exiv2/webpimage.hpp b/include/exiv2/webpimage.hpp index 6a008cf0..1eb8f653 100644 --- a/include/exiv2/webpimage.hpp +++ b/include/exiv2/webpimage.hpp @@ -65,7 +65,7 @@ namespace Exiv2 { /*! @brief Not supported. Calling this function will throw an Error(kerInvalidSettingForImage). */ - void setComment(const std::string_view comment) override; + void setComment(std::string_view comment) override; void setIptcData(const IptcData& /*iptcData*/) override; //! @name Accessors diff --git a/include/exiv2/xmpsidecar.hpp b/include/exiv2/xmpsidecar.hpp index 654cef4f..a6f6b119 100644 --- a/include/exiv2/xmpsidecar.hpp +++ b/include/exiv2/xmpsidecar.hpp @@ -64,7 +64,7 @@ namespace Exiv2 { @brief Not supported. XMP sidecar files do not contain a comment. Calling this function will throw an instance of Error(kerInvalidSettingForImage). */ - void setComment(const std::string_view comment) override; + void setComment(std::string_view comment) override; //@} //! @name Accessors diff --git a/src/basicio.cpp b/src/basicio.cpp index 56a6798b..807d75c8 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -385,7 +385,7 @@ namespace Exiv2 { bool statOk = true; mode_t origStMode = 0; - char* pf = const_cast(path().c_str()); + auto pf = path().c_str(); Impl::StructStat buf1; if (p_->stat(buf1) == -1) { diff --git a/src/bmffimage.cpp b/src/bmffimage.cpp index c5dbc148..b31c6c3f 100644 --- a/src/bmffimage.cpp +++ b/src/bmffimage.cpp @@ -627,7 +627,7 @@ namespace Exiv2 } } - void BmffImage::setComment(const std::string_view /*comment*/) + void BmffImage::setComment(std::string_view /*comment*/) { // bmff files are read-only throw(Error(kerInvalidSettingForImage, "Image comment", "BMFF")); diff --git a/src/bmpimage.cpp b/src/bmpimage.cpp index 168db5d5..4e99d04a 100644 --- a/src/bmpimage.cpp +++ b/src/bmpimage.cpp @@ -61,7 +61,7 @@ namespace Exiv2 throw(Error(kerInvalidSettingForImage, "IPTC metadata", "BMP")); } - void BmpImage::setComment(const std::string_view /*comment*/) + void BmpImage::setComment(std::string_view /*comment*/) { throw(Error(kerInvalidSettingForImage, "Image comment", "BMP")); } diff --git a/src/cr2image.cpp b/src/cr2image.cpp index 73bc6dd3..acdc189e 100644 --- a/src/cr2image.cpp +++ b/src/cr2image.cpp @@ -81,7 +81,7 @@ namespace Exiv2 { printTiffStructure(io(),out,option,depth-1); } - void Cr2Image::setComment(const std::string_view /*comment*/) + void Cr2Image::setComment(std::string_view /*comment*/) { // not supported throw(Error(kerInvalidSettingForImage, "Image comment", "CR2")); diff --git a/src/epsimage.cpp b/src/epsimage.cpp index d87ed7f9..386508b8 100644 --- a/src/epsimage.cpp +++ b/src/epsimage.cpp @@ -1094,7 +1094,7 @@ namespace Exiv2 return "application/postscript"; } - void EpsImage::setComment(const std::string_view /*comment*/) + void EpsImage::setComment(std::string_view /*comment*/) { throw Error(kerInvalidSettingForImage, "Image comment", "EPS"); } diff --git a/src/futils.cpp b/src/futils.cpp index ef0312f1..be13d424 100644 --- a/src/futils.cpp +++ b/src/futils.cpp @@ -105,11 +105,11 @@ namespace Exiv2 { return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; } - std::string urlencode(const std::string_view& str) + std::string urlencode(std::string_view str) { std::string encoded; encoded.reserve(str.size() * 3); - for (auto c : str) { + for (uint8_t c : str) { if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') encoded += c; else if (c == ' ') diff --git a/src/gifimage.cpp b/src/gifimage.cpp index 98f81e64..b9e17bdf 100644 --- a/src/gifimage.cpp +++ b/src/gifimage.cpp @@ -58,7 +58,7 @@ namespace Exiv2 { throw(Error(kerInvalidSettingForImage, "IPTC metadata", "GIF")); } - void GifImage::setComment(const std::string_view /*comment*/) + void GifImage::setComment(std::string_view /*comment*/) { // not supported throw(Error(kerInvalidSettingForImage, "Image comment", "GIF")); diff --git a/src/image.cpp b/src/image.cpp index bf40c543..3555f237 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -662,7 +662,7 @@ namespace Exiv2 { comment_.erase(); } - void Image::setComment(const std::string_view comment) + void Image::setComment(std::string_view comment) { comment_ = comment; } diff --git a/src/jp2image.cpp b/src/jp2image.cpp index b31908b5..078e3a4d 100644 --- a/src/jp2image.cpp +++ b/src/jp2image.cpp @@ -158,7 +158,7 @@ namespace Exiv2 return "image/jp2"; } - void Jp2Image::setComment(const std::string_view /*comment*/) + void Jp2Image::setComment(std::string_view /*comment*/) { // Todo: implement me! throw(Error(kerInvalidSettingForImage, "Image comment", "JP2")); diff --git a/src/makernote_int.cpp b/src/makernote_int.cpp index 479ca933..0fbb54c0 100644 --- a/src/makernote_int.cpp +++ b/src/makernote_int.cpp @@ -35,6 +35,7 @@ #include "utils.hpp" // + standard includes +#include #include #include #include @@ -1197,7 +1198,7 @@ namespace Exiv2 { { // Not valid for models beginning std::string model = getExifModel(pRoot); - const std::vector strs { "SLT-", "HV", "ILCA-"}; + const std::array strs { "SLT-", "HV", "ILCA-"}; return std::any_of(strs.begin(), strs.end(), [&model](auto& m){return startsWith(model, m);}) ? -1 : 0; } diff --git a/src/mrwimage.cpp b/src/mrwimage.cpp index 80decc04..66af177d 100644 --- a/src/mrwimage.cpp +++ b/src/mrwimage.cpp @@ -79,7 +79,7 @@ namespace Exiv2 { throw(Error(kerInvalidSettingForImage, "IPTC metadata", "MRW")); } - void MrwImage::setComment(const std::string_view /*comment*/) + void MrwImage::setComment(std::string_view /*comment*/) { // not supported throw(Error(kerInvalidSettingForImage, "Image comment", "MRW")); diff --git a/src/orfimage.cpp b/src/orfimage.cpp index 8adb4680..c1f859be 100644 --- a/src/orfimage.cpp +++ b/src/orfimage.cpp @@ -72,7 +72,7 @@ namespace Exiv2 { return 0; } - void OrfImage::setComment(const std::string_view /*comment*/) + void OrfImage::setComment(std::string_view /*comment*/) { // not supported throw(Error(kerInvalidSettingForImage, "Image comment", "ORF")); diff --git a/src/psdimage.cpp b/src/psdimage.cpp index e0420be0..6b509344 100644 --- a/src/psdimage.cpp +++ b/src/psdimage.cpp @@ -127,7 +127,7 @@ namespace Exiv2 { return "image/x-photoshop"; } - void PsdImage::setComment(const std::string_view /*comment*/) + void PsdImage::setComment(std::string_view /*comment*/) { // not supported throw(Error(kerInvalidSettingForImage, "Image comment", "Photoshop")); diff --git a/src/rafimage.cpp b/src/rafimage.cpp index b3ecaa34..4cf6c9d1 100644 --- a/src/rafimage.cpp +++ b/src/rafimage.cpp @@ -81,7 +81,7 @@ namespace Exiv2 { throw(Error(kerInvalidSettingForImage, "IPTC metadata", "RAF")); } - void RafImage::setComment(const std::string_view /*comment*/) + void RafImage::setComment(std::string_view /*comment*/) { // not supported throw(Error(kerInvalidSettingForImage, "Image comment", "RAF")); diff --git a/src/rw2image.cpp b/src/rw2image.cpp index 7142960c..6b3369ee 100644 --- a/src/rw2image.cpp +++ b/src/rw2image.cpp @@ -83,7 +83,7 @@ namespace Exiv2 { throw(Error(kerInvalidSettingForImage, "IPTC metadata", "RW2")); } - void Rw2Image::setComment(const std::string_view /*comment*/) + void Rw2Image::setComment(std::string_view /*comment*/) { // not supported throw(Error(kerInvalidSettingForImage, "Image comment", "RW2")); diff --git a/src/tgaimage.cpp b/src/tgaimage.cpp index 0db1fff6..61031b9d 100644 --- a/src/tgaimage.cpp +++ b/src/tgaimage.cpp @@ -58,7 +58,7 @@ namespace Exiv2 { throw(Error(kerInvalidSettingForImage, "IPTC metadata", "TGA")); } - void TgaImage::setComment(const std::string_view /*comment*/) + void TgaImage::setComment(std::string_view /*comment*/) { // not supported throw(Error(kerInvalidSettingForImage, "Image comment", "TGA")); diff --git a/src/tiffimage.cpp b/src/tiffimage.cpp index e7a6a81b..ea5445e7 100644 --- a/src/tiffimage.cpp +++ b/src/tiffimage.cpp @@ -162,7 +162,7 @@ namespace Exiv2 { return pixelHeightPrimary_; } - void TiffImage::setComment(const std::string_view /*comment*/) + void TiffImage::setComment(std::string_view /*comment*/) { // not supported throw(Error(kerInvalidSettingForImage, "Image comment", "TIFF")); diff --git a/src/webpimage.cpp b/src/webpimage.cpp index 3cc1c9f8..f881c3f7 100644 --- a/src/webpimage.cpp +++ b/src/webpimage.cpp @@ -96,7 +96,7 @@ namespace Exiv2 { // throw(Error(kerInvalidSettingForImage, "IPTC metadata", "WebP")); } - void WebPImage::setComment(const std::string_view /*comment*/) + void WebPImage::setComment(std::string_view /*comment*/) { // not supported throw(Error(kerInvalidSettingForImage, "Image comment", "WebP")); diff --git a/src/xmpsidecar.cpp b/src/xmpsidecar.cpp index b4cbb23a..cb709a5c 100644 --- a/src/xmpsidecar.cpp +++ b/src/xmpsidecar.cpp @@ -62,7 +62,7 @@ namespace Exiv2 { return "application/rdf+xml"; } - void XmpSidecar::setComment(const std::string_view /*comment*/) + void XmpSidecar::setComment(std::string_view /*comment*/) { // not supported throw(Error(kerInvalidSettingForImage, "Image comment", "XMP"));