String
createName(String input)
Source
static String createName(String input) {
var out = new StringBuffer();
cu(String n) => const Utf8Encoder().convert(n)[0];
mainLoop: for (var i = 0; i < input.length; i++) {
String char = input[i];
if (char == "%" && (i + 1 < input.length)) {
String hexA = input[i + 1].toUpperCase();
if ((cu(hexA) >= cu("0") && cu(hexA) <= cu("9")) ||
(cu(hexA) >= cu("A") && cu(hexA) <= cu("F"))
) {
if (i + 2 < input.length) {
String hexB = input[i + 2].toUpperCase();
if ((cu(hexB) > cu("0") && cu(hexB) <= cu("9")) ||
(cu(hexB) >= cu("A") && cu(hexB) <= cu("F"))
) {
i += 2;
out.write("%");
out.write(hexA);
out.write(hexB);
continue;
} else {
++i;
out.write("%${hexA}");
continue;
}
}
}
}
for (String bannedChar in BANNED_CHARS) {
if (char == bannedChar) {
var e = char.codeUnitAt(0).toRadixString(16);
out.write("%${e}".toUpperCase());
continue mainLoop;
}
}
out.write(char);
}
return out.toString();
}