-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditor.cpp
100 lines (98 loc) · 2.9 KB
/
Editor.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
/* Arbel Nathan 308366749 */
#include "Editor.h"
void Editor::loop(){
// p prints the current line (ed maintains a current line)
regex p("p");
// n prints line number of current line followed by TAB followed by current line
regex n("n");
// %p prints all lines
regex prAll("%p");
// 7 makes line #7 the current line
regex changeLine(R"(\d)");
// a appends new text after the current line
regex a("a");
// i inserts new text before the current line
regex i("i");
// c changes the current line for text that follows
regex c("c");
// d deletes the current line
regex d("d");
// /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
regex src(R"(/\w+)");
// s/old/new/ replaces old string with new in current line (google: C++ split or token)
regex swc(R"(s/\w+/\w+/?)");
// Q Quits the editor without saving
regex Q("Q");
while(true){
string work;
getline(cin,work);
if(regex_match(work, swc)){
//cout<<"swc"<<endl;
string first=work.substr(2);
int find1 =first.find("/");
string one= first.substr(0,find1);
int find2=first.rfind("/");
string two;
if(find2==find1) {
two= first.substr(find1+1);
//cout<<"in4"<<endl;
}else{
//cout<<first<<endl;
two= first.substr((find1+1),find2-find1-1);
}
Doc->s(one,two);
// Doc->Q();
}
else if(regex_match(work, p)){
// cout<<"p"<<endl;
// Doc->Q();
Doc->p();
}
else if(regex_match(work, n)){
// cout<<"n"<<endl;
// Doc->Q();
Doc->n();
}
else if(regex_match(work, prAll)){
// cout<<"prAll"<<endl;
// Doc->Q();
Doc->pAll();
}
else if(regex_match(work, changeLine)){
// cout<<"changeLine"<<endl;
// Doc->Q();
Doc->changeLine(stoi(work));//stoi string to int
}
else if(regex_match(work, a)){
// cout<<"a"<<endl;
// Doc->Q();
Doc->a();
}
else if(regex_match(work, i)){
// cout<<"i"<<endl;
// Doc->Q();
Doc->i();
}
else if(regex_match(work, c)){
// cout<<"c"<<endl;
// Doc->Q();
Doc->c();
}
else if(regex_match(work, d)){
// cout<<"d"<<endl;
// Doc->Q();
Doc->d();
}
else if(regex_match(work, src)){
// cout<<"src"<<endl;
// Doc->Q();
string src=work.substr(1);
Doc->search(src);
}
else if(regex_match(work,Q)){
// cout<<"Q"<<endl;
Doc->Q();
}
}
}