13 #include "llvm/Support/Errc.h"
14 #include "llvm/Support/Error.h"
20 CommandObjectRegexCommand::CommandObjectRegexCommand(
25 m_max_matches(max_matches), m_completion_type_mask(completion_type_mask),
26 m_is_removable(is_removable) {}
32 llvm::StringRef input,
35 llvm::raw_string_ostream output(buffer);
37 llvm::SmallVector<llvm::StringRef, 4> parts;
38 input.split(parts,
'%');
41 for (llvm::StringRef part : drop_begin(parts)) {
43 if (part.consumeInteger(10, idx))
45 else if (idx < replacements.size())
46 output << replacements[idx];
48 return llvm::make_error<llvm::StringError>(
49 llvm::formatv(
"%{0} is out of range: not enough arguments specified",
51 llvm::errc::invalid_argument);
60 EntryCollection::const_iterator pos, end =
m_entries.end();
61 for (pos =
m_entries.begin(); pos != end; ++pos) {
62 llvm::SmallVector<llvm::StringRef, 4> matches;
63 if (pos->regex.Execute(command, &matches)) {
64 llvm::Expected<std::string> new_command =
67 result.
SetError(new_command.takeError());
85 <<
"' failed to match any "
86 "regular expression in the '"
92 llvm::StringRef command_cstr) {
97 m_entries.back().command = command_cstr.str();