@amxts/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +162 -0
- package/README.ru.md +162 -0
- package/amxmodx/base/include/amxconst.inc +594 -0
- package/amxmodx/base/include/amxmisc.inc +902 -0
- package/amxmodx/base/include/amxmodx.inc +3447 -0
- package/amxmodx/base/include/amxmodx_version.inc +20 -0
- package/amxmodx/base/include/cellarray.inc +525 -0
- package/amxmodx/base/include/cellstack.inc +166 -0
- package/amxmodx/base/include/celltrie.inc +412 -0
- package/amxmodx/base/include/core.inc +202 -0
- package/amxmodx/base/include/csstats.inc +298 -0
- package/amxmodx/base/include/csstats_const.inc +29 -0
- package/amxmodx/base/include/cstrike.inc +1287 -0
- package/amxmodx/base/include/cstrike_const.inc +521 -0
- package/amxmodx/base/include/csx.inc +259 -0
- package/amxmodx/base/include/cvars.inc +547 -0
- package/amxmodx/base/include/datapack.inc +161 -0
- package/amxmodx/base/include/dbi.inc +154 -0
- package/amxmodx/base/include/dodconst.inc +152 -0
- package/amxmodx/base/include/dodfun.inc +152 -0
- package/amxmodx/base/include/dodstats.inc +69 -0
- package/amxmodx/base/include/dodx.inc +161 -0
- package/amxmodx/base/include/engine.inc +1343 -0
- package/amxmodx/base/include/engine_const.inc +310 -0
- package/amxmodx/base/include/engine_stocks.inc +248 -0
- package/amxmodx/base/include/esf.inc +70 -0
- package/amxmodx/base/include/esf_const.inc +74 -0
- package/amxmodx/base/include/fakemeta.inc +1127 -0
- package/amxmodx/base/include/fakemeta_const.inc +793 -0
- package/amxmodx/base/include/fakemeta_stocks.inc +395 -0
- package/amxmodx/base/include/fakemeta_util.inc +882 -0
- package/amxmodx/base/include/file.inc +666 -0
- package/amxmodx/base/include/float.inc +422 -0
- package/amxmodx/base/include/fun.inc +333 -0
- package/amxmodx/base/include/gameconfig.inc +93 -0
- package/amxmodx/base/include/geoip.inc +264 -0
- package/amxmodx/base/include/ham_const.inc +4352 -0
- package/amxmodx/base/include/hamsandwich.inc +439 -0
- package/amxmodx/base/include/hlsdk_const.inc +808 -0
- package/amxmodx/base/include/json.inc +777 -0
- package/amxmodx/base/include/lang.inc +119 -0
- package/amxmodx/base/include/message_const.inc +1130 -0
- package/amxmodx/base/include/message_stocks.inc +161 -0
- package/amxmodx/base/include/messages.inc +604 -0
- package/amxmodx/base/include/newmenus.inc +387 -0
- package/amxmodx/base/include/ns.inc +754 -0
- package/amxmodx/base/include/ns_const.inc +196 -0
- package/amxmodx/base/include/nvault.inc +154 -0
- package/amxmodx/base/include/regex.inc +348 -0
- package/amxmodx/base/include/sockets.inc +183 -0
- package/amxmodx/base/include/sorting.inc +107 -0
- package/amxmodx/base/include/sqlx.inc +582 -0
- package/amxmodx/base/include/string.inc +786 -0
- package/amxmodx/base/include/string_const.inc +156 -0
- package/amxmodx/base/include/string_stocks.inc +325 -0
- package/amxmodx/base/include/textparse_ini.inc +214 -0
- package/amxmodx/base/include/textparse_smc.inc +261 -0
- package/amxmodx/base/include/tfcconst.inc +84 -0
- package/amxmodx/base/include/tfcstats.inc +62 -0
- package/amxmodx/base/include/tfcx.inc +148 -0
- package/amxmodx/base/include/time.inc +118 -0
- package/amxmodx/base/include/tsconst.inc +154 -0
- package/amxmodx/base/include/tsfun.inc +198 -0
- package/amxmodx/base/include/tsstats.inc +65 -0
- package/amxmodx/base/include/tsx.inc +88 -0
- package/amxmodx/base/include/vault.inc +60 -0
- package/amxmodx/base/include/vector.inc +131 -0
- package/amxmodx/base/include/xs.inc +1570 -0
- package/as/amxts.d.ts +153 -0
- package/as/constants.ts +4730 -0
- package/as/effects.ts +1449 -0
- package/as/entities.ts +5482 -0
- package/as/events.ts +3054 -0
- package/as/facade.ts +4639 -0
- package/as/flags.ts +299 -0
- package/as/fs.ts +287 -0
- package/as/hooks.ts +18536 -0
- package/as/kit.ts +25 -0
- package/as/lib/check.ts +86 -0
- package/as/modules/http.ts +184 -0
- package/as/natives.ts +11845 -0
- package/as/os.ts +30 -0
- package/as/promise.ts +1392 -0
- package/as/promise.types.d.ts +82 -0
- package/as/remote.ts +288 -0
- package/as/tsconfig.json +22 -0
- package/as/vector.ts +65 -0
- package/bin/amxts.mjs +10 -0
- package/includes/menu_core.inc +355 -0
- package/includes/order.txt +54 -0
- package/includes/sources.json +27 -0
- package/includes/universal_config.inc +355 -0
- package/lint/oxlint-plugin.mjs +77 -0
- package/node_modules/assemblyscript/LICENSE +201 -0
- package/node_modules/assemblyscript/NOTICE +93 -0
- package/node_modules/assemblyscript/package.json +63 -0
- package/node_modules/assemblyscript/std/README.md +6 -0
- package/node_modules/assemblyscript/std/assembly/array.ts +526 -0
- package/node_modules/assemblyscript/std/assembly/arraybuffer.ts +77 -0
- package/node_modules/assemblyscript/std/assembly/atomics.ts +127 -0
- package/node_modules/assemblyscript/std/assembly/bindings/asyncify.ts +16 -0
- package/node_modules/assemblyscript/std/assembly/bindings/dom.ts +291 -0
- package/node_modules/assemblyscript/std/assembly/bindings/node.ts +6 -0
- package/node_modules/assemblyscript/std/assembly/builtins.ts +2631 -0
- package/node_modules/assemblyscript/std/assembly/compat.ts +2 -0
- package/node_modules/assemblyscript/std/assembly/console.ts +42 -0
- package/node_modules/assemblyscript/std/assembly/crypto.ts +9 -0
- package/node_modules/assemblyscript/std/assembly/dataview.ts +181 -0
- package/node_modules/assemblyscript/std/assembly/date.ts +373 -0
- package/node_modules/assemblyscript/std/assembly/diagnostics.ts +11 -0
- package/node_modules/assemblyscript/std/assembly/error.ts +44 -0
- package/node_modules/assemblyscript/std/assembly/function.ts +38 -0
- package/node_modules/assemblyscript/std/assembly/index.d.ts +2822 -0
- package/node_modules/assemblyscript/std/assembly/iterator.ts +35 -0
- package/node_modules/assemblyscript/std/assembly/map.ts +260 -0
- package/node_modules/assemblyscript/std/assembly/math.ts +3289 -0
- package/node_modules/assemblyscript/std/assembly/memory.ts +123 -0
- package/node_modules/assemblyscript/std/assembly/number.ts +388 -0
- package/node_modules/assemblyscript/std/assembly/object.ts +36 -0
- package/node_modules/assemblyscript/std/assembly/performance.ts +9 -0
- package/node_modules/assemblyscript/std/assembly/polyfills.ts +27 -0
- package/node_modules/assemblyscript/std/assembly/process.ts +50 -0
- package/node_modules/assemblyscript/std/assembly/reference.ts +48 -0
- package/node_modules/assemblyscript/std/assembly/regexp.ts +12 -0
- package/node_modules/assemblyscript/std/assembly/rt/README.md +83 -0
- package/node_modules/assemblyscript/std/assembly/rt/common.ts +81 -0
- package/node_modules/assemblyscript/std/assembly/rt/index-incremental.ts +2 -0
- package/node_modules/assemblyscript/std/assembly/rt/index-minimal.ts +2 -0
- package/node_modules/assemblyscript/std/assembly/rt/index-stub.ts +1 -0
- package/node_modules/assemblyscript/std/assembly/rt/index.d.ts +37 -0
- package/node_modules/assemblyscript/std/assembly/rt/itcms.ts +419 -0
- package/node_modules/assemblyscript/std/assembly/rt/rtrace.ts +15 -0
- package/node_modules/assemblyscript/std/assembly/rt/stub.ts +133 -0
- package/node_modules/assemblyscript/std/assembly/rt/tcms.ts +254 -0
- package/node_modules/assemblyscript/std/assembly/rt/tlsf.ts +592 -0
- package/node_modules/assemblyscript/std/assembly/rt.ts +87 -0
- package/node_modules/assemblyscript/std/assembly/set.ts +220 -0
- package/node_modules/assemblyscript/std/assembly/shared/feature.ts +65 -0
- package/node_modules/assemblyscript/std/assembly/shared/runtime.ts +11 -0
- package/node_modules/assemblyscript/std/assembly/shared/target.ts +11 -0
- package/node_modules/assemblyscript/std/assembly/shared/tsconfig.json +11 -0
- package/node_modules/assemblyscript/std/assembly/shared/typeinfo.ts +72 -0
- package/node_modules/assemblyscript/std/assembly/staticarray.ts +401 -0
- package/node_modules/assemblyscript/std/assembly/string.ts +847 -0
- package/node_modules/assemblyscript/std/assembly/symbol.ts +114 -0
- package/node_modules/assemblyscript/std/assembly/table.ts +16 -0
- package/node_modules/assemblyscript/std/assembly/tsconfig.json +6 -0
- package/node_modules/assemblyscript/std/assembly/typedarray.ts +1945 -0
- package/node_modules/assemblyscript/std/assembly/uri.ts +17 -0
- package/node_modules/assemblyscript/std/assembly/util/bytes.ts +107 -0
- package/node_modules/assemblyscript/std/assembly/util/casemap.ts +497 -0
- package/node_modules/assemblyscript/std/assembly/util/error.ts +54 -0
- package/node_modules/assemblyscript/std/assembly/util/hash.ts +117 -0
- package/node_modules/assemblyscript/std/assembly/util/math.ts +1922 -0
- package/node_modules/assemblyscript/std/assembly/util/memory.ts +290 -0
- package/node_modules/assemblyscript/std/assembly/util/number.ts +873 -0
- package/node_modules/assemblyscript/std/assembly/util/sort.ts +313 -0
- package/node_modules/assemblyscript/std/assembly/util/string.ts +1202 -0
- package/node_modules/assemblyscript/std/assembly/util/uri.ts +275 -0
- package/node_modules/assemblyscript/std/assembly/vector.ts +4 -0
- package/node_modules/assemblyscript/std/assembly.json +16 -0
- package/node_modules/assemblyscript/std/portable/index.d.ts +462 -0
- package/node_modules/assemblyscript/std/portable/index.js +416 -0
- package/node_modules/assemblyscript/std/portable.json +11 -0
- package/node_modules/assemblyscript/std/types/assembly/index.d.ts +1 -0
- package/node_modules/assemblyscript/std/types/assembly/package.json +3 -0
- package/node_modules/assemblyscript/std/types/portable/index.d.ts +1 -0
- package/node_modules/assemblyscript/std/types/portable/package.json +3 -0
- package/node_modules/assemblyscript/tsconfig-base.json +13 -0
- package/package.json +112 -0
- package/runtime/deps/assemblyscript/LICENSE +201 -0
- package/runtime/deps/assemblyscript/NOTICE +93 -0
- package/runtime/deps/assemblyscript/bin/asc.js +35 -0
- package/runtime/deps/assemblyscript/dist/asc.js +25035 -0
- package/runtime/deps/assemblyscript/dist/assemblyscript.js +337 -0
- package/runtime/deps/assemblyscript/node_modules/binaryen/LICENSE +201 -0
- package/runtime/deps/assemblyscript/node_modules/binaryen/index.js +28905 -0
- package/runtime/deps/assemblyscript/node_modules/binaryen/package.json +50 -0
- package/runtime/deps/assemblyscript/node_modules/long/LICENSE +202 -0
- package/runtime/deps/assemblyscript/node_modules/long/index.js +1581 -0
- package/runtime/deps/assemblyscript/node_modules/long/package.json +58 -0
- package/runtime/deps/assemblyscript/package.json +114 -0
- package/runtime/host/amxts.inc +85 -0
- package/runtime/licenses/AMXX-LICENSE.txt +34 -0
- package/runtime/licenses/AssemblyScript-LICENSE +201 -0
- package/runtime/licenses/AssemblyScript-NOTICE +93 -0
- package/runtime/licenses/Binaryen-LICENSE +201 -0
- package/runtime/licenses/Bun-LICENSE.md +84 -0
- package/runtime/licenses/GPL-3.0.txt +674 -0
- package/runtime/licenses/LLVM-LICENSE.TXT +279 -0
- package/runtime/licenses/README.md +25 -0
- package/runtime/licenses/WAMR-LICENSE +219 -0
- package/runtime/natives.txt +1095 -0
- package/runtime/patches/README.md +59 -0
- package/runtime/patches/assemblyscript-0.28.20-amxts.patch +14174 -0
- package/runtime/patches/wamr-2.4.5-amxts.patch +364 -0
- package/scripts/apply-docs.ts +508 -0
- package/scripts/asc.ts +27 -0
- package/scripts/auto-imports.ts +258 -0
- package/scripts/build-wasm.ts +595 -0
- package/scripts/check.ts +93 -0
- package/scripts/compile-cache.ts +179 -0
- package/scripts/compile.ts +401 -0
- package/scripts/docker-server.ts +73 -0
- package/scripts/docs/as/amxts.ts +210 -0
- package/scripts/docs/as/effects.ts +1684 -0
- package/scripts/docs/as/facade.ts +3302 -0
- package/scripts/docs/as/fs.ts +173 -0
- package/scripts/docs/as/lib/check.ts +68 -0
- package/scripts/docs/as/modules/http.ts +66 -0
- package/scripts/docs/as/os.ts +16 -0
- package/scripts/docs/as/promise.ts +132 -0
- package/scripts/docs/as/promise.types.ts +63 -0
- package/scripts/docs/as/vector.ts +48 -0
- package/scripts/docs/entities.ts +2338 -0
- package/scripts/docs/events.ts +245 -0
- package/scripts/docs/game.ts +497 -0
- package/scripts/docs/messages.ts +148 -0
- package/scripts/file-contents.ts +74 -0
- package/scripts/includes.ts +134 -0
- package/scripts/player-fields.ts +866 -0
- package/scripts/plugin-cache.ts +92 -0
- package/scripts/plugin-natives.ts +1157 -0
- package/scripts/prebuilt.ts +268 -0
- package/scripts/prepare.ts +134 -0
- package/scripts/project.ts +973 -0
- package/scripts/run.ts +28 -0
- package/scripts/shared-modules.ts +906 -0
- package/scripts/system.ts +33 -0
- package/scripts/tracked-fs.ts +115 -0
- package/scripts/typed-configs.ts +788 -0
- package/scripts/ui.ts +77 -0
- package/src/cli-api.mjs +175 -0
- package/src/parser/include-parser.ts +506 -0
- package/src/system.mjs +155 -0
- package/src/testing/compile-cache.ts +31 -0
- package/src/testing/compile.ts +222 -0
- package/src/testing/coroutines.ts +191 -0
- package/src/testing/index.ts +39 -0
- package/src/testing/kits.ts +55 -0
- package/src/testing/memory.ts +125 -0
- package/src/testing/natives.ts +925 -0
- package/src/testing/server.ts +1874 -0
- package/src/testing/setup.ts +63 -0
- package/src/testing/tables.ts +139 -0
- package/src/types.ts +51 -0
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { E_URI_MALFORMED } from "./error";
|
|
2
|
+
import { CharCode } from "./string";
|
|
3
|
+
|
|
4
|
+
// Truncated lookup boolean table that helps us quickly determine
|
|
5
|
+
// if a char needs to be escaped for URIs (RFC 2396).
|
|
6
|
+
// @ts-ignore: decorator
|
|
7
|
+
@lazy export const URI_UNSAFE = memory.data<u8>([
|
|
8
|
+
/* skip 32 + 1 always set to '1' head slots
|
|
9
|
+
*/ 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
10
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0,
|
|
11
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
12
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0,
|
|
13
|
+
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
14
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, /*
|
|
15
|
+
skip 128 + 1 always set to '1' tail slots */
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
// Truncated lookup boolean table that helps us quickly determine
|
|
19
|
+
// if a char needs to be escaped for URLs (RFC 3986).
|
|
20
|
+
// @ts-ignore: decorator
|
|
21
|
+
@lazy export const URL_UNSAFE = memory.data<u8>([
|
|
22
|
+
/* skip 32 + 1 always set to '1' head slots
|
|
23
|
+
*/ 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1,
|
|
24
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
|
|
25
|
+
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
26
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0,
|
|
27
|
+
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
28
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, /*
|
|
29
|
+
skip 128 + 1 always set to '1' tail slots */
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
// Truncated lookup boolean table for determine reserved chars: ;/?:@&=+$,#
|
|
33
|
+
// @ts-ignore: decorator
|
|
34
|
+
@lazy export const URI_RESERVED = memory.data<u8>([
|
|
35
|
+
/* skip 32 + 3 always set to '0' head slots
|
|
36
|
+
*/ 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1,
|
|
37
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1,
|
|
38
|
+
1, /* skip 191 always set to '0' tail slots */
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
export function encode(src: usize, len: usize, table: usize): usize {
|
|
42
|
+
if (!len) return src;
|
|
43
|
+
|
|
44
|
+
let i: usize = 0, offset: usize = 0, outSize = len << 1;
|
|
45
|
+
let dst = __new(outSize, idof<String>());
|
|
46
|
+
|
|
47
|
+
while (i < len) {
|
|
48
|
+
let org = i;
|
|
49
|
+
let c: u32, c1: u32;
|
|
50
|
+
// fast scan a check chars until it valid ASCII
|
|
51
|
+
// and safe for copying withoud escaping.
|
|
52
|
+
do {
|
|
53
|
+
c = <u32>load<u16>(src + (i << 1));
|
|
54
|
+
// is it valid ASII and safe?
|
|
55
|
+
if (c - 33 < 94) { // 127 - 33
|
|
56
|
+
if (load<u8>(table + (c - 33))) break;
|
|
57
|
+
} else break;
|
|
58
|
+
} while (++i < len);
|
|
59
|
+
|
|
60
|
+
// if we have some safe range of sequence just copy it without encoding
|
|
61
|
+
if (i > org) {
|
|
62
|
+
let size = i - org << 1;
|
|
63
|
+
if (offset + size > outSize) {
|
|
64
|
+
outSize = offset + size;
|
|
65
|
+
dst = __renew(dst, outSize);
|
|
66
|
+
}
|
|
67
|
+
// TODO: should we optimize for short cases like 2 byte size?
|
|
68
|
+
memory.copy(
|
|
69
|
+
dst + offset,
|
|
70
|
+
src + (org << 1),
|
|
71
|
+
size
|
|
72
|
+
);
|
|
73
|
+
offset += size;
|
|
74
|
+
// return if we reach end on input string
|
|
75
|
+
if (i >= len) break;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// decode UTF16 with checking for unpaired surrogates
|
|
79
|
+
if (c >= 0xD800) {
|
|
80
|
+
if (c >= 0xDC00 && c <= 0xDFFF) {
|
|
81
|
+
throw new URIError(E_URI_MALFORMED);
|
|
82
|
+
}
|
|
83
|
+
if (c <= 0xDBFF) {
|
|
84
|
+
if (i >= len) {
|
|
85
|
+
throw new URIError(E_URI_MALFORMED);
|
|
86
|
+
}
|
|
87
|
+
c1 = <u32>load<u16>(src + (++i << 1));
|
|
88
|
+
if (c1 < 0xDC00 || c1 > 0xDFFF) {
|
|
89
|
+
throw new URIError(E_URI_MALFORMED);
|
|
90
|
+
}
|
|
91
|
+
c = (((c & 0x3FF) << 10) | (c1 & 0x3FF)) + 0x10000;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let estSize = offset + (c < 0x80 ? 1 * 6 : 4 * 6);
|
|
96
|
+
if (estSize > outSize) {
|
|
97
|
+
// doubling estimated size but only for greater than one
|
|
98
|
+
// input lenght due to we already estemated it for worst case
|
|
99
|
+
outSize = len > 1 ? estSize << 1 : estSize;
|
|
100
|
+
dst = __renew(dst, outSize);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (c < 0x80) {
|
|
104
|
+
// encode ASCII unsafe code point
|
|
105
|
+
storeHex(dst, offset, c);
|
|
106
|
+
offset += 6;
|
|
107
|
+
} else {
|
|
108
|
+
// encode UTF-8 unsafe code point
|
|
109
|
+
if (c < 0x800) {
|
|
110
|
+
storeHex(dst, offset, (c >> 6) | 0xC0);
|
|
111
|
+
offset += 6;
|
|
112
|
+
} else {
|
|
113
|
+
if (c < 0x10000) {
|
|
114
|
+
storeHex(dst, offset, (c >> 12) | 0xE0);
|
|
115
|
+
offset += 6;
|
|
116
|
+
} else {
|
|
117
|
+
storeHex(dst, offset, (c >> 18) | 0xF0);
|
|
118
|
+
offset += 6;
|
|
119
|
+
storeHex(dst, offset, (c >> 12 & 0x3F) | 0x80);
|
|
120
|
+
offset += 6;
|
|
121
|
+
}
|
|
122
|
+
storeHex(dst, offset, (c >> 6 & 0x3F) | 0x80);
|
|
123
|
+
offset += 6;
|
|
124
|
+
}
|
|
125
|
+
storeHex(dst, offset, (c & 0x3F) | 0x80);
|
|
126
|
+
offset += 6;
|
|
127
|
+
}
|
|
128
|
+
++i;
|
|
129
|
+
}
|
|
130
|
+
// shink output string buffer if necessary
|
|
131
|
+
if (outSize > offset) {
|
|
132
|
+
dst = __renew(dst, offset);
|
|
133
|
+
}
|
|
134
|
+
return dst;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function decode(src: usize, len: usize, component: bool): usize {
|
|
138
|
+
if (!len) return src;
|
|
139
|
+
|
|
140
|
+
let i: usize = 0, offset: usize = 0, ch: u32 = 0;
|
|
141
|
+
let dst = __new(len << 1, idof<String>());
|
|
142
|
+
|
|
143
|
+
while (i < len) {
|
|
144
|
+
let org = i;
|
|
145
|
+
while (i < len && (ch = load<u16>(src + (i << 1))) != CharCode.PERCENT) i++;
|
|
146
|
+
|
|
147
|
+
if (i > org) {
|
|
148
|
+
let size = i - org << 1;
|
|
149
|
+
// TODO: should we optimize for short cases like 2 byte size?
|
|
150
|
+
memory.copy(
|
|
151
|
+
dst + offset,
|
|
152
|
+
src + (org << 1),
|
|
153
|
+
size
|
|
154
|
+
);
|
|
155
|
+
offset += size;
|
|
156
|
+
if (i >= len) break;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// decode hex
|
|
160
|
+
if (
|
|
161
|
+
i + 2 >= len ||
|
|
162
|
+
ch != CharCode.PERCENT ||
|
|
163
|
+
(ch = loadHex(src, i + 1 << 1)) == -1
|
|
164
|
+
) throw new URIError(E_URI_MALFORMED);
|
|
165
|
+
|
|
166
|
+
i += 3;
|
|
167
|
+
if (ch < 0x80) {
|
|
168
|
+
if (!component && isReserved(ch)) {
|
|
169
|
+
ch = CharCode.PERCENT;
|
|
170
|
+
i -= 2;
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
// decode UTF-8 sequence
|
|
174
|
+
let nb = utf8LenFromUpperByte(ch);
|
|
175
|
+
// minimal surrogate: 2 => 0x80, 3 => 0x800, 4 => 0x10000, _ => -1
|
|
176
|
+
let lo: u32 = 1 << (17 * nb >> 2) - 1;
|
|
177
|
+
// mask: 2 => 31, 3 => 15, 4 => 7, _ => 0
|
|
178
|
+
ch &= nb ? (0x80 >> nb) - 1 : 0;
|
|
179
|
+
|
|
180
|
+
while (--nb != 0) {
|
|
181
|
+
let c1: u32;
|
|
182
|
+
// decode hex
|
|
183
|
+
if (
|
|
184
|
+
i + 2 >= len ||
|
|
185
|
+
load<u16>(src + (i << 1)) != CharCode.PERCENT ||
|
|
186
|
+
(c1 = loadHex(src, i + 1 << 1)) == -1
|
|
187
|
+
) throw new URIError(E_URI_MALFORMED);
|
|
188
|
+
|
|
189
|
+
i += 3;
|
|
190
|
+
if ((c1 & 0xC0) != 0x80) {
|
|
191
|
+
ch = 0;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
ch = (ch << 6) | (c1 & 0x3F);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// check if UTF8 code point properly fit into invalid UTF16 encoding
|
|
198
|
+
if (ch < lo || lo == -1 || ch > 0x10FFFF || (ch >= 0xD800 && ch < 0xE000)) {
|
|
199
|
+
throw new URIError(E_URI_MALFORMED);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// encode UTF16
|
|
203
|
+
if (ch >= 0x10000) {
|
|
204
|
+
ch -= 0x10000;
|
|
205
|
+
let lo = ch >> 10 | 0xD800;
|
|
206
|
+
let hi = (ch & 0x03FF) | 0xDC00;
|
|
207
|
+
store<u32>(dst + offset, lo | (hi << 16));
|
|
208
|
+
offset += 4;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
store<u16>(dst + offset, ch);
|
|
213
|
+
offset += 2;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
assert(offset <= (len << 1));
|
|
217
|
+
// shink output string buffer if necessary
|
|
218
|
+
if ((len << 1) > offset) {
|
|
219
|
+
dst = __renew(dst, offset);
|
|
220
|
+
}
|
|
221
|
+
return dst;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function storeHex(dst: usize, offset: usize, ch: u32): void {
|
|
225
|
+
// @ts-ignore: decorator
|
|
226
|
+
const HEX_CHARS = memory.data<u8>([
|
|
227
|
+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
|
|
228
|
+
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46
|
|
229
|
+
]);
|
|
230
|
+
|
|
231
|
+
store<u16>(dst + offset, CharCode.PERCENT, 0); // %
|
|
232
|
+
store<u32>(
|
|
233
|
+
dst + offset,
|
|
234
|
+
<u32>load<u8>(HEX_CHARS + (ch >> 4 & 0x0F)) |
|
|
235
|
+
<u32>load<u8>(HEX_CHARS + (ch & 0x0F)) << 16,
|
|
236
|
+
2
|
|
237
|
+
); // XX
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function loadHex(src: usize, offset: usize): u32 {
|
|
241
|
+
let c0 = <u32>load<u16>(src + offset, 0);
|
|
242
|
+
let c1 = <u32>load<u16>(src + offset, 2);
|
|
243
|
+
return isHex(c0) && isHex(c1)
|
|
244
|
+
? fromHex(c0) << 4 | fromHex(c1)
|
|
245
|
+
: -1;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// @ts-ignore: decorator
|
|
249
|
+
@inline function fromHex(ch: u32): u32 {
|
|
250
|
+
return (ch | 32) % 39 - 9;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// @ts-ignore: decorator
|
|
254
|
+
@inline function utf8LenFromUpperByte(c0: u32): u32 {
|
|
255
|
+
// same as
|
|
256
|
+
// if (c0 - 0xC0 <= 0xDF - 0xC0) return 2;
|
|
257
|
+
// if (c0 - 0xE0 <= 0xEF - 0xE0) return 3;
|
|
258
|
+
// if (c0 - 0xF0 <= 0xF7 - 0xF0) return 4;
|
|
259
|
+
// return 0;
|
|
260
|
+
return c0 - 0xC0 < 56
|
|
261
|
+
? clz(~(c0 << 24))
|
|
262
|
+
: 0;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// @ts-ignore: decorator
|
|
266
|
+
@inline function isReserved(ch: u32): bool {
|
|
267
|
+
return ch - 35 < 30
|
|
268
|
+
? <bool>load<u8>(URI_RESERVED + (ch - 35))
|
|
269
|
+
: false;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// @ts-ignore: decorator
|
|
273
|
+
@inline function isHex(ch: u32): bool {
|
|
274
|
+
return (ch - CharCode._0 < 10) || ((ch | 32) - CharCode.a < 6);
|
|
275
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../tsconfig-base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "esnext",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"noLib": true,
|
|
7
|
+
"allowJs": false,
|
|
8
|
+
"typeRoots": [ "types" ],
|
|
9
|
+
"types": [ "assembly" ],
|
|
10
|
+
"paths": {
|
|
11
|
+
"*": [
|
|
12
|
+
"./assembly/*"
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|