Eliminate duplicate copies of lastPathComponent function.

This commit is contained in:
Stephen Anthony 2020-12-23 22:21:46 -03:30
parent 5853e7eb53
commit e14da1344a
4 changed files with 20 additions and 64 deletions

View File

@ -106,21 +106,6 @@ class FilesystemNodeZIP : public AbstractFSNode
// ZipHandler static reference variable responsible for accessing ZIP files
static unique_ptr<ZipHandler> myZipHandler;
// Get last component of path
static const char* lastPathComponent(const string& str)
{
if(str.empty())
return "";
const char* start = str.c_str();
const char* cur = start + str.size() - 2;
while (cur >= start && !(*cur == '/' || *cur == '\\'))
--cur;
return cur + 1;
}
};
#endif

View File

@ -471,6 +471,26 @@ class AbstractFSNode
* a try-catch block.
*/
virtual size_t write(const stringstream& buffer) const { return 0; }
/**
* Returns the last component of a given path.
*
* @param str String containing the path.
* @return Pointer to the first char of the last component inside str.
*/
static const char* lastPathComponent(const string& str)
{
if(str.empty())
return "";
const char* start = str.c_str();
const char* cur = start + str.size() - 2;
while (cur >= start && !(*cur == '/' || *cur == '\\'))
--cur;
return cur + 1;
}
};
#endif

View File

@ -89,30 +89,6 @@ class FilesystemNodePOSIX : public AbstractFSNode
* using the stat() function.
*/
void setFlags();
/**
* Returns the last component of a given path.
*
* Examples:
* /foo/bar.txt would return /bar.txt
* /foo/bar/ would return /bar/
*
* @param str String containing the path.
* @return Pointer to the first char of the last component inside str.
*/
static const char* lastPathComponent(const string& str)
{
if(str.empty())
return "";
const char* start = str.c_str();
const char* cur = start + str.size() - 2;
while (cur >= start && *cur != '/')
--cur;
return cur + 1;
}
};
#endif

View File

@ -39,31 +39,6 @@
#include "Windows.hxx"
#include "FSNodeWINDOWS.hxx"
/**
* Returns the last component of a given path.
*
* Examples:
* c:\foo\bar.txt would return "\bar.txt"
* c:\foo\bar\ would return "\bar\"
*
* @param str Path to obtain the last component from.
* @return Pointer to the first char of the last component inside str.
*/
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const char* lastPathComponent(const string& str)
{
if(str.empty())
return "";
const char* start = str.c_str();
const char* cur = start + str.size() - 2;
while(cur >= start && *cur != '\\')
--cur;
return cur + 1;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool FilesystemNodeWINDOWS::exists() const
{