Support/PathV2: Cleanup separator handling.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121110 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael J. Spencer 2010-12-07 03:57:48 +00:00
parent 936671b2ea
commit ca3a339d76

View File

@ -31,7 +31,7 @@ namespace {
#ifdef LLVM_ON_WIN32 #ifdef LLVM_ON_WIN32
const StringRef separators = "\\/"; const StringRef separators = "\\/";
const char prefered_separator = '\\'; const char prefered_separator = '\\';
#else #else
const StringRef separators = "/"; const StringRef separators = "/";
const char prefered_separator = '/'; const char prefered_separator = '/';
@ -50,16 +50,19 @@ namespace {
if (path.empty()) if (path.empty())
return path; return path;
#ifdef LLVM_ON_WIN32
// C: // C:
if (path.size() >= 2 && std::isalpha(path[0]) && path[1] == ':') if (path.size() >= 2 && std::isalpha(path[0]) && path[1] == ':')
return StringRef(path.begin(), 2); return StringRef(path.begin(), 2);
#endif
// //net // //net
if ((path.size() > 2) && if ((path.size() > 2) &&
(path.startswith("\\\\") || path.startswith("//")) && is_separator(path[0]) &&
(path[2] != '\\' && path[2] != '/')) { path[0] == path[1] &&
!is_separator(path[2])) {
// Find the next directory separator. // Find the next directory separator.
size_t end = path.find_first_of("\\/", 2); size_t end = path.find_first_of(separators, 2);
if (end == StringRef::npos) if (end == StringRef::npos)
return path; return path;
else else
@ -67,7 +70,7 @@ namespace {
} }
// {/,\} // {/,\}
if (path[0] == '\\' || path[0] == '/') if (is_separator(path[0]))
return StringRef(path.begin(), 1); return StringRef(path.begin(), 1);
if (path.startswith("..")) if (path.startswith(".."))
@ -77,7 +80,7 @@ namespace {
return StringRef(path.begin(), 1); return StringRef(path.begin(), 1);
// * {file,directory}name // * {file,directory}name
size_t end = path.find_first_of("\\/", 2); size_t end = path.find_first_of(separators, 2);
if (end == StringRef::npos) if (end == StringRef::npos)
return path; return path;
else else
@ -89,7 +92,7 @@ namespace {
size_t filename_pos(const StringRef &str) { size_t filename_pos(const StringRef &str) {
if (str.size() == 2 && if (str.size() == 2 &&
is_separator(str[0]) && is_separator(str[0]) &&
is_separator(str[1])) str[0] == str[1])
return 0; return 0;
if (str.size() > 0 && is_separator(str[str.size() - 1])) if (str.size() > 0 && is_separator(str[str.size() - 1]))