@@ -1161,113 +1161,18 @@ namespace Sass {
1161
1161
vector<string> denominator_units_;
1162
1162
size_t hash_;
1163
1163
public:
1164
- Number (ParserState pstate, double val, string u = " " , bool zero = true )
1165
- : Expression(pstate),
1166
- value_ (val),
1167
- zero_(zero),
1168
- numerator_units_(vector<string>()),
1169
- denominator_units_(vector<string>()),
1170
- hash_(0 )
1171
- {
1172
- if (!u.empty ()) numerator_units_.push_back (u);
1173
- concrete_type (NUMBER);
1174
- }
1164
+ Number (ParserState pstate, double val, string u = " " , bool zero = true );
1175
1165
bool zero () { return zero_; }
1176
1166
vector<string>& numerator_units () { return numerator_units_; }
1177
1167
vector<string>& denominator_units () { return denominator_units_; }
1178
1168
string type () { return " number" ; }
1179
1169
static string type_name () { return " number" ; }
1180
- string unit () const
1181
- {
1182
- stringstream u;
1183
- for (size_t i = 0 , S = numerator_units_.size (); i < S; ++i) {
1184
- if (i) u << ' *' ;
1185
- u << numerator_units_[i];
1186
- }
1187
- if (!denominator_units_.empty ()) u << ' /' ;
1188
- for (size_t i = 0 , S = denominator_units_.size (); i < S; ++i) {
1189
- if (i) u << ' *' ;
1190
- u << denominator_units_[i];
1191
- }
1192
- return u.str ();
1193
- }
1194
- bool is_unitless ()
1195
- { return numerator_units_.empty () && denominator_units_.empty (); }
1196
- void normalize (string to = " " )
1197
- {
1198
- // (multiple passes because I'm too tired to think up something clever)
1199
- // Find a unit to convert everything to, if one isn't provided.
1200
- if (to.empty ()) {
1201
- for (size_t i = 0 , S = numerator_units_.size (); i < S; ++i) {
1202
- string u (numerator_units_[i]);
1203
- if (string_to_unit (u) == INCOMMENSURABLE) {
1204
- continue ;
1205
- }
1206
- else {
1207
- to = u;
1208
- break ;
1209
- }
1210
- }
1211
- }
1212
- if (to.empty ()) {
1213
- for (size_t i = 0 , S = denominator_units_.size (); i < S; ++i) {
1214
- string u (denominator_units_[i]);
1215
- if (string_to_unit (u) == INCOMMENSURABLE) {
1216
- continue ;
1217
- }
1218
- else {
1219
- to = u;
1220
- break ;
1221
- }
1222
- }
1223
- }
1224
- // Now loop through again and do all the conversions.
1225
- for (size_t i = 0 , S = numerator_units_.size (); i < S; ++i) {
1226
- string from (numerator_units_[i]);
1227
- if (string_to_unit (from) == INCOMMENSURABLE) continue ;
1228
- value_ *= conversion_factor (from, to);
1229
- numerator_units_[i] = to;
1230
- }
1231
- for (size_t i = 0 , S = denominator_units_.size (); i < S; ++i) {
1232
- string from (denominator_units_[i]);
1233
- if (string_to_unit (from) == INCOMMENSURABLE) continue ;
1234
- value_ /= conversion_factor (from, to);
1235
- denominator_units_[i] = to;
1236
- }
1237
- // Now divide out identical units in the numerator and denominator.
1238
- vector<string> ncopy;
1239
- ncopy.reserve (numerator_units_.size ());
1240
- for (vector<string>::iterator n = numerator_units_.begin ();
1241
- n != numerator_units_.end ();
1242
- ++n) {
1243
- vector<string>::iterator d = find (denominator_units_.begin (),
1244
- denominator_units_.end (),
1245
- *n);
1246
- if (d != denominator_units_.end ()) {
1247
- denominator_units_.erase (d);
1248
- }
1249
- else {
1250
- ncopy.push_back (*n);
1251
- }
1252
- }
1253
- numerator_units_ = ncopy;
1254
- // Sort the units to make them pretty and, well, normal.
1255
- sort (numerator_units_.begin (), numerator_units_.end ());
1256
- sort (denominator_units_.begin (), denominator_units_.end ());
1257
- }
1170
+ string unit () const ;
1171
+
1172
+ bool is_unitless ();
1173
+ void normalize (string to = " " );
1258
1174
// useful for making one number compatible with another
1259
- string find_convertible_unit () const
1260
- {
1261
- for (size_t i = 0 , S = numerator_units_.size (); i < S; ++i) {
1262
- string u (numerator_units_[i]);
1263
- if (string_to_unit (u) != INCOMMENSURABLE) return u;
1264
- }
1265
- for (size_t i = 0 , S = denominator_units_.size (); i < S; ++i) {
1266
- string u (denominator_units_[i]);
1267
- if (string_to_unit (u) != INCOMMENSURABLE) return u;
1268
- }
1269
- return string ();
1270
- }
1175
+ string find_convertible_unit () const ;
1271
1176
1272
1177
virtual bool operator ==(Expression& rhs) const
1273
1178
{
0 commit comments