diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-01 06:21:53 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-01 06:21:53 +0000 |
commit | a72df5fae800ffc271b1e0761050516e56ca4a0c (patch) | |
tree | 857555eaf0e7fa26c72392d5f9a501a088022e70 | |
parent | 112a769379d4a56b2b9bf038bef5bbbb2517bfbd (diff) | |
download | bcm5719-llvm-a72df5fae800ffc271b1e0761050516e56ca4a0c.tar.gz bcm5719-llvm-a72df5fae800ffc271b1e0761050516e56ca4a0c.zip |
Support/PathV2: Add is_{absolute,relative} implementation.
llvm-svn: 120560
-rw-r--r-- | llvm/lib/Support/PathV2.cpp | 24 | ||||
-rw-r--r-- | llvm/unittests/Support/Path.cpp | 2 |
2 files changed, 26 insertions, 0 deletions
diff --git a/llvm/lib/Support/PathV2.cpp b/llvm/lib/Support/PathV2.cpp index 57ccf893d9b..a4a3f383411 100644 --- a/llvm/lib/Support/PathV2.cpp +++ b/llvm/lib/Support/PathV2.cpp @@ -642,6 +642,30 @@ error_code has_extension(const Twine &path, bool &result) { return make_error_code(errc::success); } +error_code is_absolute(const Twine &path, bool &result) { + SmallString<128> path_storage; + StringRef p = path.toStringRef(path_storage); + + bool rootDir = false, + rootName = false; + if (error_code ec = has_root_directory(p, rootDir)) return ec; +#ifdef LLVM_ON_WIN32 + if (error_code ec = has_root_name(p, rootName)) return ec; +#else + rootName = true; +#endif + + result = rootDir && rootName; + return make_error_code(errc::success); +} + +error_code is_relative(const Twine &path, bool &result) { + bool res; + error_code ec = is_absolute(path, res); + result = !res; + return ec; +} + } } } diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp index 3f50e708e64..24718648996 100644 --- a/llvm/unittests/Support/Path.cpp +++ b/llvm/unittests/Support/Path.cpp @@ -112,6 +112,8 @@ TEST(Support, Path) { TEST_PATH(stem, *i, sfres); TEST_PATH(has_extension, *i, bres); TEST_PATH(extension, *i, sfres); + TEST_PATH(is_absolute, *i, bres); + TEST_PATH(is_relative, *i, bres); SmallString<16> temp_store; TEST_PATH_SMALLVEC(make_absolute, *i, temp_store); |