tt_name_completion rewritten in a more C++ conformant way

This commit is contained in:
Patrick Lipka 2021-12-16 13:21:26 +01:00
parent 7ebe1c5fb4
commit 12376d3e4b
1 changed files with 11 additions and 12 deletions

View File

@ -6,6 +6,7 @@
#include <algorithm> #include <algorithm>
#include <ctime> #include <ctime>
#include <iomanip> #include <iomanip>
#include <iterator>
#include "ui.h" #include "ui.h"
#include "project.h" #include "project.h"
#include "track.h" #include "track.h"
@ -36,15 +37,13 @@ char **tt_name_completion(const char* text, int start, int end){
} }
char *tt_name_generator(const char *text, int state){ char *tt_name_generator(const char *text, int state){
static int idx, len; static std::vector<std::string>::const_iterator it;
const char *name; if (state == 0) it=begin(autocomplete_names);
if (!state){ while(it != end(autocomplete_names)){
idx = 0; std::string result = *it;
len = strlen(text); ++it;
} if (result.find(text) != std::string::npos){
while ((name = autocomplete_names[idx++].c_str())){ return strdup(result.c_str());
if (strncmp(name, text, len) == 0){
return strdup(name);
} }
} }
return NULL; return NULL;