-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
137 lines (123 loc) · 3.19 KB
/
main.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <iostream>
#include <fstream>
#include <regex>
#include <utility>
using namespace std;
class regexValue{
public:
const regex regFrom = regex("[\\s\\S]+from=<(.*@.*)>[\\s\\S]+");
const regex reTo = regex("[\\s\\S]+to=<(.*)>.*status=([a-z]+).*");
const regex time = regex("([\\s\\S]+[0-9][0-9]:[0-9][0-9]:[0-9][0-9])[\\s\\S]+");
regex getFrom(){
return regFrom;
}
regex getTo(){
return reTo;
}
regex getTime(){
return time;
}
};
class Value{
private:
string fromUser;
string toUser;
string status;
string time;
public:
Value(string From, string To, string Status ): fromUser(std::move(From)), toUser(std::move(To)), status(std::move(Status)){};
void setFromUser(string str){
this->fromUser = std::move(str);
}
void setToUser(string str){
this->toUser = std::move(str);
}
void setStatus(string str){
this->status = std::move(str);
}
void setTime(string str){
this->time = std::move(str);
}
string getFromUser(){
return this->fromUser;
}
string getToUser(){
return this->toUser;
}
string getStatus(){
return this->status;
}
string getTime(){
return this->time;
}
};
bool matchValue(Value* value, string& input, regexValue regValus){
//getline(cin, input);
smatch sms;
if( regex_match(input, sms, regValus.getTime()) ){
// cout << "Match!" << endl;
int i=0;
// cout << "The matches are:\n";
for(string sm:sms ){
// cout << sm << endl;
if(i==1) {
// cout << sm << endl;
value->setTime(sm);
}
i++;
}
//cout << value->getFromUser();
}
if( regex_match(input, sms, regValus.getFrom()) ){
// cout << "Match!" << endl;
int i=0;
// cout << "The matches are:\n";
for(string sm:sms ){
i++;
if(i==2) {
// cout << sm << endl;
value->setFromUser(sm);
}
}
// cout << value->getFromUser();
}
if( regex_match(input, sms, regValus.getTo()) ){
// cout << "Match!" << endl;
int i=0;
// cout << "The matches are:\n";
for(string sm:sms ){
i++;
if(i==2) {
// cout << sm << endl;
value->setToUser(sm);
}
if(i==3){
value->setStatus(sm);
}
}
// cout << value->getFromUser();
return true;
}
else{
// cout << "to Not Match!" << endl;
}
// cout << "Not Match!" << endl;
return false;
}
int main() {
Value object{"","",""};
string input;
ifstream myfile("mail.log");
if(myfile.is_open()){
while (getline(myfile,input)){
regexValue regObject;
if(matchValue(&object, input, regObject)){
cout << "time: " <<object.getTime();
cout << " from: " << object.getFromUser();
cout << " user: " << object.getToUser();
cout << " status: " << object.getStatus() <<endl;
}
}
}
return 0;
}