TildeExpressionResolver.h revision 317027
1//===--------------------- TildeExpressionResolver.h ------------*- 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#ifndef LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H
11#define LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H
12
13#include "llvm/ADT/StringRef.h"
14#include "llvm/ADT/StringSet.h"
15
16namespace llvm {
17template <typename T> class SmallVectorImpl;
18}
19
20namespace lldb_private {
21class TildeExpressionResolver {
22public:
23  virtual ~TildeExpressionResolver();
24
25  /// \brief Resolve a Tilde Expression contained according to bash rules.
26  ///
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.
30  ///
31  /// \param Output Contains the resolved tilde expression, or the original
32  ///               input if the tilde expression could not be resolved.
33  ///
34  /// \returns true if \p Expr was successfully resolved, false otherwise.
35  virtual bool ResolveExact(llvm::StringRef Expr,
36                            llvm::SmallVectorImpl<char> &Output) = 0;
37
38  /// \brief Auto-complete a tilde expression with all matching values.
39  ///
40  /// \param Expr Contains the tilde expression prefix to resolve.  See
41  ///             ResolveExact() for validity rules.
42  ///
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).
46  ///
47  /// \returns true if there were any matches, false otherwise.
48  virtual bool ResolvePartial(llvm::StringRef Expr,
49                              llvm::StringSet<> &Output) = 0;
50
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);
55};
56
57class StandardTildeExpressionResolver : public TildeExpressionResolver {
58public:
59  bool ResolveExact(llvm::StringRef Expr,
60                    llvm::SmallVectorImpl<char> &Output) override;
61  bool ResolvePartial(llvm::StringRef Expr, llvm::StringSet<> &Output) override;
62};
63}
64
65#endif // #ifndef LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H
66