Added: Case compare flag to attribute selector
--HG-- branch : develop
This commit is contained in:
parent
e6aa13258b
commit
12fb7af8b7
3 changed files with 34 additions and 19 deletions
|
@ -43,8 +43,9 @@ namespace NLGUI
|
||||||
std::string key;
|
std::string key;
|
||||||
std::string value;
|
std::string value;
|
||||||
char op; // =, ~, |, ^, $, *
|
char op; // =, ~, |, ^, $, *
|
||||||
SAttribute(const std::string &k, const std::string &v, char o)
|
bool caseSensitive;
|
||||||
:key(k),value(v),op(o)
|
SAttribute(const std::string &k, const std::string &v, char o, bool cs)
|
||||||
|
:key(k),value(v),op(o), caseSensitive(cs)
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -69,7 +70,8 @@ namespace NLGUI
|
||||||
|
|
||||||
// add attribute to selector
|
// add attribute to selector
|
||||||
// ' ' op means 'key exists, ignore value'
|
// ' ' op means 'key exists, ignore value'
|
||||||
void addAttribute(const std::string &key, const std::string &val = "", char op = ' ');
|
// cs case-sensitive true|false
|
||||||
|
void addAttribute(const std::string &key, const std::string &val = "", char op = ' ', bool cs = true);
|
||||||
|
|
||||||
// add pseudo class to selector, eg 'first-child'
|
// add pseudo class to selector, eg 'first-child'
|
||||||
void addPseudoClass(const std::string &key);
|
void addPseudoClass(const std::string &key);
|
||||||
|
|
|
@ -463,7 +463,7 @@ namespace NLGUI
|
||||||
{
|
{
|
||||||
if (sel[pos] == '\'' || sel[pos] == '"')
|
if (sel[pos] == '\'' || sel[pos] == '"')
|
||||||
{
|
{
|
||||||
// value is quoted
|
// skip over quoted value
|
||||||
start = pos;
|
start = pos;
|
||||||
pos++;
|
pos++;
|
||||||
while(pos < sel.size() && sel[pos] != sel[start])
|
while(pos < sel.size() && sel[pos] != sel[start])
|
||||||
|
@ -476,9 +476,6 @@ namespace NLGUI
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos == sel.size()) break;
|
if (pos == sel.size()) break;
|
||||||
|
|
||||||
value = sel.substr(start + 1, pos - start - 1);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
else if (sel[pos] == '\\')
|
else if (sel[pos] == '\\')
|
||||||
{
|
{
|
||||||
|
@ -486,7 +483,6 @@ namespace NLGUI
|
||||||
}
|
}
|
||||||
else if (!quote && sel[pos] == ']')
|
else if (!quote && sel[pos] == ']')
|
||||||
{
|
{
|
||||||
// unquoted value
|
|
||||||
value = sel.substr(start, pos - start);
|
value = sel.substr(start, pos - start);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -494,17 +490,20 @@ namespace NLGUI
|
||||||
pos++;
|
pos++;
|
||||||
} // while 'value'
|
} // while 'value'
|
||||||
|
|
||||||
// TODO: scan for sel[pos] == ']'
|
|
||||||
if (pos == sel.size()) break;
|
|
||||||
// whitespace between quote and ], ie '[ attr $= "val" ]'
|
|
||||||
if (sel[pos] != ']')
|
|
||||||
{
|
|
||||||
while(pos < sel.size() && sel[pos] != ']')
|
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
if (pos == sel.size()) break;
|
if (pos == sel.size()) break;
|
||||||
|
|
||||||
current.addAttribute(key.toUtf8(), value.toUtf8(), (char)op);
|
bool cs = true;
|
||||||
|
// [value="attr" i]
|
||||||
|
if (value.size() > 2 && value[value.size()-2] == ' ')
|
||||||
|
{
|
||||||
|
ucchar lastChar = value[value.size()-1];
|
||||||
|
if (lastChar == 'i' || lastChar == 'I' || lastChar == 's' || lastChar == 'S')
|
||||||
|
{
|
||||||
|
value = value.substr(0, value.size()-2);
|
||||||
|
cs = !((lastChar == 'i' || lastChar == 'I'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
current.addAttribute(key.toUtf8(), trimQuotes(value).toUtf8(), (char)op, cs);
|
||||||
} // op error
|
} // op error
|
||||||
} // no value
|
} // no value
|
||||||
|
|
||||||
|
|
|
@ -71,9 +71,17 @@ namespace NLGUI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCssSelector::addAttribute(const std::string &key, const std::string &val, char op)
|
void CCssSelector::addAttribute(const std::string &key, const std::string &val, char op, bool cs)
|
||||||
{
|
{
|
||||||
Attr.push_back(SAttribute(key, val, op));
|
if (cs)
|
||||||
|
{
|
||||||
|
// case sensitive match
|
||||||
|
Attr.push_back(SAttribute(key, val, op, cs));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Attr.push_back(SAttribute(key, toLower(val), op, cs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCssSelector::addPseudoClass(const std::string &key)
|
void CCssSelector::addPseudoClass(const std::string &key)
|
||||||
|
@ -135,6 +143,12 @@ namespace NLGUI
|
||||||
if (!elm.hasAttribute(Attr[i].key)) return false;
|
if (!elm.hasAttribute(Attr[i].key)) return false;
|
||||||
|
|
||||||
std::string value = elm.getAttribute(Attr[i].key);
|
std::string value = elm.getAttribute(Attr[i].key);
|
||||||
|
// case-insensitive compare, Attr.value is already lowercased
|
||||||
|
if (!Attr[i].caseSensitive)
|
||||||
|
{
|
||||||
|
value = toLower(value);
|
||||||
|
}
|
||||||
|
|
||||||
switch(Attr[i].op)
|
switch(Attr[i].op)
|
||||||
{
|
{
|
||||||
case '=':
|
case '=':
|
||||||
|
|
Loading…
Reference in a new issue