From 023882b4233a3b297d96af7175d4db17c16317e3 Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Sat, 8 May 2021 10:35:37 +0200 Subject: [PATCH] enhanced tab auto complete for _functions --- src/common/bspf.hxx | 18 ++++++++++-------- src/debugger/CartDebug.cxx | 2 +- src/debugger/Debugger.cxx | 4 ++-- src/debugger/DebuggerParser.cxx | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/common/bspf.hxx b/src/common/bspf.hxx index 670a186c9..24c4bc246 100644 --- a/src/common/bspf.hxx +++ b/src/common/bspf.hxx @@ -281,18 +281,20 @@ namespace BSPF // (case sensitive for upper case characters in second string, except first one) // - the first character must match // - the following characters must appear in the order of the first string - inline bool matches(const string_view s1, const string_view s2) + inline bool matchesCamelCase(const string_view s1, const string_view s2) { - if(startsWithIgnoreCase(s1, s2.substr(0, 1))) - { - size_t pos = 1; - size_t lastUpper = 0; + // skip leading '_' for matching + uInt32 ofs = (s1[0] == '_' && s2[0] == '_') ? 1 : 0; - for(uInt32 j = 1; j < s2.size(); ++j) + if(startsWithIgnoreCase(s1.substr(ofs), s2.substr(ofs, 1))) + { + size_t lastUpper = ofs, pos = 1; + + for(uInt32 j = 1 + ofs; j < s2.size(); ++j) { if(std::isupper(s2[j])) { - size_t found = s1.find_first_of(s2[j], pos); + size_t found = s1.find_first_of(s2[j], pos + ofs); if(found == string::npos) return false; @@ -306,7 +308,7 @@ namespace BSPF } else { - size_t found = findIgnoreCase(s1, s2.substr(j, 1), pos); + size_t found = findIgnoreCase(s1, s2.substr(j, 1), pos + ofs); if(found == string::npos) return false; diff --git a/src/debugger/CartDebug.cxx b/src/debugger/CartDebug.cxx index 3db30c99c..910203db8 100644 --- a/src/debugger/CartDebug.cxx +++ b/src/debugger/CartDebug.cxx @@ -1509,7 +1509,7 @@ void CartDebug::getCompletions(const char* in, StringList& completions) const for(const auto& iter: myUserAddresses) { const char* l = iter.first.c_str(); - if(BSPF::matches(l, in)) + if(BSPF::matchesCamelCase(l, in)) completions.push_back(l); } } diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index bc574cefd..811f11c59 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -893,12 +893,12 @@ void Debugger::getCompletions(const char* in, StringList& list) const for(const auto& iter : myFunctions) { const char* l = iter.first.c_str(); - if(BSPF::matches(l, in)) + if(BSPF::matchesCamelCase(l, in)) list.push_back(l); } for(const auto& reg: ourPseudoRegisters) - if(BSPF::matches(reg.name, in)) + if(BSPF::matchesCamelCase(reg.name, in)) list.push_back(reg.name); } } diff --git a/src/debugger/DebuggerParser.cxx b/src/debugger/DebuggerParser.cxx index 542c090f8..e1503eb01 100644 --- a/src/debugger/DebuggerParser.cxx +++ b/src/debugger/DebuggerParser.cxx @@ -180,7 +180,7 @@ void DebuggerParser::getCompletions(const char* in, StringList& completions) con // cerr << "Attempting to complete \"" << in << "\"" << endl; for(const auto& c: commands) { - if(BSPF::matches(c.cmdString, in)) + if(BSPF::matchesCamelCase(c.cmdString, in)) completions.push_back(c.cmdString); } }