1 //===--------------------- TildeExpressionResolver.h ------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H
11 #define LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/StringSet.h"
17 template <typename T> class SmallVectorImpl;
20 namespace lldb_private {
21 class TildeExpressionResolver {
23 virtual ~TildeExpressionResolver();
25 /// \brief Resolve a Tilde Expression contained according to bash rules.
27 /// \param Expr Contains the tilde expression to resolve. A valid tilde
28 /// expression must begin with a tilde and contain only non
29 /// separator characters.
31 /// \param Output Contains the resolved tilde expression, or the original
32 /// input if the tilde expression could not be resolved.
34 /// \returns true if \p Expr was successfully resolved, false otherwise.
35 virtual bool ResolveExact(llvm::StringRef Expr,
36 llvm::SmallVectorImpl<char> &Output) = 0;
38 /// \brief Auto-complete a tilde expression with all matching values.
40 /// \param Expr Contains the tilde expression prefix to resolve. See
41 /// ResolveExact() for validity rules.
43 /// \param Output Contains all matching home directories, each one
44 /// itself unresolved (i.e. you need to call ResolveExact
45 /// on each item to turn it into a real path).
47 /// \returns true if there were any matches, false otherwise.
48 virtual bool ResolvePartial(llvm::StringRef Expr,
49 llvm::StringSet<> &Output) = 0;
51 /// \brief Resolve an entire path that begins with a tilde expression,
52 /// replacing the username portion with the matched result.
53 bool ResolveFullPath(llvm::StringRef Expr,
54 llvm::SmallVectorImpl<char> &Output);
57 class StandardTildeExpressionResolver : public TildeExpressionResolver {
59 bool ResolveExact(llvm::StringRef Expr,
60 llvm::SmallVectorImpl<char> &Output) override;
61 bool ResolvePartial(llvm::StringRef Expr, llvm::StringSet<> &Output) override;
65 #endif // #ifndef LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H