v5.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.default = (uint8, start, length) => {
  4. const end = start + length;
  5. let x = start;
  6. let str = '';
  7. while (x < end) {
  8. const b1 = uint8[x++];
  9. if ((b1 & 0x80) === 0) {
  10. str += String.fromCharCode(b1);
  11. continue;
  12. }
  13. else if ((b1 & 0xe0) === 0xc0) {
  14. str += String.fromCharCode(((b1 & 0x1f) << 6) | (uint8[x++] & 0x3f));
  15. }
  16. else if ((b1 & 0xf0) === 0xe0) {
  17. str += String.fromCharCode(((b1 & 0x1f) << 12) | ((uint8[x++] & 0x3f) << 6) | (uint8[x++] & 0x3f));
  18. }
  19. else if ((b1 & 0xf8) === 0xf0) {
  20. const b2 = uint8[x++] & 0x3f;
  21. const b3 = uint8[x++] & 0x3f;
  22. const b4 = uint8[x++] & 0x3f;
  23. let code = ((b1 & 0x07) << 0x12) | (b2 << 0x0c) | (b3 << 0x06) | b4;
  24. if (code > 0xffff) {
  25. code -= 0x10000;
  26. str += String.fromCharCode(((code >>> 10) & 0x3ff) | 0xd800);
  27. code = 0xdc00 | (code & 0x3ff);
  28. }
  29. str += String.fromCharCode(code);
  30. }
  31. else {
  32. str += String.fromCharCode(b1);
  33. }
  34. }
  35. return str;
  36. };
  37. //# sourceMappingURL=v5.js.map