1 | var _a, _b;
|
2 | const Object_prototype_toString = {}.toString;
|
3 | const ArrayBufferString = Object_prototype_toString.call(ArrayBuffer.prototype);
|
4 | function decoderReplacer(encoded) {
|
5 | let codePoint = encoded.charCodeAt(0) << 24;
|
6 | const leadingOnes = Math.clz32(~codePoint) | 0;
|
7 | let endPos = 0;
|
8 | const stringLen = encoded.length | 0;
|
9 | let result = '';
|
10 | if (leadingOnes < 5 && stringLen >= leadingOnes) {
|
11 | codePoint = (codePoint << leadingOnes) >>> (24 + leadingOnes);
|
12 | for (endPos = 1; endPos < leadingOnes; endPos = (endPos + 1) | 0) {
|
13 | codePoint = (codePoint << 6) | (encoded.charCodeAt(endPos) & 0x3f) ;
|
14 | }
|
15 | if (codePoint <= 0xffff) {
|
16 |
|
17 | result += String.fromCharCode(codePoint);
|
18 | }
|
19 | else if (codePoint <= 0x10ffff) {
|
20 |
|
21 | codePoint = (codePoint - 0x10000) | 0;
|
22 | result += String.fromCharCode(((codePoint >> 10) + 0xd800) | 0,
|
23 | ((codePoint & 0x3ff) + 0xdc00) | 0
|
24 | );
|
25 | }
|
26 | else {
|
27 | endPos = 0;
|
28 | }
|
29 | }
|
30 | for (; endPos < stringLen; endPos = (endPos + 1) | 0) {
|
31 | result += '\ufffd';
|
32 | }
|
33 | return result;
|
34 | }
|
35 | function encoderReplacer(nonAsciiChars) {
|
36 |
|
37 | let point = nonAsciiChars.charCodeAt(0) | 0;
|
38 | if (point >= 0xd800 && point <= 0xdbff) {
|
39 | const nextcode = nonAsciiChars.charCodeAt(1) | 0;
|
40 | if (nextcode !== nextcode) {
|
41 |
|
42 | return String.fromCharCode(0xef , 0xbf , 0xbd );
|
43 | }
|
44 |
|
45 | if (nextcode >= 0xdc00 && nextcode <= 0xdfff) {
|
46 | point = (((point - 0xd800) << 10) + nextcode - 0xdc00 + 0x10000) | 0;
|
47 | if (point > 0xffff) {
|
48 | return String.fromCharCode((0x1e << 3) | (point >>> 18), (0x2 << 6) | ((point >>> 12) & 0x3f) , (0x2 << 6) | ((point >>> 6) & 0x3f) , (0x2 << 6) | (point & 0x3f) );
|
49 | }
|
50 | }
|
51 | else {
|
52 | return String.fromCharCode(0xef, 0xbf, 0xbd);
|
53 | }
|
54 | }
|
55 | if (point <= 0x007f) {
|
56 | return nonAsciiChars;
|
57 | }
|
58 | else if (point <= 0x07ff) {
|
59 | return String.fromCharCode((0x6 << 5) | (point >>> 6), (0x2 << 6) | (point & 0x3f));
|
60 | }
|
61 | else {
|
62 | return String.fromCharCode((0xe << 4) | (point >>> 12), (0x2 << 6) | ((point >>> 6) & 0x3f) , (0x2 << 6) | (point & 0x3f) );
|
63 | }
|
64 | }
|
65 | export class TextDecoder {
|
66 | constructor() {
|
67 | this[_a] = 'TextDecoder';
|
68 | }
|
69 | get encoding() {
|
70 | return 'utf-8';
|
71 | }
|
72 | decode(input) {
|
73 | const buffer = ArrayBuffer.isView(input) ? input.buffer : input;
|
74 | if (Object_prototype_toString.call(buffer) !== ArrayBufferString) {
|
75 | throw Error("Failed to execute 'decode' on 'TextDecoder': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
|
76 | }
|
77 | const inputAs8 = new Uint8Array(buffer);
|
78 | let resultingString = '';
|
79 | for (let index = 0, len = inputAs8.length | 0; index < len; index = (index + 32768) | 0) {
|
80 | resultingString += String.fromCharCode.apply(0, inputAs8.slice(index, (index + 32768) | 0));
|
81 | }
|
82 | return resultingString.replace(/[\xc0-\xff][\x80-\xbf]*/g, decoderReplacer);
|
83 | }
|
84 | toString() {
|
85 | return '[object TextDecoder]';
|
86 | }
|
87 | }
|
88 | _a = Symbol.toStringTag;
|
89 | export class TextEncoder {
|
90 | constructor() {
|
91 | this[_b] = 'TextEncoder';
|
92 | }
|
93 | get encoding() {
|
94 | return 'utf-8';
|
95 | }
|
96 | encode(input = '') {
|
97 |
|
98 |
|
99 | const encodedString = input === undefined ? '' : ('' + input).replace(/[\x80-\uD7ff\uDC00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]?/g, encoderReplacer);
|
100 | const len = encodedString.length | 0, result = new Uint8Array(len);
|
101 | for (let i = 0; i < len; i = (i + 1) | 0) {
|
102 | result[i] = encodedString.charCodeAt(i);
|
103 | }
|
104 | return result;
|
105 | }
|
106 | toString() {
|
107 | return '[object TextEncoder]';
|
108 | }
|
109 | }
|
110 | _b = Symbol.toStringTag;
|
111 |
|
\ | No newline at end of file |