-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathaho_corasick_example.cpp
41 lines (33 loc) · 1.2 KB
/
aho_corasick_example.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
Copyright (c) Alexander Zaitsev <[email protected]>, 2016
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
For more information, see http://www.boost.org
*/
#include <vector>
#include <string>
#include <iostream>
#include <boost/algorithm/searching/aho_corasick.hpp>
int main()
{
std::vector<std::string> pat({"228", "he", "is", "1488", "she", "his", "322", "her",
"h", "hishera", "azaza"});
std::string corp = "hisher";
std::vector<std::pair<std::string::const_iterator, std::string::const_iterator>> out;
bool result = boost::algorithm::aho_corasick_map<char>(corp.begin(), corp.end(), pat.begin(), pat.end(),
[&out](std::string::const_iterator begin, std::string::const_iterator end) -> bool
{ out.push_back({begin, end}); return true; });
std::cout << result << std::endl;
for(const auto& val: out)
{
auto begin = val.first;
auto end = val.second;
while (begin != end)
{
std::cout << *begin;
++begin;
}
std::cout << std::endl;
}
return 0;
}