-
Notifications
You must be signed in to change notification settings - Fork 1
/
el_before_after.cpp
200 lines (188 loc) · 4.03 KB
/
el_before_after.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
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
#include "litehtml/html.h"
#include "litehtml/el_before_after.h"
#include "litehtml/el_text.h"
#include "litehtml/el_space.h"
#include "litehtml/el_image.h"
litehtml::el_before_after_base::el_before_after_base(const std::shared_ptr<litehtml::document>& doc, bool before) : html_tag(doc)
{
if(before)
{
set_tagName(_t("::before"));
} else
{
set_tagName(_t("::after"));
}
}
litehtml::el_before_after_base::~el_before_after_base()
{
}
void litehtml::el_before_after_base::add_style(const litehtml::style& st)
{
html_tag::add_style(st);
tstring content = get_style_property(_t("content"), false, _t(""));
if(!content.empty())
{
int idx = value_index(content.c_str(), content_property_string);
if(idx < 0)
{
tstring fnc;
tstring::size_type i = 0;
while(i < content.length() && i != tstring::npos)
{
if(content.at(i) == _t('"'))
{
fnc.clear();
i++;
tstring::size_type pos = content.find(_t('"'), i);
tstring txt;
if(pos == tstring::npos)
{
txt = content.substr(i);
i = tstring::npos;
} else
{
txt = content.substr(i, pos - i);
i = pos + 1;
}
add_text(txt);
} else if(content.at(i) == _t('('))
{
i++;
litehtml::trim(fnc);
litehtml::lcase(fnc);
tstring::size_type pos = content.find(_t(')'), i);
tstring params;
if(pos == tstring::npos)
{
params = content.substr(i);
i = tstring::npos;
} else
{
params = content.substr(i, pos - i);
i = pos + 1;
}
add_function(fnc, params);
fnc.clear();
} else
{
fnc += content.at(i);
i++;
}
}
}
}
}
void litehtml::el_before_after_base::add_text( const tstring& txt )
{
tstring word;
tstring esc;
for(tstring::size_type i = 0; i < txt.length(); i++)
{
if( (txt.at(i) == _t(' ')) || (txt.at(i) == _t('\t')) || (txt.at(i) == _t('\\') && !esc.empty()) )
{
if(esc.empty())
{
if(!word.empty())
{
element::ptr el = std::make_shared<el_text>(word.c_str(), get_document());
appendChild(el);
word.clear();
}
element::ptr el = std::make_shared<el_space>(txt.substr(i, 1).c_str(), get_document());
appendChild(el);
} else
{
word += convert_escape(esc.c_str() + 1);
esc.clear();
if(txt.at(i) == _t('\\'))
{
esc += txt.at(i);
}
}
} else
{
if(!esc.empty() || txt.at(i) == _t('\\'))
{
esc += txt.at(i);
} else
{
word += txt.at(i);
}
}
}
if(!esc.empty())
{
word += convert_escape(esc.c_str() + 1);
}
if(!word.empty())
{
element::ptr el = std::make_shared<el_text>(word.c_str(), get_document());
appendChild(el);
word.clear();
}
}
void litehtml::el_before_after_base::add_function( const tstring& fnc, const tstring& params )
{
int idx = value_index(fnc.c_str(), _t("attr;counter;url"));
switch(idx)
{
// attr
case 0:
{
tstring p_name = params;
trim(p_name);
lcase(p_name);
element::ptr el_parent = parent();
if (el_parent)
{
const tchar_t* attr_value = el_parent->get_attr(p_name.c_str());
if (attr_value)
{
add_text(attr_value);
}
}
}
break;
// counter
case 1:
break;
// url
case 2:
{
tstring p_url = params;
trim(p_url);
if(!p_url.empty())
{
if(p_url.at(0) == _t('\'') || p_url.at(0) == _t('\"'))
{
p_url.erase(0, 1);
}
}
if(!p_url.empty())
{
if(p_url.at(p_url.length() - 1) == _t('\'') || p_url.at(p_url.length() - 1) == _t('\"'))
{
p_url.erase(p_url.length() - 1, 1);
}
}
if(!p_url.empty())
{
element::ptr el = std::make_shared<el_image>(get_document());
el->set_attr(_t("src"), p_url.c_str());
el->set_attr(_t("style"), _t("display:inline-block"));
el->set_tagName(_t("img"));
appendChild(el);
el->parse_attributes();
}
}
break;
}
}
litehtml::tchar_t litehtml::el_before_after_base::convert_escape( const tchar_t* txt )
{
tchar_t* sss = 0;
return (tchar_t) t_strtol(txt, &sss, 16);
}
void litehtml::el_before_after_base::apply_stylesheet( const litehtml::css& stylesheet )
{
}