FSNode code: Merged most versions of lastPathComponent() into one new AbstractFilesystemNode::lastPathComponent() method, with customizable path separator character
svn-id: r34197
This commit is contained in:
parent
79fafb7b6a
commit
cb21c25e41
12 changed files with 72 additions and 231 deletions
|
@ -37,31 +37,6 @@
|
|||
#endif
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
const char *lastPathComponent(const Common::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;
|
||||
}
|
||||
|
||||
void POSIXFilesystemNode::setFlags() {
|
||||
struct stat st;
|
||||
|
||||
|
@ -93,7 +68,7 @@ POSIXFilesystemNode::POSIXFilesystemNode(const Common::String &p, bool verify) {
|
|||
_path = p;
|
||||
}
|
||||
|
||||
_displayName = lastPathComponent(_path);
|
||||
_displayName = lastPathComponent(_path, '/');
|
||||
|
||||
if (verify) {
|
||||
setFlags();
|
||||
|
@ -224,7 +199,7 @@ AbstractFilesystemNode *POSIXFilesystemNode::getParent() const {
|
|||
return 0;
|
||||
|
||||
const char *start = _path.c_str();
|
||||
const char *end = lastPathComponent(_path);
|
||||
const char *end = lastPathComponent(_path, '/');
|
||||
|
||||
#ifdef __OS2__
|
||||
if (end == start)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue