diff options
Diffstat (limited to 'lldb/source/Interpreter/OptionValueBoolean.cpp')
| -rw-r--r-- | lldb/source/Interpreter/OptionValueBoolean.cpp | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/lldb/source/Interpreter/OptionValueBoolean.cpp b/lldb/source/Interpreter/OptionValueBoolean.cpp index bd988fa5750..85799fe3cd4 100644 --- a/lldb/source/Interpreter/OptionValueBoolean.cpp +++ b/lldb/source/Interpreter/OptionValueBoolean.cpp @@ -76,35 +76,23 @@ lldb::OptionValueSP OptionValueBoolean::DeepCopy() const { return OptionValueSP(new OptionValueBoolean(*this)); } -size_t OptionValueBoolean::AutoComplete(CommandInterpreter &interpreter, - const char *s, int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches) { +size_t OptionValueBoolean::AutoComplete( + CommandInterpreter &interpreter, llvm::StringRef s, int match_start_point, + int max_return_elements, bool &word_complete, StringList &matches) { word_complete = false; matches.Clear(); - struct StringEntry { - const char *string; - const size_t length; - }; - static const StringEntry g_autocomplete_entries[] = { - {"true", 4}, {"false", 5}, {"on", 2}, {"off", 3}, - {"yes", 3}, {"no", 2}, {"1", 1}, {"0", 1}, - }; - const size_t k_num_autocomplete_entries = - llvm::array_lengthof(g_autocomplete_entries); + static const llvm::StringRef g_autocomplete_entries[] = { + "true", "false", "on", "off", "yes", "no", "1", "0"}; - if (s && s[0]) { - const size_t s_len = strlen(s); - for (size_t i = 0; i < k_num_autocomplete_entries; ++i) { - if (s_len <= g_autocomplete_entries[i].length) - if (::strncasecmp(s, g_autocomplete_entries[i].string, s_len) == 0) - matches.AppendString(g_autocomplete_entries[i].string); - } - } else { - // only suggest "true" or "false" by default - for (size_t i = 0; i < 2; ++i) - matches.AppendString(g_autocomplete_entries[i].string); + auto entries = llvm::makeArrayRef(g_autocomplete_entries); + + // only suggest "true" or "false" by default + if (s.empty()) + entries = entries.take_front(2); + + for (auto entry : entries) { + if (entry.startswith_lower(s)) + matches.AppendString(entry); } return matches.GetSize(); } |

