mirror of
https://github.com/danog/dart-sass.git
synced 2025-01-23 06:12:00 +01:00
to-*-case() shouldn't be Unicode-aware.
This commit is contained in:
parent
d38722e36d
commit
358fd0db50
@ -11,6 +11,7 @@ import 'callable.dart';
|
||||
import 'environment.dart';
|
||||
import 'exception.dart';
|
||||
import 'extend/extender.dart';
|
||||
import 'util/character.dart';
|
||||
import 'util/number.dart';
|
||||
import 'utils.dart';
|
||||
import 'value.dart';
|
||||
@ -505,12 +506,20 @@ void defineCoreFunctions(Environment environment) {
|
||||
|
||||
environment.defineFunction("to-upper-case", r"$string", (arguments) {
|
||||
var string = arguments[0].assertString("string");
|
||||
return new SassString(string.text.toUpperCase(), quotes: string.hasQuotes);
|
||||
var buffer = new StringBuffer();
|
||||
for (var i = 0; i < string.text.length; i++) {
|
||||
buffer.writeCharCode(toUpperCase(string.text.codeUnitAt(i)));
|
||||
}
|
||||
return new SassString(buffer.toString(), quotes: string.hasQuotes);
|
||||
});
|
||||
|
||||
environment.defineFunction("to-lower-case", r"$string", (arguments) {
|
||||
var string = arguments[0].assertString("string");
|
||||
return new SassString(string.text.toLowerCase(), quotes: string.hasQuotes);
|
||||
var buffer = new StringBuffer();
|
||||
for (var i = 0; i < string.text.length; i++) {
|
||||
buffer.writeCharCode(toLowerCase(string.text.codeUnitAt(i)));
|
||||
}
|
||||
return new SassString(buffer.toString(), quotes: string.hasQuotes);
|
||||
});
|
||||
|
||||
// ## Numbers
|
||||
|
@ -106,6 +106,18 @@ int opposite(int character) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns [character], converted to upper case if it's an ASCII lowercase
|
||||
/// letter.
|
||||
int toUpperCase(int character) => (character >= $a && character <= $z)
|
||||
? character | _asciiCaseBit
|
||||
: character;
|
||||
|
||||
/// Returns [character], converted to lower case if it's an ASCII uppercase
|
||||
/// letter.
|
||||
int toLowerCase(int character) => (character >= $A && character <= $Z)
|
||||
? character & ~_asciiCaseBit
|
||||
: character;
|
||||
|
||||
/// Returns whether [character1] and [character2] are the same, modulo ASCII case.
|
||||
bool characterEqualsIgnoreCase(int character1, int character2) {
|
||||
if (character1 == character2) return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user