summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/FormatEntity.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-11-17 01:37:42 +0000
committerZachary Turner <zturner@google.com>2016-11-17 01:37:42 +0000
commit4aa8753c8103f1e1988b79325f957a587c150337 (patch)
tree9d6111d7b94f298115f955e82d1b4d7053bb332e /lldb/source/Core/FormatEntity.cpp
parent004319554cf6044896073b8a305ba9d340ed5f94 (diff)
downloadbcm5719-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/FormatEntity.cpp')
-rw-r--r--lldb/source/Core/FormatEntity.cpp103
1 files changed, 56 insertions, 47 deletions
diff --git a/lldb/source/Core/FormatEntity.cpp b/lldb/source/Core/FormatEntity.cpp
index bd2e5361800..4d85c3686c2 100644
--- a/lldb/source/Core/FormatEntity.cpp
+++ b/lldb/source/Core/FormatEntity.cpp
@@ -2327,60 +2327,69 @@ static void AddMatches(const FormatEntity::Entry::Definition *def,
}
}
-size_t FormatEntity::AutoComplete(const char *s, int match_start_point,
+size_t FormatEntity::AutoComplete(llvm::StringRef str, int match_start_point,
int max_return_elements, bool &word_complete,
StringList &matches) {
word_complete = false;
- llvm::StringRef str(s + match_start_point);
+ str = str.drop_front(match_start_point);
matches.Clear();
const size_t dollar_pos = str.rfind('$');
- if (dollar_pos != llvm::StringRef::npos) {
- // Hitting TAB after $ at the end of the string add a "{"
- if (dollar_pos == str.size() - 1) {
- std::string match = str.str();
- match.append("{");
- matches.AppendString(std::move(match));
- } else if (str[dollar_pos + 1] == '{') {
- const size_t close_pos = str.find('}', dollar_pos + 2);
- if (close_pos == llvm::StringRef::npos) {
- const size_t format_pos = str.find('%', dollar_pos + 2);
- if (format_pos == llvm::StringRef::npos) {
- llvm::StringRef partial_variable(str.substr(dollar_pos + 2));
- if (partial_variable.empty()) {
- // Suggest all top level entites as we are just past "${"
- AddMatches(&g_root, str, llvm::StringRef(), matches);
- } else {
- // We have a partially specified variable, find it
- llvm::StringRef remainder;
- const FormatEntity::Entry::Definition *entry_def =
- FindEntry(partial_variable, &g_root, remainder);
- if (entry_def) {
- const size_t n = entry_def->num_children;
-
- if (remainder.empty()) {
- // Exact match
- if (n > 0) {
- // "${thread.info" <TAB>
- matches.AppendString(MakeMatch(str, "."));
- } else {
- // "${thread.id" <TAB>
- matches.AppendString(MakeMatch(str, "}"));
- word_complete = true;
- }
- } else if (remainder.equals(".")) {
- // "${thread." <TAB>
- AddMatches(entry_def, str, llvm::StringRef(), matches);
- } else {
- // We have a partial match
- // "${thre" <TAB>
- AddMatches(entry_def, str, remainder, matches);
- }
- }
- }
- }
- }
+ if (dollar_pos == llvm::StringRef::npos)
+ return 0;
+
+ // Hitting TAB after $ at the end of the string add a "{"
+ if (dollar_pos == str.size() - 1) {
+ std::string match = str.str();
+ match.append("{");
+ matches.AppendString(match);
+ return 1;
+ }
+
+ if (str[dollar_pos + 1] != '{')
+ return 0;
+
+ const size_t close_pos = str.find('}', dollar_pos + 2);
+ if (close_pos != llvm::StringRef::npos)
+ return 0;
+
+ const size_t format_pos = str.find('%', dollar_pos + 2);
+ if (format_pos != llvm::StringRef::npos)
+ return 0;
+
+ llvm::StringRef partial_variable(str.substr(dollar_pos + 2));
+ if (partial_variable.empty()) {
+ // Suggest all top level entites as we are just past "${"
+ AddMatches(&g_root, str, llvm::StringRef(), matches);
+ return matches.GetSize();
+ }
+
+ // We have a partially specified variable, find it
+ llvm::StringRef remainder;
+ const FormatEntity::Entry::Definition *entry_def =
+ FindEntry(partial_variable, &g_root, remainder);
+ if (!entry_def)
+ return 0;
+
+ const size_t n = entry_def->num_children;
+
+ if (remainder.empty()) {
+ // Exact match
+ if (n > 0) {
+ // "${thread.info" <TAB>
+ matches.AppendString(MakeMatch(str, "."));
+ } else {
+ // "${thread.id" <TAB>
+ matches.AppendString(MakeMatch(str, "}"));
+ word_complete = true;
}
+ } else if (remainder.equals(".")) {
+ // "${thread." <TAB>
+ AddMatches(entry_def, str, llvm::StringRef(), matches);
+ } else {
+ // We have a partial match
+ // "${thre" <TAB>
+ AddMatches(entry_def, str, remainder, matches);
}
return matches.GetSize();
}
OpenPOWER on IntegriCloud