1317027Sdim//===--------------------- TildeExpressionResolver.h ------------*- C++ -*-===// 2317027Sdim// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6317027Sdim// 7317027Sdim//===----------------------------------------------------------------------===// 8317027Sdim 9317027Sdim#ifndef LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H 10317027Sdim#define LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H 11317027Sdim 12317027Sdim#include "llvm/ADT/StringRef.h" 13317027Sdim#include "llvm/ADT/StringSet.h" 14317027Sdim 15317027Sdimnamespace llvm { 16317027Sdimtemplate <typename T> class SmallVectorImpl; 17317027Sdim} 18317027Sdim 19317027Sdimnamespace lldb_private { 20317027Sdimclass TildeExpressionResolver { 21317027Sdimpublic: 22317027Sdim virtual ~TildeExpressionResolver(); 23317027Sdim 24341825Sdim /// Resolve a Tilde Expression contained according to bash rules. 25317027Sdim /// 26317027Sdim /// \param Expr Contains the tilde expression to resolve. A valid tilde 27317027Sdim /// expression must begin with a tilde and contain only non 28317027Sdim /// separator characters. 29317027Sdim /// 30317027Sdim /// \param Output Contains the resolved tilde expression, or the original 31317027Sdim /// input if the tilde expression could not be resolved. 32317027Sdim /// 33317027Sdim /// \returns true if \p Expr was successfully resolved, false otherwise. 34317027Sdim virtual bool ResolveExact(llvm::StringRef Expr, 35317027Sdim llvm::SmallVectorImpl<char> &Output) = 0; 36317027Sdim 37341825Sdim /// Auto-complete a tilde expression with all matching values. 38317027Sdim /// 39317027Sdim /// \param Expr Contains the tilde expression prefix to resolve. See 40317027Sdim /// ResolveExact() for validity rules. 41317027Sdim /// 42317027Sdim /// \param Output Contains all matching home directories, each one 43317027Sdim /// itself unresolved (i.e. you need to call ResolveExact 44317027Sdim /// on each item to turn it into a real path). 45317027Sdim /// 46317027Sdim /// \returns true if there were any matches, false otherwise. 47317027Sdim virtual bool ResolvePartial(llvm::StringRef Expr, 48317027Sdim llvm::StringSet<> &Output) = 0; 49317027Sdim 50341825Sdim /// Resolve an entire path that begins with a tilde expression, replacing 51341825Sdim /// the username portion with the matched result. 52317027Sdim bool ResolveFullPath(llvm::StringRef Expr, 53317027Sdim llvm::SmallVectorImpl<char> &Output); 54317027Sdim}; 55317027Sdim 56317027Sdimclass StandardTildeExpressionResolver : public TildeExpressionResolver { 57317027Sdimpublic: 58317027Sdim bool ResolveExact(llvm::StringRef Expr, 59317027Sdim llvm::SmallVectorImpl<char> &Output) override; 60317027Sdim bool ResolvePartial(llvm::StringRef Expr, llvm::StringSet<> &Output) override; 61317027Sdim}; 62317027Sdim} 63317027Sdim 64317027Sdim#endif // #ifndef LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H 65