utf8Length function
UTF-8 编码后的字节数。
Implementation
int utf8Length(String text) {
var ascii = true;
for (var i = 0; i < text.length; i++) {
if (text.codeUnitAt(i) > 0x7f) {
ascii = false;
break;
}
}
return ascii ? text.length : utf8.encode(text).length;
}