summaryrefslogtreecommitdiffstats
path: root/lldb
diff options
context:
space:
mode:
Diffstat (limited to 'lldb')
-rw-r--r--lldb/source/Interpreter/Options.cpp28
1 files changed, 11 insertions, 17 deletions
diff --git a/lldb/source/Interpreter/Options.cpp b/lldb/source/Interpreter/Options.cpp
index 6c528b119fe..2829a22b7e4 100644
--- a/lldb/source/Interpreter/Options.cpp
+++ b/lldb/source/Interpreter/Options.cpp
@@ -652,8 +652,7 @@ bool Options::HandleOptionCompletion(CompletionRequest &request,
auto opt_defs = GetDefinitions();
- std::string cur_opt_std_str = request.GetCursorArgumentPrefix().str();
- const char *cur_opt_str = cur_opt_std_str.c_str();
+ llvm::StringRef cur_opt_str = request.GetCursorArgumentPrefix();
for (size_t i = 0; i < opt_element_vector.size(); i++) {
int opt_pos = opt_element_vector[i].opt_pos;
@@ -667,7 +666,7 @@ bool Options::HandleOptionCompletion(CompletionRequest &request,
// FIXME: We should scan the other options provided and only complete
// options
// within the option group they belong to.
- char opt_str[3] = {'-', 'a', '\0'};
+ std::string opt_str = "-a";
for (auto &def : opt_defs) {
if (!def.short_option)
@@ -685,7 +684,7 @@ bool Options::HandleOptionCompletion(CompletionRequest &request,
full_name.erase(full_name.begin() + 2, full_name.end());
full_name.append(def.long_option);
- request.AddCompletion(full_name.c_str());
+ request.AddCompletion(full_name);
}
return true;
} else if (opt_defs_index != OptionArgElement::eUnrecognizedArg) {
@@ -693,17 +692,13 @@ bool Options::HandleOptionCompletion(CompletionRequest &request,
// anyway (getopt_long_only is happy with shortest unique string, but
// it's still a nice thing to do.) Otherwise return The string so the
// upper level code will know this is a full match and add the " ".
- if (cur_opt_str && strlen(cur_opt_str) > 2 && cur_opt_str[0] == '-' &&
- cur_opt_str[1] == '-' &&
- strcmp(opt_defs[opt_defs_index].long_option, cur_opt_str) != 0) {
- std::string full_name("--");
- full_name.append(opt_defs[opt_defs_index].long_option);
- request.AddCompletion(full_name.c_str());
+ llvm::StringRef long_option = opt_defs[opt_defs_index].long_option;
+ if (cur_opt_str.startswith("--") && cur_opt_str != long_option) {
+ request.AddCompletion("--" + long_option.str());
return true;
- } else {
+ } else
request.AddCompletion(request.GetCursorArgument());
- return true;
- }
+ return true;
} else {
// FIXME - not handling wrong options yet:
// Check to see if they are writing a long option & complete it.
@@ -712,16 +707,15 @@ bool Options::HandleOptionCompletion(CompletionRequest &request,
// that are not unique up to this point. getopt_long_only does
// shortest unique match for long options already.
- if (cur_opt_str && strlen(cur_opt_str) > 2 && cur_opt_str[0] == '-' &&
- cur_opt_str[1] == '-') {
+ if (cur_opt_str.startswith("--")) {
for (auto &def : opt_defs) {
if (!def.long_option)
continue;
- if (strstr(def.long_option, cur_opt_str + 2) == def.long_option) {
+ if (cur_opt_str.startswith(def.long_option)) {
std::string full_name("--");
full_name.append(def.long_option);
- request.AddCompletion(full_name.c_str());
+ request.AddCompletion(full_name);
}
}
}
OpenPOWER on IntegriCloud