Home | History | Annotate | Download | only in Support

Lines Matching refs:Path

1 //===-- Path.cpp - Implement OS Path Concept ------------------------------===//
10 // This file implements the operating system Path API.
15 #include "llvm/Support/Path.h"
35 using llvm::sys::path::is_separator;
45 StringRef find_first_component(StringRef path) {
53 if (path.empty())
54 return path;
58 if (path.size() >= 2 && std::isalpha(static_cast<unsigned char>(path[0])) &&
59 path[1] == ':')
60 return path.substr(0, 2);
64 if ((path.size() > 2) &&
65 is_separator(path[0]) &&
66 path[0] == path[1] &&
67 !is_separator(path[2])) {
69 size_t end = path.find_first_of(separators, 2);
70 return path.substr(0, end);
74 if (is_separator(path[0]))
75 return path.substr(0, 1);
77 if (path.startswith(".."))
78 return path.substr(0, 2);
80 if (path[0] == '.')
81 return path.substr(0, 1);
84 size_t end = path.find_first_of(separators);
85 return path.substr(0, end);
141 size_t parent_path_end(StringRef path) {
142 size_t end_pos = filename_pos(path);
144 bool filename_was_sep = path.size() > 0 && is_separator(path[end_pos]);
147 size_t root_dir_pos = root_dir_start(path.substr(0, end_pos));
151 is_separator(path[end_pos - 1]))
167 // Implemented in Unix/Path.inc and Windows/Path.inc.
179 if (!sys::path::is_absolute(Twine(ModelStorage))) {
183 sys::path::append(TDir, Twine(ModelStorage));
189 // path already exists.
241 namespace path {
243 const_iterator begin(StringRef path) {
245 i.Path = path;
246 i.Component = find_first_component(path);
251 const_iterator end(StringRef path) {
253 i.Path = path;
254 i.Position = path.size();
259 assert(Position < Path.size() && "Tried to increment past end!");
265 if (Position == Path.size()) {
278 if (is_separator(Path[Position])) {
286 Component = Path.substr(Position, 1);
291 while (Position != Path.size() &&
292 is_separator(Path[Position])) {
297 if (Position == Path.size()) {
305 size_t end_pos = Path.find_first_of(separators, Position);
306 Component = Path.slice(Position, end_pos);
313 // we are the root path.
314 size_t root_dir_pos = root_dir_start(Path);
315 if (Position == Path.size() &&
316 Path.size() > root_dir_pos + 1 &&
317 is_separator(Path[Position - 1])) {
328 is_separator(Path[end_pos - 1]))
332 size_t start_pos = filename_pos(Path.substr(0, end_pos));
333 Component = Path.slice(start_pos, end_pos);
339 return Path.begin() == RHS.Path.begin() &&
351 const StringRef root_path(StringRef path) {
352 const_iterator b = begin(path),
354 e = end(path);
367 return path.substr(0, b->size() + pos->size());
383 const StringRef root_name(StringRef path) {
384 const_iterator b = begin(path),
385 e = end(path);
401 // No path or no name.
405 const StringRef root_directory(StringRef path) {
406 const_iterator b = begin(path),
408 e = end(path);
430 // No path or no root.
434 const StringRef relative_path(StringRef path) {
435 StringRef root = root_path(path);
436 return path.substr(root.size());
439 void append(SmallVectorImpl<char> &path, const Twine &a,
457 bool path_has_sep = !path.empty() && is_separator(path[path.size() - 1]);
467 path.append(c.begin(), c.end());
471 if (!component_has_sep && !(path.empty() || is_root_name)) {
473 path.push_back(preferred_separator);
476 path.append(i->begin(), i->end());
480 void append(SmallVectorImpl<char> &path,
483 path::append(path, *begin);
486 const StringRef parent_path(StringRef path) {
487 size_t end_pos = parent_path_end(path);
491 return path.substr(0, end_pos);
494 void remove_filename(SmallVectorImpl<char> &path) {
495 size_t end_pos = parent_path_end(StringRef(path.begin(), path.size()));
497 path.set_size(end_pos);
500 void replace_extension(SmallVectorImpl<char> &path, const Twine &extension) {
501 StringRef p(path.begin(), path.size());
508 path.set_size(pos);
512 path.push_back('.');
515 path.append(ext.begin(), ext.end());
518 void native(const Twine &path, SmallVectorImpl<char> &result) {
519 assert((!path.isSingleStringRef() ||
520 path.getSingleStringRef().data() != result.data()) &&
521 "path and result are not allowed to overlap!");
524 path.toVector(result);
528 void native(SmallVectorImpl<char> &path) {
530 std::replace(path.begin(), path.end(), '/', '\\');
534 const StringRef filename(StringRef path) {
535 return *(--end(path));
538 const StringRef stem(StringRef path) {
539 StringRef fname = filename(path);
551 const StringRef extension(StringRef path) {
552 StringRef fname = filename(path);
632 bool has_root_name(const Twine &path) {
634 StringRef p = path.toStringRef(path_storage);
639 bool has_root_directory(const Twine &path) {
641 StringRef p = path.toStringRef(path_storage);
646 bool has_root_path(const Twine &path) {
648 StringRef p = path.toStringRef(path_storage);
653 bool has_relative_path(const Twine &path) {
655 StringRef p = path.toStringRef(path_storage);
660 bool has_filename(const Twine &path) {
662 StringRef p = path.toStringRef(path_storage);
667 bool has_parent_path(const Twine &path) {
669 StringRef p = path.toStringRef(path_storage);
674 bool has_stem(const Twine &path) {
676 StringRef p = path.toStringRef(path_storage);
681 bool has_extension(const Twine &path) {
683 StringRef p = path.toStringRef(path_storage);
688 bool is_absolute(const Twine &path) {
690 StringRef p = path.toStringRef(path_storage);
702 bool is_relative(const Twine &path) {
703 return !is_absolute(path);
706 } // end namespace path
710 std::error_code getUniqueID(const Twine Path, UniqueID &Result) {
712 std::error_code EC = status(Path, Status);
773 std::error_code make_absolute(SmallVectorImpl<char> &path) {
774 StringRef p(path.data(), path.size());
776 bool rootDirectory = path::has_root_directory(p),
778 rootName = path::has_root_name(p);
792 // Relative path. Prepend the current directory.
794 // Append path to the current directory.
795 path::append(current_dir, p);
796 // Set path to the result.
797 path.swap(current_dir);
802 StringRef cdrn = path::root_name(current_dir);
804 path::append(curDirRootName, p);
805 // Set path to the result.
806 path.swap(curDirRootName);
811 StringRef pRootName = path::root_name(p);
812 StringRef bRootDirectory = path::root_directory(current_dir);
813 StringRef bRelativePath = path::relative_path(current_dir);
814 StringRef pRelativePath = path::relative_path(p);
817 path::append(res, pRootName, bRootDirectory, bRelativePath, pRelativePath);
818 path.swap(res);
826 std::error_code create_directories(const Twine &Path, bool IgnoreExisting) {
828 StringRef P = Path.toStringRef(PathStorage);
839 StringRef Parent = path::parent_path(P);
895 std::error_code is_directory(const Twine &path, bool &result) {
897 if (std::error_code ec = status(path, st))
907 std::error_code is_regular_file(const Twine &path, bool &result) {
909 if (std::error_code ec = status(path, st))
922 SmallString<128> path(Path.begin(), Path.end());
923 path::remove_filename(path);
924 path::append(path, filename);
925 Path = path.str();
1061 std::error_code identify_magic(const Twine &Path, file_magic &Result) {
1063 if (std::error_code EC = openFileForRead(Path, FD))
1076 return fs::status(Path, result);
1085 #include "Unix/Path.inc"
1088 #include "Windows/Path.inc"