2 #include "el_before_after.h"
6 #include "utf8_strings.h"
8 litehtml::el_before_after_base::el_before_after_base(const std::shared_ptr
<document
>& doc
, bool before
) : html_tag(doc
)
10 m_tag
= before
? __tag_before_
: __tag_after_
;
13 void litehtml::el_before_after_base::add_style(const style
& style
)
15 html_tag::add_style(style
);
17 auto children
= m_children
;
20 const auto& content_property
= style
.get_property(_content_
);
21 if(content_property
.m_type
== prop_type_string
&& !content_property
.m_string
.empty())
23 int idx
= value_index(content_property
.m_string
, content_property_string
);
27 string::size_type i
= 0;
28 while(i
< content_property
.m_string
.length() && i
!= string::npos
)
30 if(content_property
.m_string
.at(i
) == '"' || content_property
.m_string
.at(i
) == '\'')
32 auto chr
= content_property
.m_string
.at(i
);
35 string::size_type pos
= content_property
.m_string
.find(chr
, i
);
37 if(pos
== string::npos
)
39 txt
= content_property
.m_string
.substr(i
);
43 txt
= content_property
.m_string
.substr(i
, pos
- i
);
47 } else if(content_property
.m_string
.at(i
) == '(')
52 string::size_type pos
= content_property
.m_string
.find(')', i
);
54 if(pos
== string::npos
)
56 params
= content_property
.m_string
.substr(i
);
60 params
= content_property
.m_string
.substr(i
, pos
- i
);
63 add_function(fnc
, params
);
67 fnc
+= content_property
.m_string
.at(i
);
74 if(m_children
.empty())
76 m_children
= children
;
80 void litehtml::el_before_after_base::add_text( const string
& txt
)
88 !esc
.empty() && esc
.length() < 5 && (chr
>= '0' && chr
<= '9' || chr
>= 'A' && chr
<= 'Z' || chr
>= 'a' && chr
<= 'z'))
90 if(!esc
.empty() && chr
== '\\')
92 word
+= convert_escape(esc
.c_str() + 1);
100 word
+= convert_escape(esc
.c_str() + 1);
107 element::ptr el
= std::make_shared
<el_text
>(word
.c_str(), get_document());
112 element::ptr el
= std::make_shared
<el_space
>(word
.c_str(), get_document());
124 word
+= convert_escape(esc
.c_str() + 1);
128 element::ptr el
= std::make_shared
<el_text
>(word
.c_str(), get_document());
134 void litehtml::el_before_after_base::add_function( const string
& fnc
, const string
& params
)
136 int idx
= value_index(fnc
, "attr;counter;url");
142 string p_name
= params
;
145 element::ptr el_parent
= parent();
148 const char* attr_value
= el_parent
->get_attr(p_name
.c_str());
151 add_text(attr_value
);
162 string p_url
= params
;
166 if(p_url
.at(0) == '\'' || p_url
.at(0) == '\"')
173 if(p_url
.at(p_url
.length() - 1) == '\'' || p_url
.at(p_url
.length() - 1) == '\"')
175 p_url
.erase(p_url
.length() - 1, 1);
180 element::ptr el
= std::make_shared
<el_image
>(get_document());
181 el
->set_attr("src", p_url
.c_str());
182 el
->set_attr("style", "display:inline-block");
183 el
->set_tagName("img");
185 el
->parse_attributes();
192 litehtml::string
litehtml::el_before_after_base::convert_escape( const char* txt
)
196 u_str
[0] = (wchar_t) strtol(txt
, &str_end
, 16);
198 return litehtml::string(litehtml_from_wchar(u_str
));