/// @result The extension of \a path.
const StringRef extension(StringRef path);
+/// @brief Check whether the given char is a path separator on the host OS.
+///
+/// @param value a character
+/// @result true if \a value is a path separator character on the host OS
+bool is_separator(char value);
+
/// @brief Has root name?
///
/// root_name != ""
namespace {
using llvm::StringRef;
-
- bool is_separator(const char value) {
- switch(value) {
-#ifdef LLVM_ON_WIN32
- case '\\': // fall through
-#endif
- case '/': return true;
- default: return false;
- }
- }
+ using llvm::sys::path::is_separator;
#ifdef LLVM_ON_WIN32
const StringRef separators = "\\/";
return end_pos;
}
-}
+} // end unnamed namespace
namespace llvm {
namespace sys {
return fname.substr(pos);
}
+bool is_separator(char value) {
+ switch(value) {
+#ifdef LLVM_ON_WIN32
+ case '\\': // fall through
+#endif
+ case '/': return true;
+ default: return false;
+ }
+}
+
bool has_root_name(const Twine &path) {
SmallString<128> path_storage;
StringRef p = path.toStringRef(path_storage);
return success;
}
-}
+} // end unnamed namespace
error_code remove_all(const Twine &path, uint32_t &num_removed) {
SmallString<128> path_storage;
namespace {
+TEST(is_separator, Works) {
+ EXPECT_TRUE(path::is_separator('/'));
+ EXPECT_FALSE(path::is_separator('\0'));
+ EXPECT_FALSE(path::is_separator('-'));
+ EXPECT_FALSE(path::is_separator(' '));
+
+#ifdef LLVM_ON_WIN32
+ EXPECT_TRUE(path::is_separator('\\'));
+#else
+ EXPECT_FALSE(path::is_separator('\\'));
+#endif
+}
+
TEST(Support, Path) {
SmallVector<StringRef, 40> paths;
paths.push_back("");