10
0

decodeAscii.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.decodeAsciiMax15 = exports.decodeAscii = void 0;
  4. const fromCharCode = String.fromCharCode;
  5. const decodeAscii = (src, position, length) => {
  6. const bytes = [];
  7. for (let i = 0; i < length; i++) {
  8. const byte = src[position++];
  9. if (byte & 0x80)
  10. return;
  11. bytes.push(byte);
  12. }
  13. return fromCharCode.apply(String, bytes);
  14. };
  15. exports.decodeAscii = decodeAscii;
  16. const decodeAsciiMax15 = (src, position, length) => {
  17. if (length < 4) {
  18. if (length < 2) {
  19. if (length === 0)
  20. return '';
  21. else {
  22. const a = src[position++];
  23. if ((a & 0x80) > 1) {
  24. position -= 1;
  25. return;
  26. }
  27. return fromCharCode(a);
  28. }
  29. }
  30. else {
  31. const a = src[position++];
  32. const b = src[position++];
  33. if ((a & 0x80) > 0 || (b & 0x80) > 0) {
  34. position -= 2;
  35. return;
  36. }
  37. if (length < 3)
  38. return fromCharCode(a, b);
  39. const c = src[position++];
  40. if ((c & 0x80) > 0) {
  41. position -= 3;
  42. return;
  43. }
  44. return fromCharCode(a, b, c);
  45. }
  46. }
  47. else {
  48. const a = src[position++];
  49. const b = src[position++];
  50. const c = src[position++];
  51. const d = src[position++];
  52. if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
  53. position -= 4;
  54. return;
  55. }
  56. if (length < 6) {
  57. if (length === 4)
  58. return fromCharCode(a, b, c, d);
  59. else {
  60. const e = src[position++];
  61. if ((e & 0x80) > 0) {
  62. position -= 5;
  63. return;
  64. }
  65. return fromCharCode(a, b, c, d, e);
  66. }
  67. }
  68. else if (length < 8) {
  69. const e = src[position++];
  70. const f = src[position++];
  71. if ((e & 0x80) > 0 || (f & 0x80) > 0) {
  72. position -= 6;
  73. return;
  74. }
  75. if (length < 7)
  76. return fromCharCode(a, b, c, d, e, f);
  77. const g = src[position++];
  78. if ((g & 0x80) > 0) {
  79. position -= 7;
  80. return;
  81. }
  82. return fromCharCode(a, b, c, d, e, f, g);
  83. }
  84. else {
  85. const e = src[position++];
  86. const f = src[position++];
  87. const g = src[position++];
  88. const h = src[position++];
  89. if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
  90. position -= 8;
  91. return;
  92. }
  93. if (length < 10) {
  94. if (length === 8)
  95. return fromCharCode(a, b, c, d, e, f, g, h);
  96. else {
  97. const i = src[position++];
  98. if ((i & 0x80) > 0) {
  99. position -= 9;
  100. return;
  101. }
  102. return fromCharCode(a, b, c, d, e, f, g, h, i);
  103. }
  104. }
  105. else if (length < 12) {
  106. const i = src[position++];
  107. const j = src[position++];
  108. if ((i & 0x80) > 0 || (j & 0x80) > 0) {
  109. position -= 10;
  110. return;
  111. }
  112. if (length < 11)
  113. return fromCharCode(a, b, c, d, e, f, g, h, i, j);
  114. const k = src[position++];
  115. if ((k & 0x80) > 0) {
  116. position -= 11;
  117. return;
  118. }
  119. return fromCharCode(a, b, c, d, e, f, g, h, i, j, k);
  120. }
  121. else {
  122. const i = src[position++];
  123. const j = src[position++];
  124. const k = src[position++];
  125. const l = src[position++];
  126. if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
  127. position -= 12;
  128. return;
  129. }
  130. if (length < 14) {
  131. if (length === 12)
  132. return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l);
  133. else {
  134. const m = src[position++];
  135. if ((m & 0x80) > 0) {
  136. position -= 13;
  137. return;
  138. }
  139. return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m);
  140. }
  141. }
  142. else {
  143. const m = src[position++];
  144. const n = src[position++];
  145. if ((m & 0x80) > 0 || (n & 0x80) > 0) {
  146. position -= 14;
  147. return;
  148. }
  149. if (length < 15)
  150. return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
  151. const o = src[position++];
  152. if ((o & 0x80) > 0) {
  153. position -= 15;
  154. return;
  155. }
  156. return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
  157. }
  158. }
  159. }
  160. }
  161. };
  162. exports.decodeAsciiMax15 = decodeAsciiMax15;
  163. //# sourceMappingURL=decodeAscii.js.map