12#include <system_error>
14#include "llvm/ADT/STLExtras.h"
15#include "llvm/ADT/SmallVector.h"
16#include "llvm/Support/FileSystem.h"
17#include "llvm/Support/Path.h"
18#include "llvm/Support/raw_ostream.h"
27namespace fs = llvm::sys::fs;
28namespace path = llvm::sys::path;
36 assert(!llvm::any_of(Expr, [](
char c) {
return path::is_separator(c); }));
37 assert(Expr.empty() || Expr[0] ==
'~');
39 return !fs::real_path(Expr, Output,
true);
43 StringSet<> &Output) {
46 assert(!llvm::any_of(Expr, [](
char c) {
return path::is_separator(c); }));
47 assert(Expr.empty() || Expr[0] ==
'~');
50#if defined(_WIN32) || defined(__ANDROID__)
56 SmallString<32> Buffer(
"~");
58 struct passwd *user_entry;
59 Expr = Expr.drop_front();
61 while ((user_entry = getpwent()) !=
nullptr) {
62 StringRef ThisName(user_entry->pw_name);
63 if (!ThisName.starts_with(Expr))
67 Buffer.append(ThisName);
68 Buffer.append(path::get_separator());
69 Output.insert(Buffer);
78 if (!Expr.starts_with(
"~")) {
79 Output.assign(Expr.begin(), Expr.end());
83 namespace path = llvm::sys::path;
85 Expr.take_until([](
char c) {
return path::is_separator(c); });
88 Output.assign(Expr.begin(), Expr.end());
92 Output.append(Expr.begin() + Left.size(), Expr.end());
bool ResolvePartial(llvm::StringRef Expr, llvm::StringSet<> &Output) override
Auto-complete a tilde expression with all matching values.
bool ResolveExact(llvm::StringRef Expr, llvm::SmallVectorImpl< char > &Output) override
Resolve a Tilde Expression contained according to bash rules.
bool ResolveFullPath(llvm::StringRef Expr, llvm::SmallVectorImpl< char > &Output)
Resolve an entire path that begins with a tilde expression, replacing the username portion with the m...
virtual bool ResolveExact(llvm::StringRef Expr, llvm::SmallVectorImpl< char > &Output)=0
Resolve a Tilde Expression contained according to bash rules.
virtual ~TildeExpressionResolver()
A class that represents a running process on the host machine.