to-*-case() shouldn't be Unicode-aware.

This commit is contained in:
Natalie Weizenbaum 2016-10-18 18:30:00 -07:00
parent d38722e36d
commit 358fd0db50
2 changed files with 23 additions and 2 deletions

View File

@ -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

View File

@ -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;