diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2021-02-16 20:13:02 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2021-02-16 20:13:02 +0000 |
commit | b60736ec1405bb0a8dd40989f67ef4c93da068ab (patch) | |
tree | 5c43fbb7c9fc45f0f87e0e6795a86267dbd12f9d /llvm/lib/Support/Path.cpp | |
parent | cfca06d7963fa0909f90483b42a6d7d194d01e08 (diff) |
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r-- | llvm/lib/Support/Path.cpp | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index 37b3086fddf5..ef223ae5ac1d 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -354,10 +354,9 @@ StringRef root_path(StringRef path, Style style) { if ((++pos != e) && is_separator((*pos)[0], style)) { // {C:/,//net/}, so get the first two components. return path.substr(0, b->size() + pos->size()); - } else { - // just {C:,//net}, return the first component. - return *b; } + // just {C:,//net}, return the first component. + return *b; } // POSIX style root directory. @@ -467,8 +466,7 @@ StringRef parent_path(StringRef path, Style style) { size_t end_pos = parent_path_end(path, style); if (end_pos == StringRef::npos) return StringRef(); - else - return path.substr(0, end_pos); + return path.substr(0, end_pos); } void remove_filename(SmallVectorImpl<char> &path, Style style) { @@ -581,12 +579,10 @@ StringRef stem(StringRef path, Style style) { size_t pos = fname.find_last_of('.'); if (pos == StringRef::npos) return fname; - else - if ((fname.size() == 1 && fname == ".") || - (fname.size() == 2 && fname == "..")) - return fname; - else - return fname.substr(0, pos); + if ((fname.size() == 1 && fname == ".") || + (fname.size() == 2 && fname == "..")) + return fname; + return fname.substr(0, pos); } StringRef extension(StringRef path, Style style) { @@ -594,12 +590,10 @@ StringRef extension(StringRef path, Style style) { size_t pos = fname.find_last_of('.'); if (pos == StringRef::npos) return StringRef(); - else - if ((fname.size() == 1 && fname == ".") || - (fname.size() == 2 && fname == "..")) - return StringRef(); - else - return fname.substr(pos); + if ((fname.size() == 1 && fname == ".") || + (fname.size() == 2 && fname == "..")) + return StringRef(); + return fname.substr(pos); } bool is_separator(char value, Style style) { @@ -683,6 +677,24 @@ bool is_absolute(const Twine &path, Style style) { return rootDir && rootName; } +bool is_absolute_gnu(const Twine &path, Style style) { + SmallString<128> path_storage; + StringRef p = path.toStringRef(path_storage); + + // Handle '/' which is absolute for both Windows and POSIX systems. + // Handle '\\' on Windows. + if (!p.empty() && is_separator(p.front(), style)) + return true; + + if (real_style(style) == Style::windows) { + // Handle drive letter pattern (a character followed by ':') on Windows. + if (p.size() >= 2 && (p[0] && p[1] == ':')) + return true; + } + + return false; +} + bool is_relative(const Twine &path, Style style) { return !is_absolute(path, style); } @@ -1281,7 +1293,7 @@ Expected<TempFile> TempFile::create(const Twine &Model, unsigned Mode) { #endif return std::move(Ret); } -} +} // namespace fs -} // end namsspace sys -} // end namespace llvm +} // namespace sys +} // namespace llvm |