Repository navigation
Expand file tree
/
Copy pathStyle.cpp
More file actions
130 lines (105 loc) · 3.54 KB
/
Copy pathStyle.cpp
File metadata and controls
130 lines (105 loc) · 3.54 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
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
#include "Style.h"
//konstruktori
Style::Style()
{
this->next = nullptr;
this->clearStyle();
}
Style::Style(int beg, int end, char c)
{
this->openPosition = beg;
this->closedPosition = end+1;
this->type = c;
this->next = nullptr;
}
//retetuje style
void Style::clearStyle()
{
this->closedPosition = this->openPosition = 0;
this->type = 'b';
}
//ispisuje style
void Style::writeStyle(string& text)
{
string t;
//kovertovanje char u strin radi lakseg upisa
switch (this->type) {
case'i': t = "i"; break;
case'u': t = "u"; break;
case'b': t = "b"; break;
}
text.insert(closedPosition, "</" + t + ">");
text.insert(openPosition, "<" + t+ ">");
//izbrisano je prvo otvoren pa zatvoren zato moramo da upisemo zatvoren pa otvoren
}
//cita style iz teksta
bool Style::readStyle(string& text, bool& error)
{
this->type = type;
int a = text.find("<");//pronalazi prvi potencijalni znak stila
if (a != -1) {//ako ga je nasao
if ((text[a + 1] != 'i' && text[a + 1] != 'u' && text[a + 1] != 'b')||text[a+2]!='>') {//i nije validnog oblika
cout << "Nepostojeci stil ili je yatvoren stil pre otvorenog" << endl; //prijavi gresku i prekini citanje
error = false;
return false;
}
else {//ako jeste neki od validnih stilova
this->type = text[a + 1];//sacuvaj tip stila
text.erase(a, 3);//obrisi otvoren stil iz teksta
}
}
else return false;//nije nasao ni jedan stil ->prekid citanja
int b = text.find("<" );//nalazi sledeci potencijalni stil
if (b == -1) { cout << "Neki od stilova nije uparen" << endl; error = false; return false; }//ako stil nije zatvoren javlja gresku i prekida citanje
else {
if (text[b+1]!='/' || text[b + 2] != this->type || text[b+3]!='>')//ako je stil otvoren ili drugog tipa ili nije validan vraca gresku
{ cout << "Ugnjezdavanje stilova ili nevalidan zatvoren stil" << endl; error = false; return false; }
text.erase(b,4);//ako do tog momenta nije vracena greska stil je validan i zatvoren i ne preklapa se ni sa jednim
//brise se iz teksta zatvoren deo
this->openPosition = a;//cuva pociiciju pocetka stila
this->closedPosition = b;//cuva poziciju kraja stila
return true;//vraca validnost
}
}
//getter metode
int Style::getOpenPosition()
{
return this->openPosition;
}
int Style::getClosedPosition()
{
return this->closedPosition;
}
Style* Style::getNext()
{
return this->next;
}
//setter metode
void Style::setNext(Style* s)
{
this->next = s;
}
//proverava da li se stilovi preklapaju
bool Style::styleOverlapping(int start, int end)
{
int a = (this->closedPosition >= end) ? 1 : -1;
int b = (this->openPosition >= start) ? 1 : -1;
int c = (this->openPosition <= end) ? 1 : -1;
int d = (start <= this->closedPosition) ? 1 : -1;
if (a * b < 0 || c * d>0)
{
return true;
}
return false;
}
//pomocna funkcija za debagovanje
void Style::tellStyle()
{
cout << this->openPosition << "," << this->closedPosition << endl;
}
//
void Style::updatePositions(int pos)
{
if (this->openPosition >= pos)this->openPosition-=pos;
if (this->closedPosition >= pos)this->closedPosition-=pos;
}