diff options
author | Zachary Turner <zturner@google.com> | 2016-11-17 01:37:42 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-11-17 01:37:42 +0000 |
commit | 4aa8753c8103f1e1988b79325f957a587c150337 (patch) | |
tree | 9d6111d7b94f298115f955e82d1b4d7053bb332e /lldb/source/Core/StringList.cpp | |
parent | 004319554cf6044896073b8a305ba9d340ed5f94 (diff) | |
download | bcm5719-llvm-4aa8753c8103f1e1988b79325f957a587c150337.tar.gz bcm5719-llvm-4aa8753c8103f1e1988b79325f957a587c150337.zip |
Convert AutoComplete related code to StringRef.
Differential Revision: https://reviews.llvm.org/D26721
llvm-svn: 287188
Diffstat (limited to 'lldb/source/Core/StringList.cpp')
-rw-r--r-- | lldb/source/Core/StringList.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/lldb/source/Core/StringList.cpp b/lldb/source/Core/StringList.cpp index 226db21609a..d2c4ac6775a 100644 --- a/lldb/source/Core/StringList.cpp +++ b/lldb/source/Core/StringList.cpp @@ -230,24 +230,25 @@ StringList &StringList::operator=(const std::vector<std::string> &rhs) { return *this; } -size_t StringList::AutoComplete(const char *s, StringList &matches, +size_t StringList::AutoComplete(llvm::StringRef s, StringList &matches, size_t &exact_idx) const { matches.Clear(); exact_idx = SIZE_MAX; - if (s && s[0]) { - const size_t s_len = strlen(s); - const size_t num_strings = m_strings.size(); - - for (size_t i = 0; i < num_strings; ++i) { - if (m_strings[i].find(s) == 0) { - if (exact_idx == SIZE_MAX && m_strings[i].size() == s_len) - exact_idx = matches.GetSize(); - matches.AppendString(m_strings[i]); - } - } - } else { + if (s.empty()) { // No string, so it matches everything matches = *this; + return matches.GetSize(); + } + + const size_t s_len = s.size(); + const size_t num_strings = m_strings.size(); + + for (size_t i = 0; i < num_strings; ++i) { + if (m_strings[i].find(s) == 0) { + if (exact_idx == SIZE_MAX && m_strings[i].size() == s_len) + exact_idx = matches.GetSize(); + matches.AppendString(m_strings[i]); + } } return matches.GetSize(); } |