dutf8 static method

dynamic dutf8(
  1. List<int> d
)

Implementation

static dutf8(List<int> d) {
  for (dynamic r = '', i = 0;;) {
    int c = d[i++];
    int eb = (c > 127?1:0) + (c > 223?1:0) + (c > 239?1:0);
    if ((i + eb) > d.length){
      return [r, slc(d, i - 1)];
    }
    if (eb == 0){
      r += String.fromCharCode(c);
    }
    else if (eb == 3) {
      c = ((c & 15) << 18 | (d[i++] & 63) << 12 | (d[i++] & 63) << 6 | (d[i++] & 63)) - 65536;
      r += String.fromCharCodes([55296 | (c >> 10), 56320 | (c & 1023)]);
    }
    else if ((eb & 1) > 0){
      r += String.fromCharCode((c & 31) << 6 | (d[i++] & 63));
    }
    else{
      r += String.fromCharCode((c & 15) << 12 | (d[i++] & 63) << 6 | (d[i++] & 63));
    }
  }
}