WPILibC++  2020.3.2
Path.h
1 //===- llvm/Support/Path.h - Path Operating System Concept ------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the wpi::sys::path namespace. It is designed after
11 // TR2/boost filesystem (v3), but modified to remove exception handling and the
12 // path class.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef WPIUTIL_WPI_PATH_H_
17 #define WPIUTIL_WPI_PATH_H_
18 
19 #include "wpi/Twine.h"
20 #include "wpi/iterator.h"
21 #include <cstdint>
22 #include <iterator>
23 #include <system_error>
24 
25 #ifdef _WIN32
26 // Disable iterator deprecation warning
27 #pragma warning(push)
28 #pragma warning(disable : 4996)
29 #endif
30 
31 namespace wpi {
32 namespace sys {
33 namespace path {
34 
35 enum class Style { windows, posix, native };
36 
39 
60  : public iterator_facade_base<const_iterator, std::input_iterator_tag,
61  const StringRef> {
62  StringRef Path;
63  StringRef Component;
64  size_t Position;
65  Style S;
66 
67  // An end iterator has Position = Path.size() + 1.
68  friend const_iterator begin(StringRef path, Style style);
69  friend const_iterator end(StringRef path);
70 
71 public:
72  reference operator*() const { return Component; }
73  const_iterator &operator++(); // preincrement
74  bool operator==(const const_iterator &RHS) const;
75 
77  ptrdiff_t operator-(const const_iterator &RHS) const;
78 };
79 
86  : public iterator_facade_base<reverse_iterator, std::input_iterator_tag,
87  const StringRef> {
88  StringRef Path;
89  StringRef Component;
90  size_t Position;
91  Style S;
92 
93  friend reverse_iterator rbegin(StringRef path, Style style);
94  friend reverse_iterator rend(StringRef path);
95 
96 public:
97  reference operator*() const { return Component; }
98  reverse_iterator &operator++(); // preincrement
99  bool operator==(const reverse_iterator &RHS) const;
100 
102  ptrdiff_t operator-(const reverse_iterator &RHS) const;
103 };
104 
108 const_iterator begin(StringRef path, Style style = Style::native);
109 
113 const_iterator end(StringRef path);
114 
118 reverse_iterator rbegin(StringRef path, Style style = Style::native);
119 
123 reverse_iterator rend(StringRef path);
124 
128 
139 void remove_filename(SmallVectorImpl<char> &path, Style style = Style::native);
140 
153 void replace_extension(SmallVectorImpl<char> &path, const Twine &extension,
154  Style style = Style::native);
155 
169 void replace_path_prefix(SmallVectorImpl<char> &Path,
170  const StringRef &OldPrefix, const StringRef &NewPrefix,
171  Style style = Style::native);
172 
183 void append(SmallVectorImpl<char> &path, const Twine &a,
184  const Twine &b = "",
185  const Twine &c = "",
186  const Twine &d = "");
187 
188 void append(SmallVectorImpl<char> &path, Style style, const Twine &a,
189  const Twine &b = "", const Twine &c = "", const Twine &d = "");
190 
202 void append(SmallVectorImpl<char> &path, const_iterator begin,
203  const_iterator end, Style style = Style::native);
204 
208 
215 void native(const Twine &path, SmallVectorImpl<char> &result,
216  Style style = Style::native);
217 
223 void native(SmallVectorImpl<char> &path, Style style = Style::native);
224 
231 std::string convert_to_slash(StringRef path, Style style = Style::native);
232 
236 
247 StringRef root_name(StringRef path, Style style = Style::native);
248 
260 StringRef root_directory(StringRef path, Style style = Style::native);
261 
268 StringRef root_path(StringRef path, Style style = Style::native);
269 
280 StringRef relative_path(StringRef path, Style style = Style::native);
281 
292 StringRef parent_path(StringRef path, Style style = Style::native);
293 
306 StringRef filename(StringRef path, Style style = Style::native);
307 
324 StringRef stem(StringRef path, Style style = Style::native);
325 
340 StringRef extension(StringRef path, Style style = Style::native);
341 
346 bool is_separator(char value, Style style = Style::native);
347 
351 StringRef get_separator(Style style = Style::native);
352 
362 void system_temp_directory(bool erasedOnReboot, SmallVectorImpl<char> &result);
363 
368 bool home_directory(SmallVectorImpl<char> &result);
369 
376 bool has_root_name(const Twine &path, Style style = Style::native);
377 
384 bool has_root_directory(const Twine &path, Style style = Style::native);
385 
392 bool has_root_path(const Twine &path, Style style = Style::native);
393 
400 bool has_relative_path(const Twine &path, Style style = Style::native);
401 
408 bool has_parent_path(const Twine &path, Style style = Style::native);
409 
416 bool has_filename(const Twine &path, Style style = Style::native);
417 
424 bool has_stem(const Twine &path, Style style = Style::native);
425 
432 bool has_extension(const Twine &path, Style style = Style::native);
433 
438 bool is_absolute(const Twine &path, Style style = Style::native);
439 
444 bool is_relative(const Twine &path, Style style = Style::native);
445 
450 StringRef remove_leading_dotslash(StringRef path, Style style = Style::native);
451 
458 bool remove_dots(SmallVectorImpl<char> &path, bool remove_dot_dot = false,
459  Style style = Style::native);
460 
461 #if defined(_WIN32)
462 std::error_code widenPath(const Twine &Path8, SmallVectorImpl<wchar_t> &Path16);
463 #endif
464 
465 } // end namespace path
466 } // end namespace sys
467 } // end namespace wpi
468 
469 #ifdef _WIN32
470 #pragma warning(pop)
471 #endif
472 
473 #endif
wpi::sys::path::reverse_iterator::rend
friend reverse_iterator rend(StringRef path)
Get reverse end iterator over path.
wpi::sys::path::reverse_iterator
Reverse path iterator.
Definition: Path.h:85
wpi::sys::path::reverse_iterator::rbegin
friend reverse_iterator rbegin(StringRef path, Style style)
Get reverse begin iterator over path.
wpi::SmallVectorImpl< char >
wpi::sys::path::const_iterator
Path iterator.
Definition: Path.h:59
wpi::sys::path::const_iterator::end
friend const_iterator end(StringRef path)
Get end iterator over path.
wpi
WPILib C++ utilities (wpiutil) namespace.
Definition: EventLoopRunner.h:17
wpi::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
wpi::sys::path::reverse_iterator::operator-
ptrdiff_t operator-(const reverse_iterator &RHS) const
Difference in bytes between this and RHS.
wpi::iterator_facade_base
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition: iterator.h:68
wpi::sys::path::const_iterator::begin
friend const_iterator begin(StringRef path, Style style)
Get begin iterator over path.
wpi::sys::path::const_iterator::operator-
ptrdiff_t operator-(const const_iterator &RHS) const
Difference in bytes between this and RHS.
wpi::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:85