Commit 11a8906f by Aaron Leung

Moved the less-than node comparison over to the refactored version.

parent c73a1b9d
#include <sstream> #include <sstream>
#include "node.hpp" #include "node.hpp"
#include "error.hpp"
namespace Sass { namespace Sass {
using namespace std; using namespace std;
...@@ -61,8 +62,32 @@ namespace Sass { ...@@ -61,8 +62,32 @@ namespace Sass {
return true; return true;
} break; } break;
} }
return false;
} }
bool Node::operator<(Node rhs) const
{
Type lhs_type = type();
Type rhs_type = rhs.type();
if (lhs_type == number && rhs_type == number ||
lhs_type == numeric_percentage && rhs_type == numeric_percentage) {
return numeric_value() < rhs.numeric_value();
}
else if (lhs_type == numeric_dimension && rhs_type == numeric_dimension) {
if (unit() == rhs.unit()) {
return numeric_value() < rhs.numeric_value();
}
else {
throw Error(Error::evaluation, line_number(), file_name(), "incompatible units");
}
}
else {
throw Error(Error::evaluation, line_number(), file_name(), "incomparable types");
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Token method implementations // Token method implementations
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
...@@ -150,11 +175,11 @@ namespace Sass { ...@@ -150,11 +175,11 @@ namespace Sass {
const char* last2 = rhs.end; const char* last2 = rhs.end;
while (first1!=last1) while (first1!=last1)
{ {
if (first2==last2 || *first2<*first1) return false; if (first2 == last2 || *first2 < *first1) return false;
else if (*first1<*first2) return true; else if (*first1 < *first2) return true;
first1++; first2++; ++first1; ++first2;
} }
return (first2!=last2); return (first2 != last2);
} }
bool Token::operator==(const Token& rhs) const bool Token::operator==(const Token& rhs) const
......
...@@ -180,6 +180,7 @@ namespace Sass { ...@@ -180,6 +180,7 @@ namespace Sass {
Token unit() const; Token unit() const;
bool operator==(Node rhs) const; bool operator==(Node rhs) const;
bool operator<(Node rhs) const;
}; };
struct Node_Impl { struct Node_Impl {
......
...@@ -36,5 +36,8 @@ int main() ...@@ -36,5 +36,8 @@ int main()
cout << (num == num2) << endl; cout << (num == num2) << endl;
cout << (num == num3) << endl << endl; cout << (num == num3) << endl << endl;
cout << (num3[2] < num2[2]) << endl;
cout << (num2[3] < num3[3]) << endl << endl;
return 0; return 0;
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment