v8.js 1.6 KB

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