mirror of
https://github.com/danog/dart-sass.git
synced 2024-11-30 04:39:03 +01:00
Make underscores and dashes equal.
This commit is contained in:
parent
113b4787ed
commit
77dd5c1e84
@ -3,12 +3,13 @@
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
import 'value.dart';
|
||||
import 'utils.dart';
|
||||
|
||||
class Environment {
|
||||
/// Base is global scope.
|
||||
final _variables = [<String, Value>{}];
|
||||
final _variables = [separatorIndependentMap/*<Value>*/()];
|
||||
|
||||
final _variableIndices = <String, int>{};
|
||||
final _variableIndices = separatorIndependentMap/*<int>*/();
|
||||
|
||||
Value getVariable(String name) =>
|
||||
_variables[_variableIndices[name] ?? 0][name];
|
||||
|
@ -58,13 +58,49 @@ String unvendor(String name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
bool equalsIgnoreSeparator(String string1, String string2) {
|
||||
print("eis: $string1 $string2");
|
||||
if (identical(string1, string2)) return true;
|
||||
if (string1 == null || string2 == null) return false;
|
||||
if (string1.length != string2.length) return false;
|
||||
for (var i = 0; i < string1.length; i++) {
|
||||
var codeUnit1 = string1.codeUnitAt(i);
|
||||
var codeUnit2 = string2.codeUnitAt(i);
|
||||
if (codeUnit1 == codeUnit2) continue;
|
||||
if (codeUnit1 == $dash) {
|
||||
if (codeUnit2 != $underscore) return false;
|
||||
} else if (codeUnit1 == $underscore) {
|
||||
if (codeUnit2 != $dash) return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int hashCodeIgnoreSeparator(String string) {
|
||||
var hash = 4603;
|
||||
for (var i = 0; i < string.length; i++) {
|
||||
var codeUnit = string.codeUnitAt(i);
|
||||
if (codeUnit == $underscore) codeUnit = $dash;
|
||||
hash &= 0x3FFFFFF;
|
||||
hash *= 33;
|
||||
hash ^= codeUnit;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
bool equalsIgnoreCase(String string1, String string2) {
|
||||
if (string1 == null) return string2 == null;
|
||||
if (string2 == null) return false;
|
||||
if (identical(string1, string2)) return true;
|
||||
if (string1 == null || string2 == null) return false;
|
||||
if (string1.length != string2.length) return false;
|
||||
return string1.toUpperCase() == string2.toUpperCase();
|
||||
}
|
||||
|
||||
Map/*<V>*/ separatorIndependentMap/*<V>*/() =>
|
||||
new LinkedHashMap(
|
||||
equals: equalsIgnoreSeparator, hashCode: hashCodeIgnoreSeparator);
|
||||
|
||||
bool almostEquals(num number1, num number2) =>
|
||||
(number1 - number2).abs() < _epsilon;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user