about summary refs log tree commit diff stats
path: root/prefix_search.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2016-02-01 09:30:04 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2016-02-01 09:30:04 -0500
commit617155fe562652c859a380d85cc5710783d79448 (patch)
treef5eee89b0fa4b3c9dfe7187ca78916a71b59045e /prefix_search.cpp
parentb316e309559d7176af6cf0bb7dcd6dbaa83c01cd (diff)
downloadrawr-ebooks-617155fe562652c859a380d85cc5710783d79448.tar.gz
rawr-ebooks-617155fe562652c859a380d85cc5710783d79448.tar.bz2
rawr-ebooks-617155fe562652c859a380d85cc5710783d79448.zip
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).
Diffstat (limited to 'prefix_search.cpp')
-rw-r--r--prefix_search.cpp35
1 files changed, 35 insertions, 0 deletions
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 @@
1#include "prefix_search.h"
2
3void prefix_search::add(std::string prefix)
4{
5 node* cur = &top;
6 for (int c : prefix)
7 {
8 cur = &cur->children[c];
9 }
10
11 cur->match = true;
12}
13
14int prefix_search::match(std::string in) const
15{
16 int ret = 0;
17 const node* cur = &top;
18 for (int c : in)
19 {
20 if (cur->children.count(c) == 0)
21 {
22 return 0;
23 }
24
25 cur = &cur->children.at(c);
26 ret++;
27
28 if (cur->match)
29 {
30 return ret;
31 }
32 }
33
34 return 0;
35}