Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sass
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
楚学文
node-sass
Commits
5da2cd2e
Commit
5da2cd2e
authored
Apr 10, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Comparison operators for nodes. Necessary for Sass conditionals and selector inheritance.
parent
c6394df2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
103 additions
and
0 deletions
+103
-0
node_comparisons.cpp
node_comparisons.cpp
+103
-0
No files found.
node_comparisons.cpp
0 → 100644
View file @
5da2cd2e
#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include "node.hpp"
using
std
::
string
;
using
std
::
stringstream
;
using
std
::
cout
;
using
std
::
cerr
;
using
std
::
endl
;
namespace
Sass
{
bool
Node
::
operator
==
(
const
Node
&
rhs
)
const
{
if
(
type
!=
rhs
.
type
)
return
false
;
switch
(
type
)
{
case
comma_list
:
case
space_list
:
case
expression
:
case
term
:
{
for
(
int
i
=
0
;
i
<
size
();
++
i
)
{
if
(
at
(
i
)
==
rhs
[
i
])
continue
;
else
return
false
;
}
return
true
;
}
break
;
case
identifier
:
case
uri
:
case
textual_percentage
:
case
textual_dimension
:
case
textual_number
:
case
textual_hex
:
case
string_constant
:
{
return
content
.
token
.
unquote
()
==
rhs
.
content
.
token
.
unquote
();
}
break
;
case
number
:
case
numeric_percentage
:
{
return
numeric_value
()
==
rhs
.
numeric_value
();
}
break
;
case
numeric_dimension
:
{
if
(
Token
::
make
(
content
.
dimension
.
unit
,
Prelexer
::
identifier
(
content
.
dimension
.
unit
))
==
Token
::
make
(
rhs
.
content
.
dimension
.
unit
,
Prelexer
::
identifier
(
rhs
.
content
.
dimension
.
unit
)))
{
return
numeric_value
()
==
rhs
.
numeric_value
();
}
else
{
return
false
;
}
}
break
;
case
boolean
:
{
return
content
.
boolean_value
==
rhs
.
content
.
boolean_value
;
}
break
;
default
:
{
return
true
;
}
break
;
}
}
bool
Node
::
operator
!=
(
const
Node
&
rhs
)
const
{
return
!
(
*
this
==
rhs
);
}
bool
Node
::
operator
<
(
const
Node
&
rhs
)
const
{
if
(
type
==
number
&&
rhs
.
type
==
number
||
type
==
numeric_percentage
&&
rhs
.
type
==
numeric_percentage
)
{
return
numeric_value
()
<
rhs
.
numeric_value
();
}
else
if
(
type
==
numeric_dimension
&&
rhs
.
type
==
numeric_dimension
)
{
if
(
Token
::
make
(
content
.
dimension
.
unit
,
Prelexer
::
identifier
(
content
.
dimension
.
unit
))
==
Token
::
make
(
rhs
.
content
.
dimension
.
unit
,
Prelexer
::
identifier
(
rhs
.
content
.
dimension
.
unit
)))
{
return
numeric_value
()
<
rhs
.
numeric_value
();
}
else
{
// TO DO: throw an exception ("units don't match")
}
}
else
{
// TO DO: throw an exception ("incomparable types")
}
}
bool
Node
::
operator
<=
(
const
Node
&
rhs
)
const
{
return
*
this
<
rhs
||
*
this
==
rhs
;
}
bool
Node
::
operator
>
(
const
Node
&
rhs
)
const
{
return
!
(
*
this
<=
rhs
);
}
bool
Node
::
operator
>=
(
const
Node
&
rhs
)
const
{
return
!
(
*
this
<
rhs
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment