diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2008-06-15 15:15:19 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2008-06-15 15:15:19 +0000 |
commit | fc19988bcbe6cfbe4668c50cd9689a711cc26cdd (patch) | |
tree | 6554a7d91fba95551482d0f47239babb2f6c7471 /lib/System/Unix | |
parent | 1662183a83063313af24708c323817daf4bad195 (diff) |
Fix the sys::Path::getSuffix() implementation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52288 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Unix')
-rw-r--r-- | lib/System/Unix/Path.inc | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc index 6035a14d27..5b91b038d4 100644 --- a/lib/System/Unix/Path.inc +++ b/lib/System/Unix/Path.inc @@ -303,6 +303,22 @@ Path::getBasename() const { return path.substr(slash, dot - slash); } +std::string +Path::getSuffix() const { + // Find the last slash + std::string::size_type slash = path.rfind('/'); + if (slash == std::string::npos) + slash = 0; + else + slash++; + + std::string::size_type dot = path.rfind('.'); + if (dot == std::string::npos || dot < slash) + return std::string() + else + return path.substr(dot + 1); +} + bool Path::getMagicNumber(std::string& Magic, unsigned len) const { assert(len < 1024 && "Request for magic string too long"); char* buf = (char*) alloca(1 + len); |