1 | //===--------------------- TildeExpressionResolver.h ------------*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef LLDB_UTILITY_TILDEEXPRESSIONRESOLVER_H |
10 | #define LLDB_UTILITY_TILDEEXPRESSIONRESOLVER_H |
11 | |
12 | #include "llvm/ADT/StringRef.h" |
13 | #include "llvm/ADT/StringSet.h" |
14 | |
15 | namespace llvm { |
16 | template <typename T> class SmallVectorImpl; |
17 | } |
18 | |
19 | namespace lldb_private { |
20 | class TildeExpressionResolver { |
21 | public: |
22 | virtual ~TildeExpressionResolver(); |
23 | |
24 | /// Resolve a Tilde Expression contained according to bash rules. |
25 | /// |
26 | /// \param Expr Contains the tilde expression to resolve. A valid tilde |
27 | /// expression must begin with a tilde and contain only non |
28 | /// separator characters. |
29 | /// |
30 | /// \param Output Contains the resolved tilde expression, or the original |
31 | /// input if the tilde expression could not be resolved. |
32 | /// |
33 | /// \returns true if \p Expr was successfully resolved, false otherwise. |
34 | virtual bool ResolveExact(llvm::StringRef Expr, |
35 | llvm::SmallVectorImpl<char> &Output) = 0; |
36 | |
37 | /// Auto-complete a tilde expression with all matching values. |
38 | /// |
39 | /// \param Expr Contains the tilde expression prefix to resolve. See |
40 | /// ResolveExact() for validity rules. |
41 | /// |
42 | /// \param Output Contains all matching home directories, each one |
43 | /// itself unresolved (i.e. you need to call ResolveExact |
44 | /// on each item to turn it into a real path). |
45 | /// |
46 | /// \returns true if there were any matches, false otherwise. |
47 | virtual bool ResolvePartial(llvm::StringRef Expr, |
48 | llvm::StringSet<> &Output) = 0; |
49 | |
50 | /// Resolve an entire path that begins with a tilde expression, replacing |
51 | /// the username portion with the matched result. |
52 | bool ResolveFullPath(llvm::StringRef Expr, |
53 | llvm::SmallVectorImpl<char> &Output); |
54 | }; |
55 | |
56 | class StandardTildeExpressionResolver : public TildeExpressionResolver { |
57 | public: |
58 | bool ResolveExact(llvm::StringRef Expr, |
59 | llvm::SmallVectorImpl<char> &Output) override; |
60 | bool ResolvePartial(llvm::StringRef Expr, llvm::StringSet<> &Output) override; |
61 | }; |
62 | } |
63 | |
64 | #endif // LLDB_UTILITY_TILDEEXPRESSIONRESOLVER_H |
65 | |