reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
//===--------------------- TildeExpressionResolver.h ------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H
#define LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H

#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"

namespace llvm {
template <typename T> class SmallVectorImpl;
}

namespace lldb_private {
class TildeExpressionResolver {
public:
  virtual ~TildeExpressionResolver();

  /// Resolve a Tilde Expression contained according to bash rules.
  ///
  /// \param Expr Contains the tilde expression to resolve.  A valid tilde
  ///             expression must begin with a tilde and contain only non
  ///             separator characters.
  ///
  /// \param Output Contains the resolved tilde expression, or the original
  ///               input if the tilde expression could not be resolved.
  ///
  /// \returns true if \p Expr was successfully resolved, false otherwise.
  virtual bool ResolveExact(llvm::StringRef Expr,
                            llvm::SmallVectorImpl<char> &Output) = 0;

  /// Auto-complete a tilde expression with all matching values.
  ///
  /// \param Expr Contains the tilde expression prefix to resolve.  See
  ///             ResolveExact() for validity rules.
  ///
  /// \param Output Contains all matching home directories, each one
  ///               itself unresolved (i.e. you need to call ResolveExact
  ///               on each item to turn it into a real path).
  ///
  /// \returns true if there were any matches, false otherwise.
  virtual bool ResolvePartial(llvm::StringRef Expr,
                              llvm::StringSet<> &Output) = 0;

  /// Resolve an entire path that begins with a tilde expression, replacing
  /// the username portion with the matched result.
  bool ResolveFullPath(llvm::StringRef Expr,
                       llvm::SmallVectorImpl<char> &Output);
};

class StandardTildeExpressionResolver : public TildeExpressionResolver {
public:
  bool ResolveExact(llvm::StringRef Expr,
                    llvm::SmallVectorImpl<char> &Output) override;
  bool ResolvePartial(llvm::StringRef Expr, llvm::StringSet<> &Output) override;
};
}

#endif // #ifndef LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H