-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe7.cpp
79 lines (68 loc) · 1.26 KB
/
e7.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// Created by martin on 18/01/2022.
//
// Enter text ,,,,? whitespace (? to quit) " - don't use the as-if rule." ??!XXX
#include "../std_lib.h"
using namespace std;
void replace_punctuation (string &s)
{
bool in_quote = false;
for (int i {0} ; i < s.size() ; ++i)
{
switch (s.at(i))
{
case '.':
case ';':
case ',':
case '?':
case '-':
case '\'':
if (!in_quote)
{
s.at(i) = ' ';
}
break;
case '\"':
in_quote = !in_quote;
break;
default:
break;
}
}
}
void replace_strings (string &s)
{
map<string, string> en_map = {
{"don't", "do not"},
{"can't", "cannot"}
};
for (auto &item : en_map)
{
if (s.find(item.first) != string::npos)
{
s.replace(s.find(item.first), item.first.size(), item.second);
}
}
}
void string_to_lowercase (string &s)
{
for (char &c : s)
{
c = char(tolower(c));
}
}
int main ()
{
cout << "Enter text to replace_punctuation punctuation with whitespace (q to quit): " << endl;
for (string line ; getline(cin, line) ;)
{
if (line.size() == 1 && tolower(line.at(0) == 'q'))
{
exit(EXIT_SUCCESS);
}
replace_en_words(line);
replace_punctuation(line);
string_to_lowercase(line);
cout << line << endl;
}
}