source: trip-planner-front/node_modules/@webassemblyjs/utf8/esm/decoder.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[6a3a178]1function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
2
3function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
4
5function con(b) {
6 if ((b & 0xc0) === 0x80) {
7 return b & 0x3f;
8 } else {
9 throw new Error("invalid UTF-8 encoding");
10 }
11}
12
13function code(min, n) {
14 if (n < min || 0xd800 <= n && n < 0xe000 || n >= 0x10000) {
15 throw new Error("invalid UTF-8 encoding");
16 } else {
17 return n;
18 }
19}
20
21export function decode(bytes) {
22 return _decode(bytes).map(function (x) {
23 return String.fromCharCode(x);
24 }).join("");
25}
26
27function _decode(bytes) {
28 if (bytes.length === 0) {
29 return [];
30 }
31 /**
32 * 1 byte
33 */
34
35
36 {
37 var _bytes = _toArray(bytes),
38 b1 = _bytes[0],
39 bs = _bytes.slice(1);
40
41 if (b1 < 0x80) {
42 return [code(0x0, b1)].concat(_toConsumableArray(_decode(bs)));
43 }
44
45 if (b1 < 0xc0) {
46 throw new Error("invalid UTF-8 encoding");
47 }
48 }
49 /**
50 * 2 bytes
51 */
52
53 {
54 var _bytes2 = _toArray(bytes),
55 _b = _bytes2[0],
56 b2 = _bytes2[1],
57 _bs = _bytes2.slice(2);
58
59 if (_b < 0xe0) {
60 return [code(0x80, ((_b & 0x1f) << 6) + con(b2))].concat(_toConsumableArray(_decode(_bs)));
61 }
62 }
63 /**
64 * 3 bytes
65 */
66
67 {
68 var _bytes3 = _toArray(bytes),
69 _b2 = _bytes3[0],
70 _b3 = _bytes3[1],
71 b3 = _bytes3[2],
72 _bs2 = _bytes3.slice(3);
73
74 if (_b2 < 0xf0) {
75 return [code(0x800, ((_b2 & 0x0f) << 12) + (con(_b3) << 6) + con(b3))].concat(_toConsumableArray(_decode(_bs2)));
76 }
77 }
78 /**
79 * 4 bytes
80 */
81
82 {
83 var _bytes4 = _toArray(bytes),
84 _b4 = _bytes4[0],
85 _b5 = _bytes4[1],
86 _b6 = _bytes4[2],
87 b4 = _bytes4[3],
88 _bs3 = _bytes4.slice(4);
89
90 if (_b4 < 0xf8) {
91 return [code(0x10000, (((_b4 & 0x07) << 18) + con(_b5) << 12) + (con(_b6) << 6) + con(b4))].concat(_toConsumableArray(_decode(_bs3)));
92 }
93 }
94 throw new Error("invalid UTF-8 encoding");
95}
Note: See TracBrowser for help on using the repository browser.