-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPunctuation_stream.cpp
88 lines (69 loc) · 1.33 KB
/
Punctuation_stream.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
80
81
82
83
84
85
86
87
88
//
// Created by martin on 19/01/2022.
//
#include "Punctuation_stream.h"
using namespace std;
Punctuation_stream::Punctuation_stream (std::istream &source) : source(source),
sensitive(true)
{ }
void Punctuation_stream::whitespace (const string &s)
{
white = s;
}
void Punctuation_stream::add_white (char c)
{
white += c;
}
void Punctuation_stream::case_sensitive (bool b)
{
sensitive = b;
}
bool Punctuation_stream::is_case_sensitive ()
{
return sensitive;
}
Punctuation_stream::operator bool ()
{
return !(source.fail() || source.bad()) && source.good();
}
Punctuation_stream &Punctuation_stream::operator>> (std::string &s)
{
while (!(buffer >> s))
{
if (buffer.bad() || !source.good())
{
return *this;
}
buffer.clear();
string line;
getline(source, line);
for (int i {0} ; i < line.size() ; ++i)
{
if (is_whitespace(line.at(i)))
{
if (i > 0 && line.at(i) == '-' && isalpha(line.at(i - 1)) && isalpha(line.at(i + 1)))
{
continue;
}
line.at(i) = ' ';
}
else if (!sensitive)
{
line.at(i) = char(tolower(line.at(i)));
}
}
buffer.str(line);
}
return *this;
}
bool Punctuation_stream::is_whitespace (char c)
{
for (char &w : white)
{
if (c == w)
{
return true;
}
}
return false;
}