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);
493 bool has_root_name(const Twine &path) {
495 StringRef p = path.toStringRef(path_storage);
500 bool has_root_directory(const Twine &path) {
502 StringRef p = path.toStringRef(path_storage);
507 bool has_root_path(const Twine &path) {
509 StringRef p = path.toStringRef(path_storage);
514 bool has_relative_path(const Twine &path) {
516 StringRef p = path.toStringRef(path_storage);
521 bool has_filename(const Twine &path) {
523 StringRef p = path.toStringRef(path_storage);
528 bool has_parent_path(const Twine &path) {
530 StringRef p = path.toStringRef(path_storage);
535 bool has_stem(const Twine &path) {
537 StringRef p = path.toStringRef(path_storage);
542 bool has_extension(const Twine &path) {
544 StringRef p = path.toStringRef(path_storage);
549 bool is_absolute(const Twine &path) {
551 StringRef p = path.toStringRef(path_storage);
563 bool is_relative(const Twine &path) {
564 return !is_absolute(path);
567 } // end namespace path
571 error_code make_absolute(SmallVectorImpl<char> &path) {
572 StringRef p(path.data(), path.size());
574 bool rootName = path::has_root_name(p),
575 rootDirectory = path::has_root_directory(p);
585 // Relative path. Prepend the current directory.
587 // Append path to the current directory.
588 path::append(current_dir, p);
589 // Set path to the result.
590 path.swap(current_dir);
595 StringRef cdrn = path::root_name(current_dir);
597 path::append(curDirRootName, p);
598 // Set path to the result.
599 path.swap(curDirRootName);
604 StringRef pRootName = path::root_name(p);
605 StringRef bRootDirectory = path::root_directory(current_dir);
606 StringRef bRelativePath = path::relative_path(current_dir);
607 StringRef pRelativePath = path::relative_path(p);
610 path::append(res, pRootName, bRootDirectory, bRelativePath, pRelativePath);
611 path.swap(res);
619 error_code create_directories(const Twine &path, bool &existed) {
621 StringRef p = path.toStringRef(path_storage);
623 StringRef parent = path::parent_path(p);
646 error_code is_directory(const Twine &path, bool &result) {
648 path, st))
658 error_code is_regular_file(const Twine &path, bool &result) {
660 if (error_code ec = status(path, st))
670 error_code is_symlink(const Twine &path, bool &result) {
672 if (error_code ec = status(path, st))
687 SmallString<128> path(Path.begin(), Path.end());
688 path::remove_filename(path);
689 path::append(path, filename);
690 Path = path.str();
695 error_code has_magic(const Twine &path, const Twine &magic, bool &result) {
700 if (error_code ec = get_magic(path, Magic.size(), Buffer)) {
702 // Magic.size() > file_size(Path).
713 error_code identify_magic(const Twine &path, LLVMFileType &result) {
715 error_code ec = get_magic(path, Magic.capacity(), Magic);
724 error_code remove_all_r(StringRef path, file_type ft, uint32_t &count) {
728 for (directory_iterator i(path, ec), e; i != e; i.increment(ec)) {
732 if (error_code ec = remove_all_r(i->path(), st.type(), count)) return ec;
735 if (error_code ec = remove(path, obviously_this_exists)) return ec;
740 if (error_code ec = remove(path, obviously_this_exists)) return ec;
749 error_code remove_all(const Twine &path, uint32_t &num_removed) {
751 StringRef p = path.toStringRef(path_storage);
754 if (error_code ec = status(path, fs))
761 return fs::status(Path, result);