diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-01 03:37:41 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-01 03:37:41 +0000 |
commit | 5265f22f4558f376dece4744b3fe2ae1c637d223 (patch) | |
tree | 8390432374437bae8dd6dce7f327ed6403aa0744 /lib/Support/PathV2.cpp | |
parent | 28cd48fffbe2e31184332674429d6d087ad3631f (diff) |
Support/PathV2: Add extension implementation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120550 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/PathV2.cpp')
-rw-r--r-- | lib/Support/PathV2.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/Support/PathV2.cpp b/lib/Support/PathV2.cpp index e360e9cd1f..47e59dd1cf 100644 --- a/lib/Support/PathV2.cpp +++ b/lib/Support/PathV2.cpp @@ -574,6 +574,22 @@ error_code stem(const StringRef &path, StringRef &result) { return make_error_code(errc::success); } +error_code extension(const StringRef &path, StringRef &result) { + StringRef fname; + if (error_code ec = filename(path, fname)) return ec; + size_t pos = fname.find_last_of('.'); + if (pos == StringRef::npos) + result = StringRef(); + else + if ((fname.size() == 1 && fname == ".") || + (fname.size() == 2 && fname == "..")) + result = StringRef(); + else + result = StringRef(fname.begin() + pos, fname.size() - pos); + + return make_error_code(errc::success); +} + } } } |