diff options
author | Max Horn | 2008-09-02 11:32:38 +0000 |
---|---|---|
committer | Max Horn | 2008-09-02 11:32:38 +0000 |
commit | 155b8606c1a798f89078aa39780a8b4c28161da7 (patch) | |
tree | 5c28bf3781de8a610f7fcd7953cd312e6432da12 /common/str.h | |
parent | 9c5d81fb831706aae3cc0ec001aec9f0f8d0439f (diff) | |
download | scummvm-rg350-155b8606c1a798f89078aa39780a8b4c28161da7.tar.gz scummvm-rg350-155b8606c1a798f89078aa39780a8b4c28161da7.tar.bz2 scummvm-rg350-155b8606c1a798f89078aa39780a8b4c28161da7.zip |
Added two new global funcs which ease proper handling of 'path' strings: Common::lastPathComponent() and Common::normalizePath()
svn-id: r34272
Diffstat (limited to 'common/str.h')
-rw-r--r-- | common/str.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/common/str.h b/common/str.h index 663a819e70..596bf341f9 100644 --- a/common/str.h +++ b/common/str.h @@ -227,6 +227,38 @@ extern char *ltrim(char *t); extern char *rtrim(char *t); extern char *trim(char *t); + +/** + * Returns the last component of a given path. + * + * Examples: + * /foo/bar.txt would return 'bar.txt' + * /foo/bar/ would return 'bar' + * /foo/./bar// would return 'bar' + * + * @param path the path of which we want to know the last component + * @param sep character used to separate path components + * @return The last component of the path. + */ +Common::String lastPathComponent(const Common::String &path, const char sep); + +/** + * Normalize a gien path to a canonical form. In particular: + * - trailing separators are removed: /foo/bar/ -> /foo/bar + * - double separators (= empty components) are removed: /foo//bar -> /foo/bar + * - dot components are removed: /foo/./bar -> /foo/bar + * + * @todo remove double dot components: /foo/baz/../bar -> /foo/bar + * + * @param path the path to normalize + * @param sep the separator token (usually '/' on Unix-style systems, or '\\' on Windows based stuff) + * @return the normalized path + */ +Common::String normalizePath(const Common::String &path, const char sep); + + + + class StringList : public Array<String> { public: void push_back(const char *str) { |