From d55c1345449a34adb3192c23fe3760bd0aae645b Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sun, 29 Aug 2010 09:01:27 -0600 Subject: Move handling of autocomplete and input history into TextField Reviewed-by: Freeyorp --- src/utils/stringutils.cpp | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'src/utils/stringutils.cpp') 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 &candidates, + std::string base) +{ + std::vector::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; +} -- cgit v1.2.3-70-g09d2