-
Notifications
You must be signed in to change notification settings - Fork 33
/
17.18.cpp
34 lines (32 loc) · 949 Bytes
/
17.18.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
/*
* Exercise 17.18: Revise your program to ignore words that contain “ei” but
* are not misspellings, such as “albeit” and “neighbor.”
*
* By Faisal Saadatmand
*/
#include <iostream>
#include <set>
#include <string>
#include <regex>
int main()
{
std::set<std::string> exceptions{"albeit", "being", "neigbour", "veil"};
std::string pattern("[^c]ei");
pattern = "[[:alpha:]]*" + pattern + "[[:alpha:]]*";
std::regex r(pattern, std::regex::icase);
std::string line;
while (std::getline(std::cin, line)) {
for (std::sregex_iterator it(line.cbegin(), line.cend(), r), end_it;
it != end_it; ++it) {
auto skip = exceptions.find(it->str());
if (skip != exceptions.cend())
continue;
auto pos = it->prefix().length();
pos = pos > 40 ? pos - 40 : 0;
std::cout << it->prefix().str().substr(pos)
<< "\n\t\t>>> " << it->str() << " <<<\n"
<< it->suffix().str().substr(0, 40) << '\n';
}
}
return 0;
}