aboutsummaryrefslogtreecommitdiff
path: root/node_modules/@webassemblyjs/utf8
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/@webassemblyjs/utf8
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/@webassemblyjs/utf8')
-rw-r--r--node_modules/@webassemblyjs/utf8/LICENSE21
-rw-r--r--node_modules/@webassemblyjs/utf8/esm/decoder.js95
-rw-r--r--node_modules/@webassemblyjs/utf8/esm/encoder.js46
-rw-r--r--node_modules/@webassemblyjs/utf8/esm/index.js2
-rw-r--r--node_modules/@webassemblyjs/utf8/lib/decoder.js102
-rw-r--r--node_modules/@webassemblyjs/utf8/lib/encoder.js53
-rw-r--r--node_modules/@webassemblyjs/utf8/lib/index.js21
-rw-r--r--node_modules/@webassemblyjs/utf8/package.json20
-rw-r--r--node_modules/@webassemblyjs/utf8/src/decoder.js86
-rw-r--r--node_modules/@webassemblyjs/utf8/src/encoder.js44
-rw-r--r--node_modules/@webassemblyjs/utf8/src/index.js4
-rw-r--r--node_modules/@webassemblyjs/utf8/test/index.js13
12 files changed, 507 insertions, 0 deletions
diff --git a/node_modules/@webassemblyjs/utf8/LICENSE b/node_modules/@webassemblyjs/utf8/LICENSE
new file mode 100644
index 00000000..87e7e1ff
--- /dev/null
+++ b/node_modules/@webassemblyjs/utf8/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2018 Sven Sauleau <sven@sauleau.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/node_modules/@webassemblyjs/utf8/esm/decoder.js b/node_modules/@webassemblyjs/utf8/esm/decoder.js
new file mode 100644
index 00000000..12d88eb1
--- /dev/null
+++ b/node_modules/@webassemblyjs/utf8/esm/decoder.js
@@ -0,0 +1,95 @@
+function _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); } }
+
+function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
+
+function con(b) {
+ if ((b & 0xc0) === 0x80) {
+ return b & 0x3f;
+ } else {
+ throw new Error("invalid UTF-8 encoding");
+ }
+}
+
+function code(min, n) {
+ if (n < min || 0xd800 <= n && n < 0xe000 || n >= 0x10000) {
+ throw new Error("invalid UTF-8 encoding");
+ } else {
+ return n;
+ }
+}
+
+export function decode(bytes) {
+ return _decode(bytes).map(function (x) {
+ return String.fromCharCode(x);
+ }).join("");
+}
+
+function _decode(bytes) {
+ if (bytes.length === 0) {
+ return [];
+ }
+ /**
+ * 1 byte
+ */
+
+
+ {
+ var _bytes = _toArray(bytes),
+ b1 = _bytes[0],
+ bs = _bytes.slice(1);
+
+ if (b1 < 0x80) {
+ return [code(0x0, b1)].concat(_toConsumableArray(_decode(bs)));
+ }
+
+ if (b1 < 0xc0) {
+ throw new Error("invalid UTF-8 encoding");
+ }
+ }
+ /**
+ * 2 bytes
+ */
+
+ {
+ var _bytes2 = _toArray(bytes),
+ _b = _bytes2[0],
+ b2 = _bytes2[1],
+ _bs = _bytes2.slice(2);
+
+ if (_b < 0xe0) {
+ return [code(0x80, ((_b & 0x1f) << 6) + con(b2))].concat(_toConsumableArray(_decode(_bs)));
+ }
+ }
+ /**
+ * 3 bytes
+ */
+
+ {
+ var _bytes3 = _toArray(bytes),
+ _b2 = _bytes3[0],
+ _b3 = _bytes3[1],
+ b3 = _bytes3[2],
+ _bs2 = _bytes3.slice(3);
+
+ if (_b2 < 0xf0) {
+ return [code(0x800, ((_b2 & 0x0f) << 12) + (con(_b3) << 6) + con(b3))].concat(_toConsumableArray(_decode(_bs2)));
+ }
+ }
+ /**
+ * 4 bytes
+ */
+
+ {
+ var _bytes4 = _toArray(bytes),
+ _b4 = _bytes4[0],
+ _b5 = _bytes4[1],
+ _b6 = _bytes4[2],
+ b4 = _bytes4[3],
+ _bs3 = _bytes4.slice(4);
+
+ if (_b4 < 0xf8) {
+ return [code(0x10000, (((_b4 & 0x07) << 18) + con(_b5) << 12) + (con(_b6) << 6) + con(b4))].concat(_toConsumableArray(_decode(_bs3)));
+ }
+ }
+ throw new Error("invalid UTF-8 encoding");
+} \ No newline at end of file
diff --git a/node_modules/@webassemblyjs/utf8/esm/encoder.js b/node_modules/@webassemblyjs/utf8/esm/encoder.js
new file mode 100644
index 00000000..6d5e4dec
--- /dev/null
+++ b/node_modules/@webassemblyjs/utf8/esm/encoder.js
@@ -0,0 +1,46 @@
+function _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); } }
+
+function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
+
+function con(n) {
+ return 0x80 | n & 0x3f;
+}
+
+export function encode(str) {
+ var arr = str.split("").map(function (x) {
+ return x.charCodeAt(0);
+ });
+ return _encode(arr);
+}
+
+function _encode(arr) {
+ if (arr.length === 0) {
+ return [];
+ }
+
+ var _arr = _toArray(arr),
+ n = _arr[0],
+ ns = _arr.slice(1);
+
+ if (n < 0) {
+ throw new Error("utf8");
+ }
+
+ if (n < 0x80) {
+ return [n].concat(_toConsumableArray(_encode(ns)));
+ }
+
+ if (n < 0x800) {
+ return [0xc0 | n >>> 6, con(n)].concat(_toConsumableArray(_encode(ns)));
+ }
+
+ if (n < 0x10000) {
+ return [0xe0 | n >>> 12, con(n >>> 6), con(n)].concat(_toConsumableArray(_encode(ns)));
+ }
+
+ if (n < 0x110000) {
+ return [0xf0 | n >>> 18, con(n >>> 12), con(n >>> 6), con(n)].concat(_toConsumableArray(_encode(ns)));
+ }
+
+ throw new Error("utf8");
+} \ No newline at end of file
diff --git a/node_modules/@webassemblyjs/utf8/esm/index.js b/node_modules/@webassemblyjs/utf8/esm/index.js
new file mode 100644
index 00000000..2e31357a
--- /dev/null
+++ b/node_modules/@webassemblyjs/utf8/esm/index.js
@@ -0,0 +1,2 @@
+export { decode } from "./decoder";
+export { encode } from "./encoder"; \ No newline at end of file
diff --git a/node_modules/@webassemblyjs/utf8/lib/decoder.js b/node_modules/@webassemblyjs/utf8/lib/decoder.js
new file mode 100644
index 00000000..824c843f
--- /dev/null
+++ b/node_modules/@webassemblyjs/utf8/lib/decoder.js
@@ -0,0 +1,102 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.decode = decode;
+
+function _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); } }
+
+function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
+
+function con(b) {
+ if ((b & 0xc0) === 0x80) {
+ return b & 0x3f;
+ } else {
+ throw new Error("invalid UTF-8 encoding");
+ }
+}
+
+function code(min, n) {
+ if (n < min || 0xd800 <= n && n < 0xe000 || n >= 0x10000) {
+ throw new Error("invalid UTF-8 encoding");
+ } else {
+ return n;
+ }
+}
+
+function decode(bytes) {
+ return _decode(bytes).map(function (x) {
+ return String.fromCharCode(x);
+ }).join("");
+}
+
+function _decode(bytes) {
+ if (bytes.length === 0) {
+ return [];
+ }
+ /**
+ * 1 byte
+ */
+
+
+ {
+ var _bytes = _toArray(bytes),
+ b1 = _bytes[0],
+ bs = _bytes.slice(1);
+
+ if (b1 < 0x80) {
+ return [code(0x0, b1)].concat(_toConsumableArray(_decode(bs)));
+ }
+
+ if (b1 < 0xc0) {
+ throw new Error("invalid UTF-8 encoding");
+ }
+ }
+ /**
+ * 2 bytes
+ */
+
+ {
+ var _bytes2 = _toArray(bytes),
+ _b = _bytes2[0],
+ b2 = _bytes2[1],
+ _bs = _bytes2.slice(2);
+
+ if (_b < 0xe0) {
+ return [code(0x80, ((_b & 0x1f) << 6) + con(b2))].concat(_toConsumableArray(_decode(_bs)));
+ }
+ }
+ /**
+ * 3 bytes
+ */
+
+ {
+ var _bytes3 = _toArray(bytes),
+ _b2 = _bytes3[0],
+ _b3 = _bytes3[1],
+ b3 = _bytes3[2],
+ _bs2 = _bytes3.slice(3);
+
+ if (_b2 < 0xf0) {
+ return [code(0x800, ((_b2 & 0x0f) << 12) + (con(_b3) << 6) + con(b3))].concat(_toConsumableArray(_decode(_bs2)));
+ }
+ }
+ /**
+ * 4 bytes
+ */
+
+ {
+ var _bytes4 = _toArray(bytes),
+ _b4 = _bytes4[0],
+ _b5 = _bytes4[1],
+ _b6 = _bytes4[2],
+ b4 = _bytes4[3],
+ _bs3 = _bytes4.slice(4);
+
+ if (_b4 < 0xf8) {
+ return [code(0x10000, (((_b4 & 0x07) << 18) + con(_b5) << 12) + (con(_b6) << 6) + con(b4))].concat(_toConsumableArray(_decode(_bs3)));
+ }
+ }
+ throw new Error("invalid UTF-8 encoding");
+} \ No newline at end of file
diff --git a/node_modules/@webassemblyjs/utf8/lib/encoder.js b/node_modules/@webassemblyjs/utf8/lib/encoder.js
new file mode 100644
index 00000000..0606b561
--- /dev/null
+++ b/node_modules/@webassemblyjs/utf8/lib/encoder.js
@@ -0,0 +1,53 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.encode = encode;
+
+function _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); } }
+
+function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
+
+function con(n) {
+ return 0x80 | n & 0x3f;
+}
+
+function encode(str) {
+ var arr = str.split("").map(function (x) {
+ return x.charCodeAt(0);
+ });
+ return _encode(arr);
+}
+
+function _encode(arr) {
+ if (arr.length === 0) {
+ return [];
+ }
+
+ var _arr = _toArray(arr),
+ n = _arr[0],
+ ns = _arr.slice(1);
+
+ if (n < 0) {
+ throw new Error("utf8");
+ }
+
+ if (n < 0x80) {
+ return [n].concat(_toConsumableArray(_encode(ns)));
+ }
+
+ if (n < 0x800) {
+ return [0xc0 | n >>> 6, con(n)].concat(_toConsumableArray(_encode(ns)));
+ }
+
+ if (n < 0x10000) {
+ return [0xe0 | n >>> 12, con(n >>> 6), con(n)].concat(_toConsumableArray(_encode(ns)));
+ }
+
+ if (n < 0x110000) {
+ return [0xf0 | n >>> 18, con(n >>> 12), con(n >>> 6), con(n)].concat(_toConsumableArray(_encode(ns)));
+ }
+
+ throw new Error("utf8");
+} \ No newline at end of file
diff --git a/node_modules/@webassemblyjs/utf8/lib/index.js b/node_modules/@webassemblyjs/utf8/lib/index.js
new file mode 100644
index 00000000..fef94701
--- /dev/null
+++ b/node_modules/@webassemblyjs/utf8/lib/index.js
@@ -0,0 +1,21 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+Object.defineProperty(exports, "decode", {
+ enumerable: true,
+ get: function get() {
+ return _decoder.decode;
+ }
+});
+Object.defineProperty(exports, "encode", {
+ enumerable: true,
+ get: function get() {
+ return _encoder.encode;
+ }
+});
+
+var _decoder = require("./decoder");
+
+var _encoder = require("./encoder"); \ No newline at end of file
diff --git a/node_modules/@webassemblyjs/utf8/package.json b/node_modules/@webassemblyjs/utf8/package.json
new file mode 100644
index 00000000..0bed2ac6
--- /dev/null
+++ b/node_modules/@webassemblyjs/utf8/package.json
@@ -0,0 +1,20 @@
+{
+ "name": "@webassemblyjs/utf8",
+ "version": "1.7.11",
+ "description": "UTF8 encoder/decoder for WASM",
+ "main": "lib/index.js",
+ "module": "esm/index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/xtuc/webassemblyjs.git"
+ },
+ "publishConfig": {
+ "access": "public"
+ },
+ "author": "Sven Sauleau",
+ "license": "MIT",
+ "gitHead": "4291990bfc4648bc6676091a955d12dc3c7e5909"
+}
diff --git a/node_modules/@webassemblyjs/utf8/src/decoder.js b/node_modules/@webassemblyjs/utf8/src/decoder.js
new file mode 100644
index 00000000..227ba3ad
--- /dev/null
+++ b/node_modules/@webassemblyjs/utf8/src/decoder.js
@@ -0,0 +1,86 @@
+function con(b) {
+ if ((b & 0xc0) === 0x80) {
+ return b & 0x3f;
+ } else {
+ throw new Error("invalid UTF-8 encoding");
+ }
+}
+
+function code(min, n) {
+ if (n < min || (0xd800 <= n && n < 0xe000) || n >= 0x10000) {
+ throw new Error("invalid UTF-8 encoding");
+ } else {
+ return n;
+ }
+}
+
+export function decode(bytes) {
+ return _decode(bytes)
+ .map(x => String.fromCharCode(x))
+ .join("");
+}
+
+function _decode(bytes) {
+ if (bytes.length === 0) {
+ return [];
+ }
+
+ /**
+ * 1 byte
+ */
+ {
+ const [b1, ...bs] = bytes;
+
+ if (b1 < 0x80) {
+ return [code(0x0, b1), ..._decode(bs)];
+ }
+
+ if (b1 < 0xc0) {
+ throw new Error("invalid UTF-8 encoding");
+ }
+ }
+
+ /**
+ * 2 bytes
+ */
+ {
+ const [b1, b2, ...bs] = bytes;
+
+ if (b1 < 0xe0) {
+ return [code(0x80, ((b1 & 0x1f) << 6) + con(b2)), ..._decode(bs)];
+ }
+ }
+
+ /**
+ * 3 bytes
+ */
+ {
+ const [b1, b2, b3, ...bs] = bytes;
+
+ if (b1 < 0xf0) {
+ return [
+ code(0x800, ((b1 & 0x0f) << 12) + (con(b2) << 6) + con(b3)),
+ ..._decode(bs)
+ ];
+ }
+ }
+
+ /**
+ * 4 bytes
+ */
+ {
+ const [b1, b2, b3, b4, ...bs] = bytes;
+
+ if (b1 < 0xf8) {
+ return [
+ code(
+ 0x10000,
+ ((((b1 & 0x07) << 18) + con(b2)) << 12) + (con(b3) << 6) + con(b4)
+ ),
+ ..._decode(bs)
+ ];
+ }
+ }
+
+ throw new Error("invalid UTF-8 encoding");
+}
diff --git a/node_modules/@webassemblyjs/utf8/src/encoder.js b/node_modules/@webassemblyjs/utf8/src/encoder.js
new file mode 100644
index 00000000..1c482f07
--- /dev/null
+++ b/node_modules/@webassemblyjs/utf8/src/encoder.js
@@ -0,0 +1,44 @@
+function con(n) {
+ return 0x80 | (n & 0x3f);
+}
+
+export function encode(str) {
+ const arr = str.split("").map(x => x.charCodeAt(0));
+ return _encode(arr);
+}
+
+function _encode(arr) {
+ if (arr.length === 0) {
+ return [];
+ }
+
+ const [n, ...ns] = arr;
+
+ if (n < 0) {
+ throw new Error("utf8");
+ }
+
+ if (n < 0x80) {
+ return [n, ..._encode(ns)];
+ }
+
+ if (n < 0x800) {
+ return [0xc0 | (n >>> 6), con(n), ..._encode(ns)];
+ }
+
+ if (n < 0x10000) {
+ return [0xe0 | (n >>> 12), con(n >>> 6), con(n), ..._encode(ns)];
+ }
+
+ if (n < 0x110000) {
+ return [
+ 0xf0 | (n >>> 18),
+ con(n >>> 12),
+ con(n >>> 6),
+ con(n),
+ ..._encode(ns)
+ ];
+ }
+
+ throw new Error("utf8");
+}
diff --git a/node_modules/@webassemblyjs/utf8/src/index.js b/node_modules/@webassemblyjs/utf8/src/index.js
new file mode 100644
index 00000000..82cf9a70
--- /dev/null
+++ b/node_modules/@webassemblyjs/utf8/src/index.js
@@ -0,0 +1,4 @@
+// @flow
+
+export { decode } from "./decoder";
+export { encode } from "./encoder";
diff --git a/node_modules/@webassemblyjs/utf8/test/index.js b/node_modules/@webassemblyjs/utf8/test/index.js
new file mode 100644
index 00000000..dabdc6ca
--- /dev/null
+++ b/node_modules/@webassemblyjs/utf8/test/index.js
@@ -0,0 +1,13 @@
+const { assert } = require("chai");
+
+const { decode, encode } = require("../lib");
+
+describe("UTF8", () => {
+ it("should f-1(f(x)) = x", () => {
+ assert.equal(decode(encode("foo")), "foo");
+ assert.equal(decode(encode("éé")), "éé");
+
+ // TODO(sven): utf8 encoder fails here
+ // assert.equal(decode(encode("🤣见見")), "🤣见見");
+ });
+});