summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/stringutils.cpp35
-rw-r--r--src/utils/stringutils.h4
2 files changed, 39 insertions, 0 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 3988c769..4726f8a7 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -187,3 +187,38 @@ bool getBoolFromString(const std::string &text)
else
return (bool) atoi(txt.c_str());
}
+
+std::string autocomplete(std::vector<std::string> &candidates,
+ std::string base)
+{
+ std::vector<std::string>::iterator i = candidates.begin();
+ toLower(base);
+ std::string newName("");
+
+ while (i != candidates.end())
+ {
+ if (!i->empty())
+ {
+ std::string name = *i;
+ toLower(name);
+
+ std::string::size_type pos = name.find(base, 0);
+ if (pos == 0)
+ {
+ if (newName != "")
+ {
+ toLower(newName);
+ newName = findSameSubstring(name, newName);
+ }
+ else
+ {
+ newName = *i;
+ }
+ }
+ }
+
+ ++i;
+ }
+
+ return newName;
+}
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index 7c14b1e5..012ae98f 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -24,6 +24,7 @@
#include <string>
#include <sstream>
+#include <vector>
/**
* Trims spaces off the end and the beginning of the given string.
@@ -133,4 +134,7 @@ const char* getSafeUtf8String(std::string text);
*/
bool getBoolFromString(const std::string &text);
+std::string autocomplete(std::vector<std::string> &candidates,
+ std::string base);
+
#endif // UTILS_STRINGUTILS_H