llvm.org GIT mirror llvm / 63cc3a8
Adds llvm::sys::path::is_separator() to test whether a char is a path separator on the host OS. Reviewed by dgregor. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125406 91177308-0d34-0410-b5e6-96231b3b80d8 Zhanyong Wan 9 years ago
3 changed file(s) with 32 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
257257 /// @result The extension of \a path.
258258 const StringRef extension(StringRef path);
259259
260 /// @brief Check whether the given char is a path separator on the host OS.
261 ///
262 /// @param value a character
263 /// @result true if \a value is a path separator character on the host OS
264 bool is_separator(char value);
265
260266 /// @brief Has root name?
261267 ///
262268 /// root_name != ""
1919
2020 namespace {
2121 using llvm::StringRef;
22
23 bool is_separator(const char value) {
24 switch(value) {
25 #ifdef LLVM_ON_WIN32
26 case '\\': // fall through
27 #endif
28 case '/': return true;
29 default: return false;
30 }
31 }
22 using llvm::sys::path::is_separator;
3223
3324 #ifdef LLVM_ON_WIN32
3425 const StringRef separators = "\\/";
153144
154145 return end_pos;
155146 }
156 }
147 } // end unnamed namespace
157148
158149 namespace llvm {
159150 namespace sys {
482473 return fname.substr(pos);
483474 }
484475
476 bool is_separator(char value) {
477 switch(value) {
478 #ifdef LLVM_ON_WIN32
479 case '\\': // fall through
480 #endif
481 case '/': return true;
482 default: return false;
483 }
484 }
485
485486 bool has_root_name(const Twine &path) {
486487 SmallString<128> path_storage;
487488 StringRef p = path.toStringRef(path_storage);
736737
737738 return success;
738739 }
739 }
740 } // end unnamed namespace
740741
741742 error_code remove_all(const Twine &path, uint32_t &num_removed) {
742743 SmallString<128> path_storage;
2727 } else {}
2828
2929 namespace {
30
31 TEST(is_separator, Works) {
32 EXPECT_TRUE(path::is_separator('/'));
33 EXPECT_FALSE(path::is_separator('\0'));
34 EXPECT_FALSE(path::is_separator('-'));
35 EXPECT_FALSE(path::is_separator(' '));
36
37 #ifdef LLVM_ON_WIN32
38 EXPECT_TRUE(path::is_separator('\\'));
39 #else
40 EXPECT_FALSE(path::is_separator('\\'));
41 #endif
42 }
3043
3144 TEST(Support, Path) {
3245 SmallVector paths;