From 617155fe562652c859a380d85cc5710783d79448 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 1 Feb 2016 09:30:04 -0500 Subject: Added emoji freevar Strings of emojis are tokenized separately from anything else, and added to an emoticon freevar, which is mixed in with regular emoticons like :P. This breaks old-style freevars like $name$ and $noun$ so some legacy support for compatibility is left in but eventually $name$ should be made into an actual new freevar. Emoji data is from gemoji (https://github.com/github/gemoji). --- prefix_search.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 prefix_search.cpp (limited to 'prefix_search.cpp') diff --git a/prefix_search.cpp b/prefix_search.cpp new file mode 100644 index 0000000..2603061 --- /dev/null +++ b/prefix_search.cpp @@ -0,0 +1,35 @@ +#include "prefix_search.h" + +void prefix_search::add(std::string prefix) +{ + node* cur = ⊤ + for (int c : prefix) + { + cur = &cur->children[c]; + } + + cur->match = true; +} + +int prefix_search::match(std::string in) const +{ + int ret = 0; + const node* cur = ⊤ + for (int c : in) + { + if (cur->children.count(c) == 0) + { + return 0; + } + + cur = &cur->children.at(c); + ret++; + + if (cur->match) + { + return ret; + } + } + + return 0; +} -- cgit 1.4.1