xref: /aosp_15_r20/external/llvm/include/llvm/Support/Path.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===- llvm/Support/Path.h - Path Operating System Concept ------*- C++ -*-===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file declares the llvm::sys::path namespace. It is designed after
11*9880d681SAndroid Build Coastguard Worker // TR2/boost filesystem (v3), but modified to remove exception handling and the
12*9880d681SAndroid Build Coastguard Worker // path class.
13*9880d681SAndroid Build Coastguard Worker //
14*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
15*9880d681SAndroid Build Coastguard Worker 
16*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_SUPPORT_PATH_H
17*9880d681SAndroid Build Coastguard Worker #define LLVM_SUPPORT_PATH_H
18*9880d681SAndroid Build Coastguard Worker 
19*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/Twine.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/DataTypes.h"
21*9880d681SAndroid Build Coastguard Worker #include <iterator>
22*9880d681SAndroid Build Coastguard Worker 
23*9880d681SAndroid Build Coastguard Worker namespace llvm {
24*9880d681SAndroid Build Coastguard Worker namespace sys {
25*9880d681SAndroid Build Coastguard Worker namespace path {
26*9880d681SAndroid Build Coastguard Worker 
27*9880d681SAndroid Build Coastguard Worker /// @name Lexical Component Iterator
28*9880d681SAndroid Build Coastguard Worker /// @{
29*9880d681SAndroid Build Coastguard Worker 
30*9880d681SAndroid Build Coastguard Worker /// @brief Path iterator.
31*9880d681SAndroid Build Coastguard Worker ///
32*9880d681SAndroid Build Coastguard Worker /// This is an input iterator that iterates over the individual components in
33*9880d681SAndroid Build Coastguard Worker /// \a path. The traversal order is as follows:
34*9880d681SAndroid Build Coastguard Worker /// * The root-name element, if present.
35*9880d681SAndroid Build Coastguard Worker /// * The root-directory element, if present.
36*9880d681SAndroid Build Coastguard Worker /// * Each successive filename element, if present.
37*9880d681SAndroid Build Coastguard Worker /// * Dot, if one or more trailing non-root slash characters are present.
38*9880d681SAndroid Build Coastguard Worker /// Traversing backwards is possible with \a reverse_iterator
39*9880d681SAndroid Build Coastguard Worker ///
40*9880d681SAndroid Build Coastguard Worker /// Iteration examples. Each component is separated by ',':
41*9880d681SAndroid Build Coastguard Worker /// @code
42*9880d681SAndroid Build Coastguard Worker ///   /          => /
43*9880d681SAndroid Build Coastguard Worker ///   /foo       => /,foo
44*9880d681SAndroid Build Coastguard Worker ///   foo/       => foo,.
45*9880d681SAndroid Build Coastguard Worker ///   /foo/bar   => /,foo,bar
46*9880d681SAndroid Build Coastguard Worker ///   ../        => ..,.
47*9880d681SAndroid Build Coastguard Worker ///   C:\foo\bar => C:,/,foo,bar
48*9880d681SAndroid Build Coastguard Worker /// @endcode
49*9880d681SAndroid Build Coastguard Worker class const_iterator
50*9880d681SAndroid Build Coastguard Worker     : public std::iterator<std::input_iterator_tag, const StringRef> {
51*9880d681SAndroid Build Coastguard Worker   StringRef Path;      ///< The entire path.
52*9880d681SAndroid Build Coastguard Worker   StringRef Component; ///< The current component. Not necessarily in Path.
53*9880d681SAndroid Build Coastguard Worker   size_t    Position;  ///< The iterators current position within Path.
54*9880d681SAndroid Build Coastguard Worker 
55*9880d681SAndroid Build Coastguard Worker   // An end iterator has Position = Path.size() + 1.
56*9880d681SAndroid Build Coastguard Worker   friend const_iterator begin(StringRef path);
57*9880d681SAndroid Build Coastguard Worker   friend const_iterator end(StringRef path);
58*9880d681SAndroid Build Coastguard Worker 
59*9880d681SAndroid Build Coastguard Worker public:
60*9880d681SAndroid Build Coastguard Worker   reference operator*() const { return Component; }
61*9880d681SAndroid Build Coastguard Worker   pointer   operator->() const { return &Component; }
62*9880d681SAndroid Build Coastguard Worker   const_iterator &operator++();    // preincrement
63*9880d681SAndroid Build Coastguard Worker   bool operator==(const const_iterator &RHS) const;
64*9880d681SAndroid Build Coastguard Worker   bool operator!=(const const_iterator &RHS) const { return !(*this == RHS); }
65*9880d681SAndroid Build Coastguard Worker 
66*9880d681SAndroid Build Coastguard Worker   /// @brief Difference in bytes between this and RHS.
67*9880d681SAndroid Build Coastguard Worker   ptrdiff_t operator-(const const_iterator &RHS) const;
68*9880d681SAndroid Build Coastguard Worker };
69*9880d681SAndroid Build Coastguard Worker 
70*9880d681SAndroid Build Coastguard Worker /// @brief Reverse path iterator.
71*9880d681SAndroid Build Coastguard Worker ///
72*9880d681SAndroid Build Coastguard Worker /// This is an input iterator that iterates over the individual components in
73*9880d681SAndroid Build Coastguard Worker /// \a path in reverse order. The traversal order is exactly reversed from that
74*9880d681SAndroid Build Coastguard Worker /// of \a const_iterator
75*9880d681SAndroid Build Coastguard Worker class reverse_iterator
76*9880d681SAndroid Build Coastguard Worker     : public std::iterator<std::input_iterator_tag, const StringRef> {
77*9880d681SAndroid Build Coastguard Worker   StringRef Path;      ///< The entire path.
78*9880d681SAndroid Build Coastguard Worker   StringRef Component; ///< The current component. Not necessarily in Path.
79*9880d681SAndroid Build Coastguard Worker   size_t    Position;  ///< The iterators current position within Path.
80*9880d681SAndroid Build Coastguard Worker 
81*9880d681SAndroid Build Coastguard Worker   friend reverse_iterator rbegin(StringRef path);
82*9880d681SAndroid Build Coastguard Worker   friend reverse_iterator rend(StringRef path);
83*9880d681SAndroid Build Coastguard Worker 
84*9880d681SAndroid Build Coastguard Worker public:
85*9880d681SAndroid Build Coastguard Worker   reference operator*() const { return Component; }
86*9880d681SAndroid Build Coastguard Worker   pointer   operator->() const { return &Component; }
87*9880d681SAndroid Build Coastguard Worker   reverse_iterator &operator++();    // preincrement
88*9880d681SAndroid Build Coastguard Worker   bool operator==(const reverse_iterator &RHS) const;
89*9880d681SAndroid Build Coastguard Worker   bool operator!=(const reverse_iterator &RHS) const { return !(*this == RHS); }
90*9880d681SAndroid Build Coastguard Worker 
91*9880d681SAndroid Build Coastguard Worker   /// @brief Difference in bytes between this and RHS.
92*9880d681SAndroid Build Coastguard Worker   ptrdiff_t operator-(const reverse_iterator &RHS) const;
93*9880d681SAndroid Build Coastguard Worker };
94*9880d681SAndroid Build Coastguard Worker 
95*9880d681SAndroid Build Coastguard Worker /// @brief Get begin iterator over \a path.
96*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
97*9880d681SAndroid Build Coastguard Worker /// @returns Iterator initialized with the first component of \a path.
98*9880d681SAndroid Build Coastguard Worker const_iterator begin(StringRef path);
99*9880d681SAndroid Build Coastguard Worker 
100*9880d681SAndroid Build Coastguard Worker /// @brief Get end iterator over \a path.
101*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
102*9880d681SAndroid Build Coastguard Worker /// @returns Iterator initialized to the end of \a path.
103*9880d681SAndroid Build Coastguard Worker const_iterator end(StringRef path);
104*9880d681SAndroid Build Coastguard Worker 
105*9880d681SAndroid Build Coastguard Worker /// @brief Get reverse begin iterator over \a path.
106*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
107*9880d681SAndroid Build Coastguard Worker /// @returns Iterator initialized with the first reverse component of \a path.
108*9880d681SAndroid Build Coastguard Worker reverse_iterator rbegin(StringRef path);
109*9880d681SAndroid Build Coastguard Worker 
110*9880d681SAndroid Build Coastguard Worker /// @brief Get reverse end iterator over \a path.
111*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
112*9880d681SAndroid Build Coastguard Worker /// @returns Iterator initialized to the reverse end of \a path.
113*9880d681SAndroid Build Coastguard Worker reverse_iterator rend(StringRef path);
114*9880d681SAndroid Build Coastguard Worker 
115*9880d681SAndroid Build Coastguard Worker /// @}
116*9880d681SAndroid Build Coastguard Worker /// @name Lexical Modifiers
117*9880d681SAndroid Build Coastguard Worker /// @{
118*9880d681SAndroid Build Coastguard Worker 
119*9880d681SAndroid Build Coastguard Worker /// @brief Remove the last component from \a path unless it is the root dir.
120*9880d681SAndroid Build Coastguard Worker ///
121*9880d681SAndroid Build Coastguard Worker /// @code
122*9880d681SAndroid Build Coastguard Worker ///   directory/filename.cpp => directory/
123*9880d681SAndroid Build Coastguard Worker ///   directory/             => directory
124*9880d681SAndroid Build Coastguard Worker ///   filename.cpp           => <empty>
125*9880d681SAndroid Build Coastguard Worker ///   /                      => /
126*9880d681SAndroid Build Coastguard Worker /// @endcode
127*9880d681SAndroid Build Coastguard Worker ///
128*9880d681SAndroid Build Coastguard Worker /// @param path A path that is modified to not have a file component.
129*9880d681SAndroid Build Coastguard Worker void remove_filename(SmallVectorImpl<char> &path);
130*9880d681SAndroid Build Coastguard Worker 
131*9880d681SAndroid Build Coastguard Worker /// @brief Replace the file extension of \a path with \a extension.
132*9880d681SAndroid Build Coastguard Worker ///
133*9880d681SAndroid Build Coastguard Worker /// @code
134*9880d681SAndroid Build Coastguard Worker ///   ./filename.cpp => ./filename.extension
135*9880d681SAndroid Build Coastguard Worker ///   ./filename     => ./filename.extension
136*9880d681SAndroid Build Coastguard Worker ///   ./             => ./.extension
137*9880d681SAndroid Build Coastguard Worker /// @endcode
138*9880d681SAndroid Build Coastguard Worker ///
139*9880d681SAndroid Build Coastguard Worker /// @param path A path that has its extension replaced with \a extension.
140*9880d681SAndroid Build Coastguard Worker /// @param extension The extension to be added. It may be empty. It may also
141*9880d681SAndroid Build Coastguard Worker ///                  optionally start with a '.', if it does not, one will be
142*9880d681SAndroid Build Coastguard Worker ///                  prepended.
143*9880d681SAndroid Build Coastguard Worker void replace_extension(SmallVectorImpl<char> &path, const Twine &extension);
144*9880d681SAndroid Build Coastguard Worker 
145*9880d681SAndroid Build Coastguard Worker /// @brief Replace matching path prefix with another path.
146*9880d681SAndroid Build Coastguard Worker ///
147*9880d681SAndroid Build Coastguard Worker /// @code
148*9880d681SAndroid Build Coastguard Worker ///   /foo, /old, /new => /foo
149*9880d681SAndroid Build Coastguard Worker ///   /old/foo, /old, /new => /new/foo
150*9880d681SAndroid Build Coastguard Worker ///   /foo, <empty>, /new => /new/foo
151*9880d681SAndroid Build Coastguard Worker ///   /old/foo, /old, <empty> => /foo
152*9880d681SAndroid Build Coastguard Worker /// @endcode
153*9880d681SAndroid Build Coastguard Worker ///
154*9880d681SAndroid Build Coastguard Worker /// @param Path If \a Path starts with \a OldPrefix modify to instead
155*9880d681SAndroid Build Coastguard Worker ///        start with \a NewPrefix.
156*9880d681SAndroid Build Coastguard Worker /// @param OldPrefix The path prefix to strip from \a Path.
157*9880d681SAndroid Build Coastguard Worker /// @param NewPrefix The path prefix to replace \a NewPrefix with.
158*9880d681SAndroid Build Coastguard Worker void replace_path_prefix(SmallVectorImpl<char> &Path,
159*9880d681SAndroid Build Coastguard Worker                          const StringRef &OldPrefix,
160*9880d681SAndroid Build Coastguard Worker                          const StringRef &NewPrefix);
161*9880d681SAndroid Build Coastguard Worker 
162*9880d681SAndroid Build Coastguard Worker /// @brief Append to path.
163*9880d681SAndroid Build Coastguard Worker ///
164*9880d681SAndroid Build Coastguard Worker /// @code
165*9880d681SAndroid Build Coastguard Worker ///   /foo  + bar/f => /foo/bar/f
166*9880d681SAndroid Build Coastguard Worker ///   /foo/ + bar/f => /foo/bar/f
167*9880d681SAndroid Build Coastguard Worker ///   foo   + bar/f => foo/bar/f
168*9880d681SAndroid Build Coastguard Worker /// @endcode
169*9880d681SAndroid Build Coastguard Worker ///
170*9880d681SAndroid Build Coastguard Worker /// @param path Set to \a path + \a component.
171*9880d681SAndroid Build Coastguard Worker /// @param a The component to be appended to \a path.
172*9880d681SAndroid Build Coastguard Worker void append(SmallVectorImpl<char> &path, const Twine &a,
173*9880d681SAndroid Build Coastguard Worker                                          const Twine &b = "",
174*9880d681SAndroid Build Coastguard Worker                                          const Twine &c = "",
175*9880d681SAndroid Build Coastguard Worker                                          const Twine &d = "");
176*9880d681SAndroid Build Coastguard Worker 
177*9880d681SAndroid Build Coastguard Worker /// @brief Append to path.
178*9880d681SAndroid Build Coastguard Worker ///
179*9880d681SAndroid Build Coastguard Worker /// @code
180*9880d681SAndroid Build Coastguard Worker ///   /foo  + [bar,f] => /foo/bar/f
181*9880d681SAndroid Build Coastguard Worker ///   /foo/ + [bar,f] => /foo/bar/f
182*9880d681SAndroid Build Coastguard Worker ///   foo   + [bar,f] => foo/bar/f
183*9880d681SAndroid Build Coastguard Worker /// @endcode
184*9880d681SAndroid Build Coastguard Worker ///
185*9880d681SAndroid Build Coastguard Worker /// @param path Set to \a path + [\a begin, \a end).
186*9880d681SAndroid Build Coastguard Worker /// @param begin Start of components to append.
187*9880d681SAndroid Build Coastguard Worker /// @param end One past the end of components to append.
188*9880d681SAndroid Build Coastguard Worker void append(SmallVectorImpl<char> &path,
189*9880d681SAndroid Build Coastguard Worker             const_iterator begin, const_iterator end);
190*9880d681SAndroid Build Coastguard Worker 
191*9880d681SAndroid Build Coastguard Worker /// @}
192*9880d681SAndroid Build Coastguard Worker /// @name Transforms (or some other better name)
193*9880d681SAndroid Build Coastguard Worker /// @{
194*9880d681SAndroid Build Coastguard Worker 
195*9880d681SAndroid Build Coastguard Worker /// Convert path to the native form. This is used to give paths to users and
196*9880d681SAndroid Build Coastguard Worker /// operating system calls in the platform's normal way. For example, on Windows
197*9880d681SAndroid Build Coastguard Worker /// all '/' are converted to '\'.
198*9880d681SAndroid Build Coastguard Worker ///
199*9880d681SAndroid Build Coastguard Worker /// @param path A path that is transformed to native format.
200*9880d681SAndroid Build Coastguard Worker /// @param result Holds the result of the transformation.
201*9880d681SAndroid Build Coastguard Worker void native(const Twine &path, SmallVectorImpl<char> &result);
202*9880d681SAndroid Build Coastguard Worker 
203*9880d681SAndroid Build Coastguard Worker /// Convert path to the native form in place. This is used to give paths to
204*9880d681SAndroid Build Coastguard Worker /// users and operating system calls in the platform's normal way. For example,
205*9880d681SAndroid Build Coastguard Worker /// on Windows all '/' are converted to '\'.
206*9880d681SAndroid Build Coastguard Worker ///
207*9880d681SAndroid Build Coastguard Worker /// @param path A path that is transformed to native format.
208*9880d681SAndroid Build Coastguard Worker void native(SmallVectorImpl<char> &path);
209*9880d681SAndroid Build Coastguard Worker 
210*9880d681SAndroid Build Coastguard Worker /// @}
211*9880d681SAndroid Build Coastguard Worker /// @name Lexical Observers
212*9880d681SAndroid Build Coastguard Worker /// @{
213*9880d681SAndroid Build Coastguard Worker 
214*9880d681SAndroid Build Coastguard Worker /// @brief Get root name.
215*9880d681SAndroid Build Coastguard Worker ///
216*9880d681SAndroid Build Coastguard Worker /// @code
217*9880d681SAndroid Build Coastguard Worker ///   //net/hello => //net
218*9880d681SAndroid Build Coastguard Worker ///   c:/hello    => c: (on Windows, on other platforms nothing)
219*9880d681SAndroid Build Coastguard Worker ///   /hello      => <empty>
220*9880d681SAndroid Build Coastguard Worker /// @endcode
221*9880d681SAndroid Build Coastguard Worker ///
222*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
223*9880d681SAndroid Build Coastguard Worker /// @result The root name of \a path if it has one, otherwise "".
224*9880d681SAndroid Build Coastguard Worker StringRef root_name(StringRef path);
225*9880d681SAndroid Build Coastguard Worker 
226*9880d681SAndroid Build Coastguard Worker /// @brief Get root directory.
227*9880d681SAndroid Build Coastguard Worker ///
228*9880d681SAndroid Build Coastguard Worker /// @code
229*9880d681SAndroid Build Coastguard Worker ///   /goo/hello => /
230*9880d681SAndroid Build Coastguard Worker ///   c:/hello   => /
231*9880d681SAndroid Build Coastguard Worker ///   d/file.txt => <empty>
232*9880d681SAndroid Build Coastguard Worker /// @endcode
233*9880d681SAndroid Build Coastguard Worker ///
234*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
235*9880d681SAndroid Build Coastguard Worker /// @result The root directory of \a path if it has one, otherwise
236*9880d681SAndroid Build Coastguard Worker ///               "".
237*9880d681SAndroid Build Coastguard Worker StringRef root_directory(StringRef path);
238*9880d681SAndroid Build Coastguard Worker 
239*9880d681SAndroid Build Coastguard Worker /// @brief Get root path.
240*9880d681SAndroid Build Coastguard Worker ///
241*9880d681SAndroid Build Coastguard Worker /// Equivalent to root_name + root_directory.
242*9880d681SAndroid Build Coastguard Worker ///
243*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
244*9880d681SAndroid Build Coastguard Worker /// @result The root path of \a path if it has one, otherwise "".
245*9880d681SAndroid Build Coastguard Worker StringRef root_path(StringRef path);
246*9880d681SAndroid Build Coastguard Worker 
247*9880d681SAndroid Build Coastguard Worker /// @brief Get relative path.
248*9880d681SAndroid Build Coastguard Worker ///
249*9880d681SAndroid Build Coastguard Worker /// @code
250*9880d681SAndroid Build Coastguard Worker ///   C:\hello\world => hello\world
251*9880d681SAndroid Build Coastguard Worker ///   foo/bar        => foo/bar
252*9880d681SAndroid Build Coastguard Worker ///   /foo/bar       => foo/bar
253*9880d681SAndroid Build Coastguard Worker /// @endcode
254*9880d681SAndroid Build Coastguard Worker ///
255*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
256*9880d681SAndroid Build Coastguard Worker /// @result The path starting after root_path if one exists, otherwise "".
257*9880d681SAndroid Build Coastguard Worker StringRef relative_path(StringRef path);
258*9880d681SAndroid Build Coastguard Worker 
259*9880d681SAndroid Build Coastguard Worker /// @brief Get parent path.
260*9880d681SAndroid Build Coastguard Worker ///
261*9880d681SAndroid Build Coastguard Worker /// @code
262*9880d681SAndroid Build Coastguard Worker ///   /          => <empty>
263*9880d681SAndroid Build Coastguard Worker ///   /foo       => /
264*9880d681SAndroid Build Coastguard Worker ///   foo/../bar => foo/..
265*9880d681SAndroid Build Coastguard Worker /// @endcode
266*9880d681SAndroid Build Coastguard Worker ///
267*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
268*9880d681SAndroid Build Coastguard Worker /// @result The parent path of \a path if one exists, otherwise "".
269*9880d681SAndroid Build Coastguard Worker StringRef parent_path(StringRef path);
270*9880d681SAndroid Build Coastguard Worker 
271*9880d681SAndroid Build Coastguard Worker /// @brief Get filename.
272*9880d681SAndroid Build Coastguard Worker ///
273*9880d681SAndroid Build Coastguard Worker /// @code
274*9880d681SAndroid Build Coastguard Worker ///   /foo.txt    => foo.txt
275*9880d681SAndroid Build Coastguard Worker ///   .          => .
276*9880d681SAndroid Build Coastguard Worker ///   ..         => ..
277*9880d681SAndroid Build Coastguard Worker ///   /          => /
278*9880d681SAndroid Build Coastguard Worker /// @endcode
279*9880d681SAndroid Build Coastguard Worker ///
280*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
281*9880d681SAndroid Build Coastguard Worker /// @result The filename part of \a path. This is defined as the last component
282*9880d681SAndroid Build Coastguard Worker ///         of \a path.
283*9880d681SAndroid Build Coastguard Worker StringRef filename(StringRef path);
284*9880d681SAndroid Build Coastguard Worker 
285*9880d681SAndroid Build Coastguard Worker /// @brief Get stem.
286*9880d681SAndroid Build Coastguard Worker ///
287*9880d681SAndroid Build Coastguard Worker /// If filename contains a dot but not solely one or two dots, result is the
288*9880d681SAndroid Build Coastguard Worker /// substring of filename ending at (but not including) the last dot. Otherwise
289*9880d681SAndroid Build Coastguard Worker /// it is filename.
290*9880d681SAndroid Build Coastguard Worker ///
291*9880d681SAndroid Build Coastguard Worker /// @code
292*9880d681SAndroid Build Coastguard Worker ///   /foo/bar.txt => bar
293*9880d681SAndroid Build Coastguard Worker ///   /foo/bar     => bar
294*9880d681SAndroid Build Coastguard Worker ///   /foo/.txt    => <empty>
295*9880d681SAndroid Build Coastguard Worker ///   /foo/.       => .
296*9880d681SAndroid Build Coastguard Worker ///   /foo/..      => ..
297*9880d681SAndroid Build Coastguard Worker /// @endcode
298*9880d681SAndroid Build Coastguard Worker ///
299*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
300*9880d681SAndroid Build Coastguard Worker /// @result The stem of \a path.
301*9880d681SAndroid Build Coastguard Worker StringRef stem(StringRef path);
302*9880d681SAndroid Build Coastguard Worker 
303*9880d681SAndroid Build Coastguard Worker /// @brief Get extension.
304*9880d681SAndroid Build Coastguard Worker ///
305*9880d681SAndroid Build Coastguard Worker /// If filename contains a dot but not solely one or two dots, result is the
306*9880d681SAndroid Build Coastguard Worker /// substring of filename starting at (and including) the last dot, and ending
307*9880d681SAndroid Build Coastguard Worker /// at the end of \a path. Otherwise "".
308*9880d681SAndroid Build Coastguard Worker ///
309*9880d681SAndroid Build Coastguard Worker /// @code
310*9880d681SAndroid Build Coastguard Worker ///   /foo/bar.txt => .txt
311*9880d681SAndroid Build Coastguard Worker ///   /foo/bar     => <empty>
312*9880d681SAndroid Build Coastguard Worker ///   /foo/.txt    => .txt
313*9880d681SAndroid Build Coastguard Worker /// @endcode
314*9880d681SAndroid Build Coastguard Worker ///
315*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
316*9880d681SAndroid Build Coastguard Worker /// @result The extension of \a path.
317*9880d681SAndroid Build Coastguard Worker StringRef extension(StringRef path);
318*9880d681SAndroid Build Coastguard Worker 
319*9880d681SAndroid Build Coastguard Worker /// @brief Check whether the given char is a path separator on the host OS.
320*9880d681SAndroid Build Coastguard Worker ///
321*9880d681SAndroid Build Coastguard Worker /// @param value a character
322*9880d681SAndroid Build Coastguard Worker /// @result true if \a value is a path separator character on the host OS
323*9880d681SAndroid Build Coastguard Worker bool is_separator(char value);
324*9880d681SAndroid Build Coastguard Worker 
325*9880d681SAndroid Build Coastguard Worker /// @brief Return the preferred separator for this platform.
326*9880d681SAndroid Build Coastguard Worker ///
327*9880d681SAndroid Build Coastguard Worker /// @result StringRef of the preferred separator, null-terminated.
328*9880d681SAndroid Build Coastguard Worker StringRef get_separator();
329*9880d681SAndroid Build Coastguard Worker 
330*9880d681SAndroid Build Coastguard Worker /// @brief Get the typical temporary directory for the system, e.g.,
331*9880d681SAndroid Build Coastguard Worker /// "/var/tmp" or "C:/TEMP"
332*9880d681SAndroid Build Coastguard Worker ///
333*9880d681SAndroid Build Coastguard Worker /// @param erasedOnReboot Whether to favor a path that is erased on reboot
334*9880d681SAndroid Build Coastguard Worker /// rather than one that potentially persists longer. This parameter will be
335*9880d681SAndroid Build Coastguard Worker /// ignored if the user or system has set the typical environment variable
336*9880d681SAndroid Build Coastguard Worker /// (e.g., TEMP on Windows, TMPDIR on *nix) to specify a temporary directory.
337*9880d681SAndroid Build Coastguard Worker ///
338*9880d681SAndroid Build Coastguard Worker /// @param result Holds the resulting path name.
339*9880d681SAndroid Build Coastguard Worker void system_temp_directory(bool erasedOnReboot, SmallVectorImpl<char> &result);
340*9880d681SAndroid Build Coastguard Worker 
341*9880d681SAndroid Build Coastguard Worker /// @brief Get the user's home directory.
342*9880d681SAndroid Build Coastguard Worker ///
343*9880d681SAndroid Build Coastguard Worker /// @param result Holds the resulting path name.
344*9880d681SAndroid Build Coastguard Worker /// @result True if a home directory is set, false otherwise.
345*9880d681SAndroid Build Coastguard Worker bool home_directory(SmallVectorImpl<char> &result);
346*9880d681SAndroid Build Coastguard Worker 
347*9880d681SAndroid Build Coastguard Worker /// @brief Get the user's cache directory.
348*9880d681SAndroid Build Coastguard Worker ///
349*9880d681SAndroid Build Coastguard Worker /// Expect the resulting path to be a directory shared with other
350*9880d681SAndroid Build Coastguard Worker /// applications/services used by the user. Params \p Path1 to \p Path3 can be
351*9880d681SAndroid Build Coastguard Worker /// used to append additional directory names to the resulting path. Recommended
352*9880d681SAndroid Build Coastguard Worker /// pattern is <user_cache_directory>/<vendor>/<application>.
353*9880d681SAndroid Build Coastguard Worker ///
354*9880d681SAndroid Build Coastguard Worker /// @param Result Holds the resulting path.
355*9880d681SAndroid Build Coastguard Worker /// @param Path1 Additional path to be appended to the user's cache directory
356*9880d681SAndroid Build Coastguard Worker /// path. "" can be used to append nothing.
357*9880d681SAndroid Build Coastguard Worker /// @param Path2 Second additional path to be appended.
358*9880d681SAndroid Build Coastguard Worker /// @param Path3 Third additional path to be appended.
359*9880d681SAndroid Build Coastguard Worker /// @result True if a cache directory path is set, false otherwise.
360*9880d681SAndroid Build Coastguard Worker bool user_cache_directory(SmallVectorImpl<char> &Result, const Twine &Path1,
361*9880d681SAndroid Build Coastguard Worker                           const Twine &Path2 = "", const Twine &Path3 = "");
362*9880d681SAndroid Build Coastguard Worker 
363*9880d681SAndroid Build Coastguard Worker /// @brief Has root name?
364*9880d681SAndroid Build Coastguard Worker ///
365*9880d681SAndroid Build Coastguard Worker /// root_name != ""
366*9880d681SAndroid Build Coastguard Worker ///
367*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
368*9880d681SAndroid Build Coastguard Worker /// @result True if the path has a root name, false otherwise.
369*9880d681SAndroid Build Coastguard Worker bool has_root_name(const Twine &path);
370*9880d681SAndroid Build Coastguard Worker 
371*9880d681SAndroid Build Coastguard Worker /// @brief Has root directory?
372*9880d681SAndroid Build Coastguard Worker ///
373*9880d681SAndroid Build Coastguard Worker /// root_directory != ""
374*9880d681SAndroid Build Coastguard Worker ///
375*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
376*9880d681SAndroid Build Coastguard Worker /// @result True if the path has a root directory, false otherwise.
377*9880d681SAndroid Build Coastguard Worker bool has_root_directory(const Twine &path);
378*9880d681SAndroid Build Coastguard Worker 
379*9880d681SAndroid Build Coastguard Worker /// @brief Has root path?
380*9880d681SAndroid Build Coastguard Worker ///
381*9880d681SAndroid Build Coastguard Worker /// root_path != ""
382*9880d681SAndroid Build Coastguard Worker ///
383*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
384*9880d681SAndroid Build Coastguard Worker /// @result True if the path has a root path, false otherwise.
385*9880d681SAndroid Build Coastguard Worker bool has_root_path(const Twine &path);
386*9880d681SAndroid Build Coastguard Worker 
387*9880d681SAndroid Build Coastguard Worker /// @brief Has relative path?
388*9880d681SAndroid Build Coastguard Worker ///
389*9880d681SAndroid Build Coastguard Worker /// relative_path != ""
390*9880d681SAndroid Build Coastguard Worker ///
391*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
392*9880d681SAndroid Build Coastguard Worker /// @result True if the path has a relative path, false otherwise.
393*9880d681SAndroid Build Coastguard Worker bool has_relative_path(const Twine &path);
394*9880d681SAndroid Build Coastguard Worker 
395*9880d681SAndroid Build Coastguard Worker /// @brief Has parent path?
396*9880d681SAndroid Build Coastguard Worker ///
397*9880d681SAndroid Build Coastguard Worker /// parent_path != ""
398*9880d681SAndroid Build Coastguard Worker ///
399*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
400*9880d681SAndroid Build Coastguard Worker /// @result True if the path has a parent path, false otherwise.
401*9880d681SAndroid Build Coastguard Worker bool has_parent_path(const Twine &path);
402*9880d681SAndroid Build Coastguard Worker 
403*9880d681SAndroid Build Coastguard Worker /// @brief Has filename?
404*9880d681SAndroid Build Coastguard Worker ///
405*9880d681SAndroid Build Coastguard Worker /// filename != ""
406*9880d681SAndroid Build Coastguard Worker ///
407*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
408*9880d681SAndroid Build Coastguard Worker /// @result True if the path has a filename, false otherwise.
409*9880d681SAndroid Build Coastguard Worker bool has_filename(const Twine &path);
410*9880d681SAndroid Build Coastguard Worker 
411*9880d681SAndroid Build Coastguard Worker /// @brief Has stem?
412*9880d681SAndroid Build Coastguard Worker ///
413*9880d681SAndroid Build Coastguard Worker /// stem != ""
414*9880d681SAndroid Build Coastguard Worker ///
415*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
416*9880d681SAndroid Build Coastguard Worker /// @result True if the path has a stem, false otherwise.
417*9880d681SAndroid Build Coastguard Worker bool has_stem(const Twine &path);
418*9880d681SAndroid Build Coastguard Worker 
419*9880d681SAndroid Build Coastguard Worker /// @brief Has extension?
420*9880d681SAndroid Build Coastguard Worker ///
421*9880d681SAndroid Build Coastguard Worker /// extension != ""
422*9880d681SAndroid Build Coastguard Worker ///
423*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
424*9880d681SAndroid Build Coastguard Worker /// @result True if the path has a extension, false otherwise.
425*9880d681SAndroid Build Coastguard Worker bool has_extension(const Twine &path);
426*9880d681SAndroid Build Coastguard Worker 
427*9880d681SAndroid Build Coastguard Worker /// @brief Is path absolute?
428*9880d681SAndroid Build Coastguard Worker ///
429*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
430*9880d681SAndroid Build Coastguard Worker /// @result True if the path is absolute, false if it is not.
431*9880d681SAndroid Build Coastguard Worker bool is_absolute(const Twine &path);
432*9880d681SAndroid Build Coastguard Worker 
433*9880d681SAndroid Build Coastguard Worker /// @brief Is path relative?
434*9880d681SAndroid Build Coastguard Worker ///
435*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
436*9880d681SAndroid Build Coastguard Worker /// @result True if the path is relative, false if it is not.
437*9880d681SAndroid Build Coastguard Worker bool is_relative(const Twine &path);
438*9880d681SAndroid Build Coastguard Worker 
439*9880d681SAndroid Build Coastguard Worker /// @brief Remove redundant leading "./" pieces and consecutive separators.
440*9880d681SAndroid Build Coastguard Worker ///
441*9880d681SAndroid Build Coastguard Worker /// @param path Input path.
442*9880d681SAndroid Build Coastguard Worker /// @result The cleaned-up \a path.
443*9880d681SAndroid Build Coastguard Worker StringRef remove_leading_dotslash(StringRef path);
444*9880d681SAndroid Build Coastguard Worker 
445*9880d681SAndroid Build Coastguard Worker /// @brief In-place remove any './' and optionally '../' components from a path.
446*9880d681SAndroid Build Coastguard Worker ///
447*9880d681SAndroid Build Coastguard Worker /// @param path processed path
448*9880d681SAndroid Build Coastguard Worker /// @param remove_dot_dot specify if '../' should be removed
449*9880d681SAndroid Build Coastguard Worker /// @result True if path was changed
450*9880d681SAndroid Build Coastguard Worker bool remove_dots(SmallVectorImpl<char> &path, bool remove_dot_dot = false);
451*9880d681SAndroid Build Coastguard Worker 
452*9880d681SAndroid Build Coastguard Worker } // end namespace path
453*9880d681SAndroid Build Coastguard Worker } // end namespace sys
454*9880d681SAndroid Build Coastguard Worker } // end namespace llvm
455*9880d681SAndroid Build Coastguard Worker 
456*9880d681SAndroid Build Coastguard Worker #endif
457