From 12376d3e4b90c448be09d199faebde01800663ec Mon Sep 17 00:00:00 2001 From: Patrick Lipka Date: Thu, 16 Dec 2021 13:21:26 +0100 Subject: [PATCH] tt_name_completion rewritten in a more C++ conformant way --- src/ui.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/ui.cpp b/src/ui.cpp index 1272c6a..60156a8 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "ui.h" #include "project.h" #include "track.h" @@ -36,18 +37,16 @@ char **tt_name_completion(const char* text, int start, int end){ } char *tt_name_generator(const char *text, int state){ - static int idx, len; - const char *name; - if (!state){ - idx = 0; - len = strlen(text); - } - while ((name = autocomplete_names[idx++].c_str())){ - if (strncmp(name, text, len) == 0){ - return strdup(name); - } - } - return NULL; + static std::vector::const_iterator it; + if (state == 0) it=begin(autocomplete_names); + while(it != end(autocomplete_names)){ + std::string result = *it; + ++it; + if (result.find(text) != std::string::npos){ + return strdup(result.c_str()); + } + } + return NULL; } void init_autocomplete(ProjectList *proj_list){