Home | History | Annotate | Download | only in Support

Lines Matching refs:Path

1 //===-- PathV2.cpp - Implement OS Path Concept ------------------*- C++ -*-===//
23 using llvm::sys::path::is_separator;
35 StringRef find_first_component(StringRef path) {
43 if (path.empty())
44 return path;
48 if (path.size() >= 2 && std::isalpha(path[0]) && path[1] == ':')
49 return path.substr(0, 2);
53 if ((path.size() > 2) &&
54 is_separator(path[0]) &&
55 path[0] == path[1] &&
56 !is_separator(path[2])) {
58 size_t end = path.find_first_of(separators, 2);
59 return path.substr(0, end);
63 if (is_separator(path[0]))
64 return path.substr(0, 1);
66 if (path.startswith(".."))
67 return path.substr(0, 2);
69 if (path[0] == '.')
70 return path.substr(0, 1);
73 size_t end = path.find_first_of(separators, 2);
74 return path.substr(0, end);
130 size_t parent_path_end(StringRef path) {
131 size_t end_pos = filename_pos(path);
133 bool filename_was_sep = path.size() > 0 && is_separator(path[end_pos]);
136 size_t root_dir_pos = root_dir_start(path.substr(0, end_pos));
140 is_separator(path[end_pos - 1]))
152 namespace path {
154 const_iterator begin(StringRef path) {
156 i.Path = path;
157 i.Component = find_first_component(path);
162 const_iterator end(StringRef path) {
164 i.Path = path;
165 i.Position = path.size();
170 assert(Position < Path.size() && "Tried to increment past end!");
176 if (Position == Path.size()) {
189 if (is_separator(Path[Position])) {
197 Component = Path.substr(Position, 1);
202 while (Position != Path.size() &&
203 is_separator(Path[Position])) {
208 if (Position == Path.size()) {
216 size_t end_pos = Path.find_first_of(separators, Position);
217 Component = Path.slice(Position, end_pos);
224 if (Position == Path.size() &&
225 Path.size() > 1 &&
226 is_separator(Path[Position - 1])
228 && Path[Position - 2] != ':'
237 size_t root_dir_pos = root_dir_start(Path);
242 is_separator(Path[end_pos - 1]))
246 size_t start_pos = filename_pos(Path.substr(0, end_pos));
247 Component = Path.slice(start_pos, end_pos);
253 return Path.begin() == RHS.Path.begin() &&
265 const StringRef root_path(StringRef path) {
266 const_iterator b = begin(path),
268 e = end(path);
281 return path.substr(0, b->size() + pos->size());
297 const StringRef root_name(StringRef path) {
298 const_iterator b = begin(path),
299 e = end(path);
315 // No path or no name.
319 const StringRef root_directory(StringRef path) {
320 const_iterator b = begin(path),
322 e = end(path);
344 // No path or no root.
348 const StringRef relative_path(StringRef path) {
349 StringRef root = root_path(path);
353 void append(SmallVectorImpl<char> &path, const Twine &a,
371 bool path_has_sep = !path.empty() && is_separator(path[path.size() - 1]);
381 path.append(c.begin(), c.end());
385 if (!component_has_sep && !(path.empty() || is_root_name)) {
387 path.push_back(prefered_separator);
390 path.append(i->begin(), i->end());
394 void append(SmallVectorImpl<char> &path,
397 path::append(path, *begin);
400 const StringRef parent_path(StringRef path) {
401 size_t end_pos = parent_path_end(path);
405 return path.substr(0, end_pos);
408 void remove_filename(SmallVectorImpl<char> &path) {
409 size_t end_pos = parent_path_end(StringRef(path.begin(), path.size()));
411 path.set_size(end_pos);
414 void replace_extension(SmallVectorImpl<char> &path, const Twine &extension) {
415 StringRef p(path.begin(), path.size());
422 path.set_size(pos);
426 path.push_back('.');
429 path.append(ext.begin(), ext.end());
432 void native(const Twine &path, SmallVectorImpl<char> &result) {
437 StringRef p = path.toStringRef(path_storage);
449 path.toVector(result);
453 const StringRef filename(StringRef path) {
454 return *(--end(path));
457 const StringRef stem(StringRef path) {
458 StringRef fname = filename(path);
470 const StringRef extension(StringRef path) {
471 StringRef fname = filename(path);
523 bool has_root_name(const Twine &path) {
525 StringRef p = path.toStringRef(path_storage);
530 bool has_root_directory(const Twine &path) {
532 StringRef p = path.toStringRef(path_storage);
537 bool has_root_path(const Twine &path) {
539 StringRef p = path.toStringRef(path_storage);
544 bool has_relative_path(const Twine &path) {
546 StringRef p = path.toStringRef(path_storage);
551 bool has_filename(const Twine &path) {
553 StringRef p = path.toStringRef(path_storage);
558 bool has_parent_path(const Twine &path) {
560 StringRef p = path.toStringRef(path_storage);
565 bool has_stem(const Twine &path) {
567 StringRef p = path.toStringRef(path_storage);
572 bool has_extension(const Twine &path) {
574 StringRef p = path.toStringRef(path_storage);
579 bool is_absolute(const Twine &path) {
581 StringRef p = path.toStringRef(path_storage);
593 bool is_relative(const Twine &path) {
594 return !is_absolute(path);
597 } // end namespace path
601 error_code make_absolute(SmallVectorImpl<char> &path) {
602 StringRef p(path.data(), path.size());
604 bool rootName = path::has_root_name(p),
605 rootDirectory = path::has_root_directory(p);
615 // Relative path. Prepend the current directory.
617 // Append path to the current directory.
618 path::append(current_dir, p);
619 // Set path to the result.
620 path.swap(current_dir);
625 StringRef cdrn = path::root_name(current_dir);
627 path::append(curDirRootName, p);
628 // Set path to the result.
629 path.swap(curDirRootName);
634 StringRef pRootName = path::root_name(p);
635 StringRef bRootDirectory = path::root_directory(current_dir);
636 StringRef bRelativePath = path::relative_path(current_dir);
637 StringRef pRelativePath = path::relative_path(p);
640 path::append(res, pRootName, bRootDirectory, bRelativePath, pRelativePath);
641 path.swap(res);
649 error_code create_directories(const Twine &path, bool &existed) {
651 StringRef p = path.toStringRef(path_storage);
653 StringRef parent = path::parent_path(p);
676 error_code is_directory(const Twine &path, bool &result) {
678 if (error_code ec = status(path, st))
688 error_code is_regular_file(const Twine &path, bool &result) {
690 if (error_code ec = status(path, st))
700 error_code is_symlink(const Twine &path, bool &result) {
702 if (error_code ec = status(path, st))
716 SmallString<128> path(Path.begin(), Path.end());
717 path::remove_filename(path);
718 path::append(path, filename);
719 Path = path.str();
723 error_code has_magic(const Twine &path, const Twine &magic, bool &result) {
728 if (error_code ec = get_magic(path, Magic.size(), Buffer)) {
730 // Magic.size() > file_size(Path).
741 error_code identify_magic(const Twine &path, LLVMFileType &result) {
743 error_code ec = get_magic(path, Magic.capacity(), Magic);
752 error_code remove_all_r(StringRef path, file_type ft, uint32_t &count) {
756 for (directory_iterator i(path, ec), e; i != e; i.increment(ec)) {
760 if (error_code ec = remove_all_r(i->path(), st.type(), count)) return ec;
763 if (error_code ec = remove(path, obviously_this_exists)) return ec;
768 if (error_code ec = remove(path, obviously_this_exists)) return ec;
777 error_code remove_all(const Twine &path, uint32_t &num_removed) {
779 StringRef p = path.toStringRef(path_storage);
782 if (error_code ec = status(path, fs))
789 return fs::status(Path, result);