constexpr string conversions

Signed-off-by: Rosen Penev <rosenp@gmail.com>
main
Rosen Penev 3 years ago
parent 3a2309bfea
commit a25bbe133f

@ -690,12 +690,12 @@ namespace Exiv2 {
@brief The extension of the temporary file which is created when getting input data @brief The extension of the temporary file which is created when getting input data
to read metadata. This file will be deleted in destructor. to read metadata. This file will be deleted in destructor.
*/ */
static const std::string TEMP_FILE_EXT; static constexpr std::string_view TEMP_FILE_EXT = ".exiv2_temp";
/*! /*!
@brief The extension of the generated file which is created when getting input data @brief The extension of the generated file which is created when getting input data
to add or modify the metadata. to add or modify the metadata.
*/ */
static const std::string GEN_FILE_EXT; static constexpr std::string_view GEN_FILE_EXT = ".exiv2";
//! @name Creators //! @name Creators
//@{ //@{

@ -53,7 +53,7 @@ namespace fs = std::filesystem;
// class member definitions // class member definitions
namespace { namespace {
/// @brief replace each substring of the subject that matches the given search string with the given replacement. /// @brief replace each substring of the subject that matches the given search string with the given replacement.
void ReplaceStringInPlace(std::string& subject, const std::string& search, const std::string& replace) void ReplaceStringInPlace(std::string& subject, std::string_view search, std::string_view replace)
{ {
auto pos = subject.find(search); auto pos = subject.find(search);
while (pos != std::string::npos) { while (pos != std::string::npos) {
@ -946,9 +946,6 @@ namespace Exiv2 {
} }
#else #else
const std::string XPathIo::TEMP_FILE_EXT = ".exiv2_temp";
const std::string XPathIo::GEN_FILE_EXT = ".exiv2";
XPathIo::XPathIo(const std::string& orgPath) : FileIo(XPathIo::writeDataToFile(orgPath)), isTemp_(true) XPathIo::XPathIo(const std::string& orgPath) : FileIo(XPathIo::writeDataToFile(orgPath)), isTemp_(true)
{ {
tempFilePath_ = path(); tempFilePath_ = path();

@ -33,7 +33,7 @@ namespace {
using Exiv2::byte; using Exiv2::byte;
// signature of DOS EPS // signature of DOS EPS
const std::string dosEpsSignature = "\xC5\xD0\xD3\xC6"; constexpr auto dosEpsSignature = std::string_view("\xC5\xD0\xD3\xC6");
// first line of EPS // first line of EPS
constexpr auto epsFirstLine = std::array<std::string_view, 3>{ constexpr auto epsFirstLine = std::array<std::string_view, 3>{
@ -43,11 +43,12 @@ namespace {
}; };
// blank EPS file // blank EPS file
const std::string epsBlank = "%!PS-Adobe-3.0 EPSF-3.0\n" constexpr auto epsBlank = std::string_view(
"%%BoundingBox: 0 0 0 0\n"; "%!PS-Adobe-3.0 EPSF-3.0\n"
"%%BoundingBox: 0 0 0 0\n");
// list of all valid XMP headers // list of all valid XMP headers
const std::string xmpHeaders[] = { constexpr std::string_view xmpHeaders[] = {
// We do not enforce the trailing "?>" here, because the XMP specification // We do not enforce the trailing "?>" here, because the XMP specification
// permits additional attributes after begin="..." and id="...". // permits additional attributes after begin="..." and id="...".
@ -67,11 +68,11 @@ namespace {
// list of all valid XMP trailers // list of all valid XMP trailers
struct XmpTrailer { struct XmpTrailer {
std::string trailer; std::string_view trailer;
bool readOnly; bool readOnly;
}; };
const XmpTrailer xmpTrailers[] = { constexpr XmpTrailer xmpTrailers[] = {
// We do not enforce the trailing "?>" here, because the XMP specification // We do not enforce the trailing "?>" here, because the XMP specification
// permits additional attributes after end="...". // permits additional attributes after end="...".
@ -83,7 +84,7 @@ namespace {
}; };
// closing part of all valid XMP trailers // closing part of all valid XMP trailers
const std::string xmpTrailerEnd = "?>"; constexpr auto xmpTrailerEnd = std::string_view("?>");
//! Write data into temp file, taking care of errors //! Write data into temp file, taking care of errors
void writeTemp(BasicIo& tempIo, const byte* data, size_t size) void writeTemp(BasicIo& tempIo, const byte* data, size_t size)
@ -186,7 +187,7 @@ namespace {
for (size_t trailerPos = xmpPos + header.size(); trailerPos < size; trailerPos++) { for (size_t trailerPos = xmpPos + header.size(); trailerPos < size; trailerPos++) {
if (data[xmpPos] != '\x00' && data[xmpPos] != '<') continue; if (data[xmpPos] != '\x00' && data[xmpPos] != '<') continue;
for (auto&& xmpTrailer : xmpTrailers) { for (auto&& xmpTrailer : xmpTrailers) {
const std::string& trailer = xmpTrailer.trailer; auto trailer = xmpTrailer.trailer;
const bool readOnly = xmpTrailer.readOnly; const bool readOnly = xmpTrailer.readOnly;
if (trailerPos + trailer.size() > size) continue; if (trailerPos + trailer.size() > size) continue;

@ -206,15 +206,14 @@ namespace Exiv2 {
chType[4]=0; chType[4]=0;
if ( option == kpsBasic || option == kpsXMP || option == kpsIccProfile || option == kpsRecursive ) { if ( option == kpsBasic || option == kpsXMP || option == kpsIccProfile || option == kpsRecursive ) {
constexpr auto xmpKey = "XML:com.adobe.xmp";
const std::string xmpKey = "XML:com.adobe.xmp"; constexpr auto exifKey = "Raw profile type exif";
const std::string exifKey = "Raw profile type exif"; constexpr auto app1Key = "Raw profile type APP1";
const std::string app1Key = "Raw profile type APP1"; constexpr auto iptcKey = "Raw profile type iptc";
const std::string iptcKey = "Raw profile type iptc"; constexpr auto iccKey = "icc";
const std::string iccKey = "icc"; constexpr auto softKey = "Software";
const std::string softKey = "Software"; constexpr auto commKey = "Comment";
const std::string commKey = "Comment"; constexpr auto descKey = "Description";
const std::string descKey = "Description";
bool bPrint = option == kpsBasic || option == kpsRecursive ; bool bPrint = option == kpsBasic || option == kpsRecursive ;
if ( bPrint ) { if ( bPrint ) {

@ -831,7 +831,7 @@ namespace Exiv2 {
return value_.size(); return value_.size();
} }
static const std::string x_default = "x-default"; static constexpr auto x_default = "x-default";
std::ostream& LangAltValue::write(std::ostream& os) const std::ostream& LangAltValue::write(std::ostream& os) const
{ {

Loading…
Cancel
Save