isUtf8.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.isUtf8 = void 0;
  4. const tslib_1 = require("tslib");
  5. tslib_1.__exportStar(require("@jsonjoy.com/buffers/lib/utf8/isUtf8"), exports);
  6. const isUtf8 = (buf, from, length) => {
  7. const to = from + length;
  8. while (from < to) {
  9. const c = buf[from];
  10. if (c <= 0x7f) {
  11. from++;
  12. continue;
  13. }
  14. if (c >= 0xc2 && c <= 0xdf) {
  15. if (buf[from + 1] >> 6 === 2) {
  16. from += 2;
  17. continue;
  18. }
  19. else
  20. return false;
  21. }
  22. const c1 = buf[from + 1];
  23. if (((c === 0xe0 && c1 >= 0xa0 && c1 <= 0xbf) || (c === 0xed && c1 >= 0x80 && c1 <= 0x9f)) &&
  24. buf[from + 2] >> 6 === 2) {
  25. from += 3;
  26. continue;
  27. }
  28. if (((c >= 0xe1 && c <= 0xec) || (c >= 0xee && c <= 0xef)) && c1 >> 6 === 2 && buf[from + 2] >> 6 === 2) {
  29. from += 3;
  30. continue;
  31. }
  32. if (((c === 0xf0 && c1 >= 0x90 && c1 <= 0xbf) ||
  33. (c >= 0xf1 && c <= 0xf3 && c1 >> 6 === 2) ||
  34. (c === 0xf4 && c1 >= 0x80 && c1 <= 0x8f)) &&
  35. buf[from + 2] >> 6 === 2 &&
  36. buf[from + 3] >> 6 === 2) {
  37. from += 4;
  38. continue;
  39. }
  40. return false;
  41. }
  42. return true;
  43. };
  44. exports.isUtf8 = isUtf8;
  45. //# sourceMappingURL=isUtf8.js.map