Fix parsing css selectors with commas

feature/develop-atys
Nimetu 4 years ago
parent 95cacf75a6
commit db7afb07bd

@ -73,7 +73,7 @@ namespace NLGUI
void preprocess();
// parse selectors + combinators
std::vector<CCssSelector> parse_selector(const std::string &sel, std::string &pseudoElement) const;
std::vector<CCssSelector> parse_selector(const std::string &sel, std::string &pseudoElement, std::string::size_type &pos) const;
// parse selector and style
void parseRule(const std::string &selectorString, const std::string &styleString);

@ -98,25 +98,22 @@ namespace NLGUI
// @internal
void CCssParser::parseRule(const std::string &selectorString, const std::string &styleString)
{
std::vector<std::string> selectors;
NLMISC::explode(selectorString, std::string(","), selectors);
TStyleVec props;
props = parseDecls(styleString);
// duplicate props to each selector in selector list,
// example 'div > p, h1' creates 'div>p' and 'h1'
for(uint i=0; i<selectors.size(); ++i)
for(std::string::size_type pos = 0; pos < selectorString.size(); pos++)
{
CCssStyle::SStyleRule rule;
while(pos < selectorString.size() && is_whitespace(selectorString[pos]))
pos++;
rule.Selector = parse_selector(trim(selectors[i]), rule.PseudoElement);
CCssStyle::SStyleRule rule;
rule.Selector = parse_selector(selectorString, rule.PseudoElement, pos);
rule.Properties = props;
if (!rule.Selector.empty())
{
_Rules.push_back(rule);
}
}
}
@ -345,7 +342,7 @@ namespace NLGUI
// ***************************************************************************
// parse selector list
// @internal
std::vector<CCssSelector> CCssParser::parse_selector(const std::string &sel, std::string &pseudoElement) const
std::vector<CCssSelector> CCssParser::parse_selector(const std::string &sel, std::string &pseudoElement, std::string::size_type &pos) const
{
std::vector<CCssSelector> result;
CCssSelector current;
@ -353,8 +350,8 @@ namespace NLGUI
pseudoElement.clear();
bool failed = false;
std::string::size_type start = 0, pos = 0;
while(pos < sel.size())
std::string::size_type start = pos;
while(pos < sel.size() && sel[pos] != ',')
{
std::string uc;
uc = sel[pos];
@ -624,6 +621,7 @@ namespace NLGUI
}
else if (isSpace)
{
if (sel[pos] != ',' && sel[pos] != '\0')
current.Combinator = ' ';
}
else

Loading…
Cancel
Save