WPILibC++  2019.2.1-2-gfdf298b
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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 
24 namespace wpi {
25 namespace sys {
26 namespace path {
27 
28 enum class Style { windows, posix, native };
29 
32 
53  : public iterator_facade_base<const_iterator, std::input_iterator_tag,
54  const StringRef> {
55  StringRef Path;
56  StringRef Component;
57  size_t Position;
58  Style S;
59 
60  // An end iterator has Position = Path.size() + 1.
61  friend const_iterator begin(StringRef path, Style style);
62  friend const_iterator end(StringRef path);
63 
64 public:
65  reference operator*() const { return Component; }
66  const_iterator &operator++(); // preincrement
67  bool operator==(const const_iterator &RHS) const;
68 
70  ptrdiff_t operator-(const const_iterator &RHS) const;
71 };
72 
79  : public iterator_facade_base<reverse_iterator, std::input_iterator_tag,
80  const StringRef> {
81  StringRef Path;
82  StringRef Component;
83  size_t Position;
84  Style S;
85 
86  friend reverse_iterator rbegin(StringRef path, Style style);
87  friend reverse_iterator rend(StringRef path);
88 
89 public:
90  reference operator*() const { return Component; }
91  reverse_iterator &operator++(); // preincrement
92  bool operator==(const reverse_iterator &RHS) const;
93 
95  ptrdiff_t operator-(const reverse_iterator &RHS) const;
96 };
97 
101 const_iterator begin(StringRef path, Style style = Style::native);
102 
106 const_iterator end(StringRef path);
107 
111 reverse_iterator rbegin(StringRef path, Style style = Style::native);
112 
116 reverse_iterator rend(StringRef path);
117 
121 
132 void remove_filename(SmallVectorImpl<char> &path, Style style = Style::native);
133 
146 void replace_extension(SmallVectorImpl<char> &path, const Twine &extension,
147  Style style = Style::native);
148 
162 void replace_path_prefix(SmallVectorImpl<char> &Path,
163  const StringRef &OldPrefix, const StringRef &NewPrefix,
164  Style style = Style::native);
165 
176 void append(SmallVectorImpl<char> &path, const Twine &a,
177  const Twine &b = "",
178  const Twine &c = "",
179  const Twine &d = "");
180 
181 void append(SmallVectorImpl<char> &path, Style style, const Twine &a,
182  const Twine &b = "", const Twine &c = "", const Twine &d = "");
183 
195 void append(SmallVectorImpl<char> &path, const_iterator begin,
196  const_iterator end, Style style = Style::native);
197 
201 
208 void native(const Twine &path, SmallVectorImpl<char> &result,
209  Style style = Style::native);
210 
216 void native(SmallVectorImpl<char> &path, Style style = Style::native);
217 
224 std::string convert_to_slash(StringRef path, Style style = Style::native);
225 
229 
240 StringRef root_name(StringRef path, Style style = Style::native);
241 
253 StringRef root_directory(StringRef path, Style style = Style::native);
254 
261 StringRef root_path(StringRef path, Style style = Style::native);
262 
273 StringRef relative_path(StringRef path, Style style = Style::native);
274 
285 StringRef parent_path(StringRef path, Style style = Style::native);
286 
299 StringRef filename(StringRef path, Style style = Style::native);
300 
317 StringRef stem(StringRef path, Style style = Style::native);
318 
333 StringRef extension(StringRef path, Style style = Style::native);
334 
339 bool is_separator(char value, Style style = Style::native);
340 
344 StringRef get_separator(Style style = Style::native);
345 
355 void system_temp_directory(bool erasedOnReboot, SmallVectorImpl<char> &result);
356 
361 bool home_directory(SmallVectorImpl<char> &result);
362 
376 bool user_cache_directory(SmallVectorImpl<char> &Result, const Twine &Path1,
377  const Twine &Path2 = "", const Twine &Path3 = "");
378 
385 bool has_root_name(const Twine &path, Style style = Style::native);
386 
393 bool has_root_directory(const Twine &path, Style style = Style::native);
394 
401 bool has_root_path(const Twine &path, Style style = Style::native);
402 
409 bool has_relative_path(const Twine &path, Style style = Style::native);
410 
417 bool has_parent_path(const Twine &path, Style style = Style::native);
418 
425 bool has_filename(const Twine &path, Style style = Style::native);
426 
433 bool has_stem(const Twine &path, Style style = Style::native);
434 
441 bool has_extension(const Twine &path, Style style = Style::native);
442 
447 bool is_absolute(const Twine &path, Style style = Style::native);
448 
453 bool is_relative(const Twine &path, Style style = Style::native);
454 
459 StringRef remove_leading_dotslash(StringRef path, Style style = Style::native);
460 
467 bool remove_dots(SmallVectorImpl<char> &path, bool remove_dot_dot = false,
468  Style style = Style::native);
469 
470 } // end namespace path
471 } // end namespace sys
472 } // end namespace wpi
473 
474 #endif
friend reverse_iterator rbegin(StringRef path, Style style)
Get reverse begin iterator over path.
ptrdiff_t operator-(const const_iterator &RHS) const
Difference in bytes between this and RHS.
friend reverse_iterator rend(StringRef path)
Get reverse end iterator over path.
Reverse path iterator.
Definition: Path.h:78
WPILib C++ utilities (wpiutil) namespace.
Definition: SmallString.h:21
friend const_iterator end(StringRef path)
Get end iterator over path.
Path iterator.
Definition: Path.h:52
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition: iterator.h:68
friend const_iterator begin(StringRef path, Style style)
Get begin iterator over path.
ptrdiff_t operator-(const reverse_iterator &RHS) const
Difference in bytes between this and RHS.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79