Skip to content

Commit df2bfd0

Browse files
committed
Merge pull request #1592 from xzyfer/fix/issue-1574
Fix operator overloading for attribute selectors
2 parents d44cae0 + 160de51 commit df2bfd0

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/ast.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,21 @@ namespace Sass {
205205

206206
bool Simple_Selector::operator== (const Simple_Selector& rhs) const
207207
{
208+
const Attribute_Selector* ll = dynamic_cast<const Attribute_Selector*>(this);
209+
const Attribute_Selector* rr = dynamic_cast<const Attribute_Selector*>(&rhs);
210+
if (ll && rr) return *ll == *rr;
211+
208212
if (is_ns_eq(ns(), rhs.ns()))
209213
{ return name() == rhs.name(); }
210214
return ns() == rhs.ns();
211215
}
212216

213217
bool Simple_Selector::operator< (const Simple_Selector& rhs) const
214218
{
219+
const Attribute_Selector* ll = dynamic_cast<const Attribute_Selector*>(this);
220+
const Attribute_Selector* rr = dynamic_cast<const Attribute_Selector*>(&rhs);
221+
if (ll && rr) return *ll < *rr;
222+
215223
if (is_ns_eq(ns(), rhs.ns()))
216224
{ return name() < rhs.name(); }
217225
return ns() < rhs.ns();
@@ -423,6 +431,47 @@ namespace Sass {
423431
return Simple_Selector::unify_with(rhs, ctx);
424432
}
425433

434+
bool Attribute_Selector::operator< (const Attribute_Selector& rhs) const
435+
{
436+
if (is_ns_eq(ns(), rhs.ns())) {
437+
if (name() == rhs.name()) {
438+
if (matcher() == rhs.matcher()) {
439+
return value() < rhs.value();
440+
} else { return matcher() < rhs.matcher(); }
441+
} else { return name() < rhs.name(); }
442+
}
443+
else return false;
444+
}
445+
446+
bool Attribute_Selector::operator< (const Simple_Selector& rhs) const
447+
{
448+
if (const Attribute_Selector* w = dynamic_cast<const Attribute_Selector*>(&rhs))
449+
{
450+
return *this < *w;
451+
}
452+
if (is_ns_eq(ns(), rhs.ns()))
453+
{ return name() < rhs.name(); }
454+
return ns() < rhs.ns();
455+
}
456+
457+
bool Attribute_Selector::operator== (const Attribute_Selector& rhs) const
458+
{
459+
if (is_ns_eq(ns(), rhs.ns()) && name() == rhs.name())
460+
{ return matcher() == rhs.matcher() && value() == rhs.value(); }
461+
else return false;
462+
}
463+
464+
bool Attribute_Selector::operator== (const Simple_Selector& rhs) const
465+
{
466+
if (const Attribute_Selector* w = dynamic_cast<const Attribute_Selector*>(&rhs))
467+
{
468+
return *this == *w;
469+
}
470+
if (is_ns_eq(ns(), rhs.ns()))
471+
{ return name() == rhs.name(); }
472+
return ns() == rhs.ns();
473+
}
474+
426475
bool Wrapped_Selector::operator== (const Wrapped_Selector& rhs) const
427476
{
428477
if (is_ns_eq(ns(), rhs.ns()) && name() == rhs.name())

src/ast.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,10 @@ namespace Sass {
19261926
{
19271927
return Constants::Specificity_Attr;
19281928
}
1929+
bool operator==(const Simple_Selector& rhs) const;
1930+
bool operator==(const Attribute_Selector& rhs) const;
1931+
bool operator<(const Simple_Selector& rhs) const;
1932+
bool operator<(const Attribute_Selector& rhs) const;
19291933
ATTACH_OPERATIONS()
19301934
};
19311935

0 commit comments

Comments
 (0)