diff options
author | Jared Adams <jaxad0127@gmail.com> | 2010-08-29 09:01:27 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2010-08-29 22:19:24 -0600 |
commit | d55c1345449a34adb3192c23fe3760bd0aae645b (patch) | |
tree | 0dfe78eba2571b2f156c14deafe375d3f3241164 /src/utils | |
parent | b61faa43db7a48c6a6871fb94dce2de2abd79dfe (diff) | |
download | mana-d55c1345449a34adb3192c23fe3760bd0aae645b.tar.gz mana-d55c1345449a34adb3192c23fe3760bd0aae645b.tar.bz2 mana-d55c1345449a34adb3192c23fe3760bd0aae645b.tar.xz mana-d55c1345449a34adb3192c23fe3760bd0aae645b.zip |
Move handling of autocomplete and input history into TextField
Reviewed-by: Freeyorp
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/stringutils.cpp | 37 | ||||
-rw-r--r-- | src/utils/stringutils.h | 4 |
2 files changed, 40 insertions, 1 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 9fe3de14..445427fe 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -174,4 +174,39 @@ const char* getSafeUtf8String(std::string text) memcpy(buf, text.c_str(), text.size()); memset(buf + text.size(), 0, UTF8_MAX_SIZE); return buf; -}
\ No newline at end of file +} + +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 ec82e240..5f1f05f0 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. @@ -125,4 +126,7 @@ const std::string findSameSubstring(const std::string &str1, const std::string & const char* getSafeUtf8String(std::string text); +std::string autocomplete(std::vector<std::string> &candidates, + std::string base); + #endif // UTILS_STRINGUTILS_H |