-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReader.cpp
More file actions
89 lines (82 loc) · 1.83 KB
/
Reader.cpp
File metadata and controls
89 lines (82 loc) · 1.83 KB
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
#include "Reader.h"
Reader::Reader(istream& inpStr){
string cell;
while(std::getline(inpStr,cell)){
this->lines += cell + "\n";
}
this->myBaseIter = this->lines.begin();
this->myLocalIter = this->myBaseIter;
}
bool Reader::AtEnd(unsigned int inpPatternSize){
string::iterator subStrIter = this->myBaseIter;
for (unsigned int i = 0; i < inpPatternSize - 1; i++){
if (subStrIter == this->lines.end()){
return true;
}
subStrIter++;
}
return subStrIter == this->lines.end();
}
void Reader::NextBaseChar(){
this->myBaseIter++;
this->myLocalIter = this->myBaseIter;
}
string Reader::GetNextChar(){
string st;
if (this->myLocalIter != this->lines.end()){
st.push_back(*(this->myLocalIter++));
}else{
st.push_back(*this->myLocalIter);
}
return st;
}
string Reader::Reverse(const string& inpStr)
{
int len = inpStr.size();
string reverse = inpStr;
for (int n = 0; n < len; ++n)
{
reverse[len - n - 1] = inpStr[n];
}
return reverse;
}
string Reader::PrintContext(unsigned int inpNum){
string::iterator fwdIter = this->myLocalIter;
string::iterator bwdIter = this->myBaseIter;
string subStr;
bool onBegin = true;
if (bwdIter != this->lines.begin()){
bwdIter--;
onBegin = false;
}
while (*bwdIter != '\n'){
if (bwdIter != this->lines.begin()){
subStr.push_back(*(bwdIter--));
} else if (!onBegin){
subStr.push_back(*bwdIter);
break;
} else{
break;
}
}
subStr = this->Reverse(subStr);
cout<<subStr;
subStr.clear();
string matched;
matched += "\e[0;31m";
for (string::iterator it = this->myBaseIter; it != myLocalIter; it++){
matched += *it;
}
cout<<matched;
subStr += "\e[0m";
while (*fwdIter != '\n'){
if (fwdIter != this->lines.end()){
subStr.push_back(*(fwdIter++));
} else{
//subStr.push_back(*fwdIter);
break;
}
}
cout<<subStr<<endl;
return subStr;
}