Skip to content

Commit

Permalink
Merge pull request #598 from xzyfer/feat/interop-as-map-key
Browse files Browse the repository at this point in the history
Add support for interpolated strings as map keys
  • Loading branch information
xzyfer committed Oct 30, 2014
2 parents 5fc015c + 0cdc4db commit 7a381b8
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1203,12 +1203,40 @@ namespace Sass {
///////////////////////////////////////////////////////////////////////
class String_Schema : public String, public Vectorized<Expression*> {
ADD_PROPERTY(char, quote_mark);
size_t hash_;
public:
String_Schema(string path, Position position, size_t size = 0, bool unq = false, char qm = '\0')
: String(path, position, unq), Vectorized<Expression*>(size), quote_mark_(qm)
: String(path, position, unq), Vectorized<Expression*>(size), quote_mark_(qm), hash_(0)
{ }
string type() { return "string"; }
static string type_name() { return "string"; }

virtual bool operator==(Expression& rhs) const
{
try
{
String_Schema& e = dynamic_cast<String_Schema&>(rhs);
if (!(e && length() == e.length())) return false;
for (size_t i = 0, L = length(); i < L; ++i)
if (!((*this)[i] == e[i])) return false;
return true;
}
catch (std::bad_cast&)
{
return false;
}
}

virtual size_t hash()
{
if (hash_ > 0) return hash_;

for (auto string : elements())
hash_ ^= string->hash();

return hash_;
}

ATTACH_OPERATIONS();
};

Expand Down

0 comments on commit 7a381b8

Please sign in to comment.