v10.js 1.4 KB

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