PromptWidget::getCompletionPrefix refactored

This commit is contained in:
thrust26 2017-10-10 16:40:54 +02:00
parent 20ff2163ca
commit c93d7e265d
1 changed files with 7 additions and 6 deletions

View File

@ -913,25 +913,26 @@ bool PromptWidget::saveBuffer(const FilesystemNode& file)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string PromptWidget::getCompletionPrefix(const StringList& completions)
{
// Find the largest match at the beginning of the completions provided
// Find the number of characters matching for each of the completions provided
for(uInt32 len = 1;; len++)
{
for(const auto& s1 : completions)
for(uInt32 i = 0; i < completions.size(); i++)
{
string s1 = completions[i];
if(s1.length() < len)
{
return s1.substr(0, len - 1);
}
string find = s1.substr(0, len);
for(const auto& s2 : completions)
{
if(!BSPF::matches(s2, find))
for(uInt32 j = i + 1; j < completions.size(); j++)
{
string s2 = completions[j];
if(!BSPF::startsWithIgnoreCase(s2, find))
return s1.substr(0, len - 1);
}
}
}
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -