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

Refactoring & cleanup #2109

Merged
merged 25 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3d370cc
Improvements in urlencode
piponazo Feb 16, 2022
f1ff3aa
Make urldecode in-place
piponazo Feb 16, 2022
6f762b4
Use std::filesystem for fileExist
piponazo Feb 16, 2022
0726104
Hide pathOfFileUrl in the only place where it is used
piponazo Feb 16, 2022
45300ad
BasicIo::path() returns const ref
piponazo Feb 16, 2022
8b2d173
ReplaceStringInPlace does it in-place now
piponazo Feb 16, 2022
9b3a643
Use rename from filesystem
piponazo Feb 16, 2022
56b5ab9
Use remove from filesystem
piponazo Feb 16, 2022
a6185d2
Image::setComment now takes string_view
piponazo Feb 16, 2022
798cf9b
Remove dead code (winNumberOfLinks)
piponazo Feb 17, 2022
c0b663b
Remove dead code (LSTAT)
piponazo Feb 17, 2022
1d243ed
Remove dead code: copyXattrFrom
piponazo Feb 17, 2022
ea201ce
Remove dead code
piponazo Feb 17, 2022
d11479e
Replace dynamic C array by std::vector
piponazo Feb 17, 2022
59f4d0d
cppcheck: reduce scope of variables
piponazo Feb 17, 2022
476a5e2
Replace raw loop for any_of
piponazo Feb 17, 2022
b543f3e
Use filesystem in getExiv2ConfigPath
piponazo Feb 18, 2022
7e5ba7c
Remove many redundant or not needed header inclusions
piponazo Feb 18, 2022
7caf409
Use fs::file_size instead of stat
piponazo Feb 18, 2022
f060b58
Clean config.h from old stuff
piponazo Feb 18, 2022
76f01fd
Clean more header inclusions
piponazo Feb 18, 2022
9fb43f2
Use standard [[maybe_unused]]
piponazo Feb 18, 2022
f774a3b
Fix build on linux
piponazo Feb 18, 2022
8b3da36
Improvements from code review
piponazo Feb 19, 2022
21eb0ce
Fix build when EXIV2_BUILD_MESSAGES is ON
piponazo Feb 19, 2022
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
8 changes: 4 additions & 4 deletions include/exiv2/basicio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ namespace Exiv2 {
comprehensive error messages where only a BasicIo instance is
available.
*/
virtual std::string path() const =0;
virtual const std::string& path() const noexcept =0;

/*!
@brief Mark all the bNone blocks to bKnow. This avoids allocating memory
Expand Down Expand Up @@ -472,7 +472,7 @@ namespace Exiv2 {
//! Returns true if the file position has reached the end, otherwise false.
bool eof() const override;
//! Returns the path of the file
std::string path() const override;
const std::string& path() const noexcept override;

/*!
@brief Mark all the bNone blocks to bKnow. This avoids allocating memory
Expand Down Expand Up @@ -654,7 +654,7 @@ namespace Exiv2 {
//!Returns true if the IO position has reached the end, otherwise false.
bool eof() const override;
//! Returns a dummy path, indicating that memory access is used
std::string path() const override;
const std::string& path() const noexcept override;

/*!
@brief Mark all the bNone blocks to bKnow. This avoids allocating memory
Expand Down Expand Up @@ -898,7 +898,7 @@ namespace Exiv2 {
//!Returns true if the IO position has reached the end, otherwise false.
bool eof() const override;
//!Returns the URL of the file.
std::string path() const override;
const std::string& path() const noexcept override;

/*!
@brief Mark all the bNone blocks to bKnow. This avoids allocating memory
Expand Down
21 changes: 10 additions & 11 deletions src/basicio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,7 @@ namespace Exiv2 {

bool statOk = true;
mode_t origStMode = 0;
std::string spf;
char* pf = nullptr;
spf = path();
pf = const_cast<char*>(spf.c_str());
char* pf = const_cast<char*>(path().c_str());
piponazo marked this conversation as resolved.
Show resolved Hide resolved

// Get the permissions of the file, or linked-to file, on platforms which have lstat
#ifdef EXV_HAVE_LSTAT
Expand Down Expand Up @@ -720,7 +717,7 @@ namespace Exiv2 {
return std::feof(p_->fp_) != 0;
}

std::string FileIo::path() const
const std::string& FileIo::path() const noexcept
{
return p_->path_;
}
Expand Down Expand Up @@ -1044,9 +1041,10 @@ namespace Exiv2 {
return p_->eof_;
}

std::string MemIo::path() const
const std::string& MemIo::path() const noexcept
{
return "MemIo";
static std::string _path{"MemIo"};
return _path;
}

void MemIo::populateFakeData() {
Expand Down Expand Up @@ -1116,7 +1114,7 @@ namespace Exiv2 {
void XPathIo::transfer(BasicIo& src) {
if (isTemp_) {
// replace temp path to gent path.
std::string currentPath = path();
auto& currentPath = path();
setPath(ReplaceStringInPlace(currentPath, XPathIo::TEMP_FILE_EXT, XPathIo::GEN_FILE_EXT));
// rename the file
tempFilePath_ = path();
Expand Down Expand Up @@ -1585,7 +1583,7 @@ namespace Exiv2 {
return p_->eof_;
}

std::string RemoteIo::path() const
const std::string& RemoteIo::path() const noexcept
{
return p_->path_;
}
Expand Down Expand Up @@ -1989,8 +1987,9 @@ namespace Exiv2 {
return file.write(buf.c_data(), buf.size());
}

std::string ReplaceStringInPlace(std::string subject, const std::string& search,
const std::string& replace) {
/// \todo do it in place!
std::string ReplaceStringInPlace(std::string subject, const std::string& search, const std::string& replace)
{
size_t pos = 0;
while((pos = subject.find(search, pos)) != std::string::npos) {
subject.replace(pos, search.length(), replace);
Expand Down
2 changes: 1 addition & 1 deletion src/tgaimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace Exiv2 {
bool isTgaType(BasicIo& iIo, bool /*advance*/)
{
// not all TARGA files have a signature string, so first just try to match the file name extension
std::string path = iIo.path();
const std::string& path = iIo.path();
if( path.rfind(".tga") != std::string::npos
|| path.rfind(".TGA") != std::string::npos) {
return true;
Expand Down
Binary file modified test/data/template.exv
Binary file not shown.