From cb21c25e417bb546f6678ab9da7440c6e1b4b2fd Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 27 Aug 2008 20:31:22 +0000 Subject: FSNode code: Merged most versions of lastPathComponent() into one new AbstractFilesystemNode::lastPathComponent() method, with customizable path separator character svn-id: r34197 --- backends/fs/palmos/palmos-fs.cpp | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) (limited to 'backends/fs/palmos') diff --git a/backends/fs/palmos/palmos-fs.cpp b/backends/fs/palmos/palmos-fs.cpp index 5edb6c2d26..69d9f350f5 100644 --- a/backends/fs/palmos/palmos-fs.cpp +++ b/backends/fs/palmos/palmos-fs.cpp @@ -80,30 +80,6 @@ private: static void addFile(AbstractFSList &list, ListMode mode, const Char *base, FileInfoType* find_data); }; -/** - * 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 PalmOSFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const char *base, FileInfoType* find_data) { PalmOSFilesystemNode entry; bool isDir; @@ -138,7 +114,7 @@ PalmOSFilesystemNode::PalmOSFilesystemNode() { PalmOSFilesystemNode::PalmOSFilesystemNode(const String &p) { _path = p; - _displayName = lastPathComponent(_path); + _displayName = lastPathComponent(_path, '/'); UInt32 attr; FileRef handle; @@ -215,13 +191,13 @@ AbstractFilesystemNode *PalmOSFilesystemNode::getParent() const { if (!_isPseudoRoot) { const char *start = _path.c_str(); - const char *end = lastPathComponent(_path); + const char *end = lastPathComponent(_path, '/'); p = new PalmOSFilesystemNode(); p->_path = String(start, end - start); p->_isValid = true; p->_isDirectory = true; - p->_displayName = lastPathComponent(p->_path); + p->_displayName = lastPathComponent(p->_path, '/'); p->_isPseudoRoot =(p->_path == "/"); } -- cgit v1.2.3