-
Notifications
You must be signed in to change notification settings - Fork 0
/
Document.cpp
129 lines (117 loc) · 3.52 KB
/
Document.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
/* Arbel Nathan 308366749 */
#include "Document.h"
// p prints the current line (ed maintains a current line)
void Documents::p(){
cout<<full.at(currentLine)<<endl;
}
// n prints line number of current line followed by TAB followed by current line
void Documents::n(){
cout<<(currentLine+1)<<"\t"<<full.at(currentLine)<<endl;
}
// %p prints all lines
void Documents::pAll(){
for(string st: full){
cout<<st<<endl;
}
}
// 7 makes line #7 the current line
void Documents::changeLine(int line){
if(line>full.size()||line<=0){
cout<<"?"<<endl;
Q();
}
currentLine=(line-1);
cout<<full.at(currentLine)<<endl;
}
// a appends new text after the current line
void Documents::a(){
if(currentLine==-1){
string temp;
//need lines and with empty lines;
getline(cin,temp);
if(temp.compare(".")){
full.push_back(temp);
currentLine=0;
}
}
std::vector<string>::iterator it;
while(true){
it=full.begin()+(currentLine+1);
string temp;
//need lines and with empty lines;
getline(cin,temp);
if(!temp.compare(".")) break;
full.insert(it,temp);
currentLine++;
// pAll();
}
}
// i inserts new text before the current line
void Documents::i(){
if(currentLine==-1){
string temp;
//need lines and with empty lines;
getline(cin,temp);
if(temp.compare(".")){
full.push_back(temp);
currentLine=0;
}
}
std::vector<string>::iterator it;
while(true){
it=full.begin()+(currentLine);
string temp;
//need lines and with empty lines;
getline(cin,temp);
if(!temp.compare(".")) break;
full.insert(it++,temp);
currentLine++;
}
}
// c changes the current line for text that follows
void Documents::c(){
d();
std::vector<string>::iterator it;
while(true){
it=full.begin()+(currentLine+1);
string temp;
//need lines and with empty lines;
getline(cin,temp);
if(!temp.compare(".")) break;
full.insert(it,temp);
currentLine++;
}
}
// d deletes the current line
void Documents::d(){
//cout<<full.at(currentLine)<<" del"<<endl;
full.erase((full.begin()+(currentLine)));
currentLine--;
}
// /text searches forward after current line for the specified text. The search wraps to the
// beginning of the buffer and continues down to the current line, if necessary
void Documents::search(string find){
for(int i =0; i<=currentLine ; i++)
{
if(full.at(i).find(find)!=string::npos){
currentLine=i;
}
}
cout<<full.at(currentLine)<<endl;
}
// s/old/new/ replaces old string with new in current line (google: C++ split or token)
void Documents::s(string s_old, string s_new){
int check= full.at(currentLine).find(s_old);
if(check!=-1){
full.at(currentLine).replace(check,s_old.size(),s_new);
}
else{
cout<<"?"<<endl;
Q();
}
}
// Q
// Quits the editor without saving
void Documents::Q(){
exit(0);
}