-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCSSselector.cpp
More file actions
352 lines (282 loc) · 8.79 KB
/
CSSselector.cpp
File metadata and controls
352 lines (282 loc) · 8.79 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*
* Name: CSS API
* Description: C++ for CSS Logic
* Web: <www/.themindspot/.com>
*
* Company: The Mind Company
*
* File: CSStag.cpp
* Author: Brandon L. Clark
*
* 2013 | All rights reserved unless authorized.
*/
#include "CSSselector.h"
CSSselector::CSSselector() {}
CSSselector::CSSselector(int type, std::string name) : CSStag(type, name) {insertSelector();}
CSSselector::CSSselector(int type, int group, std::string name) : CSStag(type, group, name) {insertSelector();}
CSSselector::CSSselector(int type, int group, int connected, std::string name) : CSStag(type, group, connected, name) {insertSelector();}
CSSselector::~CSSselector() {}
void CSSselector::setSelector(CSStag tag) {
tagContainer.clear();
setTag(tag.getTag());
CSStag::setTagExtend(1);
insertSelector();
clearTag();
}
void CSSselector::setSelector(int type, std::string name) {
tagContainer.clear();
CSStag::setTag(type, name);
CSStag::setTagExtend(1);
insertSelector();
clearTag();
}
void CSSselector::setSelectorContainer(std::vector<CSStag> container) {
tagContainer.clear();
tagContainer.insert(tagContainer.begin(), container.begin(), container.end());
}
void CSSselector::selector(CSStag tag) {
int group = tag.getTagGroup();
int previousGroup = tagContainer.back().getTagGroup();
int connected = tag.getTagConnected();
int previousConnected = tagContainer.back().getTagType();
// If group and connection is set in tag, see if it applies to current selector.
if (group != 0 && group <= previousGroup){ group = previousGroup + 1;}
if (group == previousGroup){ connected = previousConnected;}
CSStag::setTag(tag.getTagType(), group, connected, tag.getTagName());
insertSelector();
clearTag();
}
void CSSselector::selector(std::string name) {
int group = 0;
int connected = 0;
// Check previous tag to see if it applies to this one.
if (tagContainer.size() != 0){
group = tagContainer.back().getTagGroup() + 1;
connected = tagContainer.back().getTagType();
}
CSStag::setTag(0, group, connected, name);
insertSelector();
clearTag();
}
void CSSselector::selector(int type, std::string name) {
int group = 0;
int connected = 0;
// Check previous tag to see if it applies to this one.
if (tagContainer.size() != 0){
group = tagContainer.back().getTagGroup() + 1;
connected = tagContainer.back().getTagType();
}
CSStag::setTag(type, group, connected, name);
insertSelector();
clearTag();
}
void CSSselector::nest(CSStag tag) {
int group = tag.getTagGroup();
int previousGroup = tagContainer.back().getTagGroup();
int connected = tag.getTagConnected();
int previousConnected = tagContainer.back().getTagType();
// If group and connection is set in tag, see if it applies to current selector.
if (group != 0 && group <= previousGroup){ group = previousGroup + 1;}
if (group == previousGroup){ connected = previousConnected;}
CSStag::setTag(tag.getTagType(), group, connected, tag.getTagName());
CSStag::setTagExtend(1);
insertSelector();
clearTag();
}
void CSSselector::nest(std::string name) {
int group = 0;
int connected = 0;
// Check previous tag to see if it applies to this one.
if (tagContainer.size() != 0){
group = tagContainer.back().getTagGroup() + 1;
connected = tagContainer.back().getTagType();
}
CSStag::setTag(0, group, connected, name);
CSStag::setTagExtend(1);
insertSelector();
clearTag();
}
void CSSselector::nest(int type, std::string name) {
int group = 0;
int connected = 0;
// Check previous tag to see if it applies to this one.
if (tagContainer.size() != 0){
group = tagContainer.back().getTagGroup() + 1;
connected = tagContainer.back().getTagType();
}
CSStag::setTag(type, group, connected, name);
CSStag::setTagExtend(1);
insertSelector();
clearTag();
}
void CSSselector::pseudo(std::string name) {
int group = 0;
int connected = 0;
// Check previous tag to see if it applies to this one.
if (tagContainer.size() != 0){
group = tagContainer.back().getTagGroup() + 1;
connected = tagContainer.back().getTagType();
}
CSStag::setTag(3, group, connected, name);
CSStag::setTagExtend(1);
insertSelector();
clearTag();
}
void CSSselector::pseudo(CSStag tag) {
int group = 0;
int connected = 0;
// Check previous tag to see if it applies to this one.
if (tagContainer.size() != 0){
group = tagContainer.back().getTagGroup() + 1;
connected = tagContainer.back().getTagType();
}
CSStag::setTag(3, group, connected, tag.getTagName());
CSStag::setTagExtend(1);
insertSelector();
clearTag();
}
// Special case of pseudo element "::"
void CSSselector::pseudo(int type, std::string name) {
int group = 0;
int connected = 0;
// Check previous tag to see if it applies to this one.
if (tagContainer.size() != 0){
group = tagContainer.back().getTagGroup() + 1;
connected = tagContainer.back().getTagType();
}
if ( type == 1 ) {
CSStag::setTag(3, group, connected, "");
CSStag::setTagExtend(1);
insertSelector();
}
pseudo(name);
}
void CSSselector::attribute(CSSselector selector) {
int group = 0;
int connected = 0;
// Check previous tag to see if it applies to this one.
if (tagContainer.size() != 0){
group = tagContainer.back().getTagGroup() + 1;
connected = tagContainer.back().getTagType();
}
// Open attribute
CSStag::setTag(4, group, connected, "");
CSStag::setTagExtend(1);
insertSelector();
clearTag();
// Extract attribute from selector
for (int i = 0;i < (int)selector.getSelectorContainer().size(); i++){
CSStag::setTag(selector.getSelectorContainer().at(i).getTagType(), group, 4, selector.getSelectorContainer().at(i).getTagName());
if (i != 1) {CSStag::setTagExtend(selector.getSelectorContainer().at(i).getTagExtend());}
insertSelector();
clearTag();
}
// Close attribute
CSStag::setTag(5, group, connected, "");
CSStag::setTagExtend(1);
insertSelector();
clearTag();
}
void CSSselector::attribute(std::string name1, std::string comparision, std::string name2) {
int group = 0;
int connected = 0;
// Check previous tag to see if it applies to this one.
if (tagContainer.size() != 0){
group = tagContainer.back().getTagGroup() + 1;
connected = tagContainer.back().getTagType();
}
// Open attribute
CSStag::setTag(4, group, connected, "");
CSStag::setTagExtend(1);
insertSelector();
clearTag();
// Create combinator element
combinator(name1, comparision, name2);
// Close attribute
CSStag::setTag(5, group, connected, "");
CSStag::setTagExtend(1);
insertSelector();
clearTag();
}
void CSSselector::attribute(std::string name) {
int group = 0;
int connected = 0;
// Check previous tag to see if it applies to this one.
if (tagContainer.size() != 0){
group = tagContainer.back().getTagGroup() + 1;
connected = tagContainer.back().getTagType();
}
// Open attribute
CSStag::setTag(4, group, connected, "");
CSStag::setTagExtend(1);
insertSelector();
clearTag();
// Create selector element
selector(name);
// Close attribute
CSStag::setTag(5, group, connected, "");
CSStag::setTagExtend(1);
insertSelector();
clearTag();
}
void CSSselector::media(std::string name) {
// Media selector tags do not come before any other selector elements.
tagContainer.clear();
CSStag::setTag(6, name);
setTagExtend(1);
insertSelector();
clearTag();
}
void CSSselector::media(CSStag tag) {
// Media selector tags do not come before any other selector elements.
tagContainer.clear();
CSStag::setTag(6, tag.getTagName());
setTagExtend(1);
insertSelector();
clearTag();
}
// TODO combinator elements
void CSSselector::combinator(CSSselector selector) {
}
void CSSselector::combinator(std::string valueComparison) {
int group = 0;
int connected = 0;
std::string name;
name = valueComparison;
// Check previous tag to see if it applies to this one.
if (tagContainer.size() != 0){
group = tagContainer.back().getTagGroup() + 1;
connected = tagContainer.back().getTagType();
}
CSStag::setTag(7, group, connected, name);
insertSelector();
clearTag();
}
void CSSselector::combinator(std::string name1, std::string comparison, std::string name2) {
int group = 0;
int connected = 0;
std::string compare;
compare = comparison;
// Check previous tag to see if it applies to this one.
if (tagContainer.size() != 0){
group = tagContainer.back().getTagGroup() + 1;
connected = tagContainer.back().getTagType();
}
CSStag::setTag(0, group, connected, name1);
CSStag::setTagExtend(1);
insertSelector();
clearTag();
CSStag::setTag(7, group, connected, compare);
insertSelector();
clearTag();
CSStag::setTag(0, group, connected, name2);
insertSelector();
clearTag();
}
CSStag CSSselector::getSelector(int index) {
CSStag group;
group = tagContainer.at(index).getTag();
return group;
}
std::vector<CSStag> CSSselector::getSelectorContainer(void) {return tagContainer;}
void CSSselector::insertSelector(void) {if (tagContainer.size() == 0){setTagExtend(1);}tagContainer.push_back(CSStag::getTag());}