Skip to content

Commit

Permalink
Merge pull request #1592 from xzyfer/fix/issue-1574
Browse files Browse the repository at this point in the history
Fix operator overloading for attribute selectors
  • Loading branch information
xzyfer committed Oct 11, 2015
2 parents d44cae0 + 160de51 commit df2bfd0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,21 @@ namespace Sass {

bool Simple_Selector::operator== (const Simple_Selector& rhs) const
{
const Attribute_Selector* ll = dynamic_cast<const Attribute_Selector*>(this);
const Attribute_Selector* rr = dynamic_cast<const Attribute_Selector*>(&rhs);
if (ll && rr) return *ll == *rr;

if (is_ns_eq(ns(), rhs.ns()))
{ return name() == rhs.name(); }
return ns() == rhs.ns();
}

bool Simple_Selector::operator< (const Simple_Selector& rhs) const
{
const Attribute_Selector* ll = dynamic_cast<const Attribute_Selector*>(this);
const Attribute_Selector* rr = dynamic_cast<const Attribute_Selector*>(&rhs);
if (ll && rr) return *ll < *rr;

if (is_ns_eq(ns(), rhs.ns()))
{ return name() < rhs.name(); }
return ns() < rhs.ns();
Expand Down Expand Up @@ -423,6 +431,47 @@ namespace Sass {
return Simple_Selector::unify_with(rhs, ctx);
}

bool Attribute_Selector::operator< (const Attribute_Selector& rhs) const
{
if (is_ns_eq(ns(), rhs.ns())) {
if (name() == rhs.name()) {
if (matcher() == rhs.matcher()) {
return value() < rhs.value();
} else { return matcher() < rhs.matcher(); }
} else { return name() < rhs.name(); }
}
else return false;
}

bool Attribute_Selector::operator< (const Simple_Selector& rhs) const
{
if (const Attribute_Selector* w = dynamic_cast<const Attribute_Selector*>(&rhs))
{
return *this < *w;
}
if (is_ns_eq(ns(), rhs.ns()))
{ return name() < rhs.name(); }
return ns() < rhs.ns();
}

bool Attribute_Selector::operator== (const Attribute_Selector& rhs) const
{
if (is_ns_eq(ns(), rhs.ns()) && name() == rhs.name())
{ return matcher() == rhs.matcher() && value() == rhs.value(); }
else return false;
}

bool Attribute_Selector::operator== (const Simple_Selector& rhs) const
{
if (const Attribute_Selector* w = dynamic_cast<const Attribute_Selector*>(&rhs))
{
return *this == *w;
}
if (is_ns_eq(ns(), rhs.ns()))
{ return name() == rhs.name(); }
return ns() == rhs.ns();
}

bool Wrapped_Selector::operator== (const Wrapped_Selector& rhs) const
{
if (is_ns_eq(ns(), rhs.ns()) && name() == rhs.name())
Expand Down
4 changes: 4 additions & 0 deletions src/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,10 @@ namespace Sass {
{
return Constants::Specificity_Attr;
}
bool operator==(const Simple_Selector& rhs) const;
bool operator==(const Attribute_Selector& rhs) const;
bool operator<(const Simple_Selector& rhs) const;
bool operator<(const Attribute_Selector& rhs) const;
ATTACH_OPERATIONS()
};

Expand Down

0 comments on commit df2bfd0

Please sign in to comment.