[Lldb-commits] [lldb] r370179 - [lldb][NFC] Get rid of C-strings in HandleOptionCompletion
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Wed Aug 28 02:32:30 PDT 2019
Author: teemperor
Date: Wed Aug 28 02:32:30 2019
New Revision: 370179
URL: http://llvm.org/viewvc/llvm-project?rev=370179&view=rev
Log:
[lldb][NFC] Get rid of C-strings in HandleOptionCompletion
Modified:
lldb/trunk/source/Interpreter/Options.cpp
Modified: lldb/trunk/source/Interpreter/Options.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Options.cpp?rev=370179&r1=370178&r2=370179&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Options.cpp (original)
+++ lldb/trunk/source/Interpreter/Options.cpp Wed Aug 28 02:32:30 2019
@@ -652,8 +652,7 @@ bool Options::HandleOptionCompletion(Com
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(Com
// 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(Com
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(Com
// 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(Com
// 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);
}
}
}
More information about the lldb-commits
mailing list