mirror of https://github.com/stella-emu/stella.git
Eliminate duplicate copies of lastPathComponent function.
This commit is contained in:
parent
5853e7eb53
commit
e14da1344a
|
@ -106,21 +106,6 @@ class FilesystemNodeZIP : public AbstractFSNode
|
||||||
|
|
||||||
// ZipHandler static reference variable responsible for accessing ZIP files
|
// ZipHandler static reference variable responsible for accessing ZIP files
|
||||||
static unique_ptr<ZipHandler> myZipHandler;
|
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
|
#endif
|
||||||
|
|
|
@ -471,6 +471,26 @@ class AbstractFSNode
|
||||||
* a try-catch block.
|
* a try-catch block.
|
||||||
*/
|
*/
|
||||||
virtual size_t write(const stringstream& buffer) const { return 0; }
|
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
|
#endif
|
||||||
|
|
|
@ -89,30 +89,6 @@ class FilesystemNodePOSIX : public AbstractFSNode
|
||||||
* using the stat() function.
|
* using the stat() function.
|
||||||
*/
|
*/
|
||||||
void setFlags();
|
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
|
#endif
|
||||||
|
|
|
@ -39,31 +39,6 @@
|
||||||
#include "Windows.hxx"
|
#include "Windows.hxx"
|
||||||
#include "FSNodeWINDOWS.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
|
bool FilesystemNodeWINDOWS::exists() const
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue