@qevm/strings 5.7.1 → 5.7.2
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/README.md +2 -3
- package/lib/_version.d.ts +1 -1
- package/lib/_version.js +1 -1
- package/lib/bytes32.d.ts.map +1 -1
- package/lib/bytes32.js.map +1 -1
- package/lib/idna.d.ts.map +1 -1
- package/lib/idna.js +17 -7
- package/lib/idna.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/utf8.d.ts.map +1 -1
- package/lib/utf8.js +39 -29
- package/lib/utf8.js.map +1 -1
- package/package.json +31 -27
- package/src.ts/_version.ts +1 -1
- package/src.ts/bytes32.ts +13 -8
- package/src.ts/idna.ts +112 -58
- package/src.ts/index.ts +12 -7
- package/src.ts/utf8.ts +173 -85
package/README.md
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
String Manipulation Utilities
|
|
2
2
|
=============================
|
|
3
3
|
|
|
4
|
-
This sub-module is part of the [ethers project](https://github.com/ethers-io/ethers.js).
|
|
4
|
+
This sub-module is part of the qethers, a fork of [ethers project](https://github.com/ethers-io/ethers.js).
|
|
5
5
|
|
|
6
6
|
It contains functions to safely convert between UTF-8 data, strings and Bytes32 strings
|
|
7
7
|
(i.e. "short strings").
|
|
8
8
|
|
|
9
|
-
For more information, see the [documentation](https://docs.ethers.io/v5/api/utils/strings/).
|
|
10
9
|
|
|
11
10
|
Importing
|
|
12
11
|
---------
|
|
13
12
|
|
|
14
|
-
Most users will prefer to use the [umbrella package](https://www.npmjs.com/package/
|
|
13
|
+
Most users will prefer to use the [umbrella package](https://www.npmjs.com/package/@qevm/qethers),
|
|
15
14
|
but for those with more specific needs, individual components can be imported.
|
|
16
15
|
|
|
17
16
|
```javascript
|
package/lib/_version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "strings/5.7.
|
|
1
|
+
export declare const version = "strings/5.7.2";
|
|
2
2
|
//# sourceMappingURL=_version.d.ts.map
|
package/lib/_version.js
CHANGED
package/lib/bytes32.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bytes32.d.ts","sourceRoot":"","sources":["../src.ts/bytes32.ts"],"names":[],"mappings":"AAGA,OAAO,EAAY,SAAS,EAAmB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"bytes32.d.ts","sourceRoot":"","sources":["../src.ts/bytes32.ts"],"names":[],"mappings":"AAGA,OAAO,EAAY,SAAS,EAAmB,MAAM,aAAa,CAAC;AAInE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAWxD;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAmB3D"}
|
package/lib/bytes32.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bytes32.js","sourceRoot":"","sources":["../src.ts/bytes32.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;
|
|
1
|
+
{"version":3,"file":"bytes32.js","sourceRoot":"","sources":["../src.ts/bytes32.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAOb,kDAWC;AAED,gDAmBC;AArCD,+CAA2C;AAC3C,uCAAmE;AAEnE,iCAAmD;AAEnD,SAAgB,mBAAmB,CAAC,IAAY;IAC5C,gBAAgB;IAChB,MAAM,KAAK,GAAG,IAAA,kBAAW,EAAC,IAAI,CAAC,CAAC;IAEhC,0CAA0C;IAC1C,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IACjE,CAAC;IAED,wCAAwC;IACxC,OAAO,IAAA,eAAO,EAAC,IAAA,cAAM,EAAC,CAAC,KAAK,EAAE,oBAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,SAAgB,kBAAkB,CAAC,KAAgB;IAC/C,MAAM,IAAI,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAE7B,2CAA2C;IAC3C,IAAI,IAAI,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IAC3D,CAAC;IACD,IAAI,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACnE,CAAC;IAED,4BAA4B;IAC5B,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,EAAE,CAAC;IACb,CAAC;IAED,6BAA6B;IAC7B,OAAO,IAAA,mBAAY,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAC/C,CAAC"}
|
package/lib/idna.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"idna.d.ts","sourceRoot":"","sources":["../src.ts/idna.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"idna.d.ts","sourceRoot":"","sources":["../src.ts/idna.ts"],"names":[],"mappings":"AAmKA,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAsBjE;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAiE9C"}
|
package/lib/idna.js
CHANGED
|
@@ -6,7 +6,7 @@ exports._nameprepTableC = _nameprepTableC;
|
|
|
6
6
|
exports.nameprep = nameprep;
|
|
7
7
|
const utf8_1 = require("./utf8");
|
|
8
8
|
function bytes2(data) {
|
|
9
|
-
if (
|
|
9
|
+
if (data.length % 4 !== 0) {
|
|
10
10
|
throw new Error("bad data");
|
|
11
11
|
}
|
|
12
12
|
let result = [];
|
|
@@ -17,7 +17,9 @@ function bytes2(data) {
|
|
|
17
17
|
}
|
|
18
18
|
function createTable(data, func) {
|
|
19
19
|
if (!func) {
|
|
20
|
-
func = function (value) {
|
|
20
|
+
func = function (value) {
|
|
21
|
+
return [parseInt(value, 16)];
|
|
22
|
+
};
|
|
21
23
|
}
|
|
22
24
|
let lo = 0;
|
|
23
25
|
let result = {};
|
|
@@ -48,7 +50,9 @@ function matchMap(value, ranges) {
|
|
|
48
50
|
for (let i = 0; i < ranges.length; i++) {
|
|
49
51
|
let range = ranges[i];
|
|
50
52
|
lo += range.l;
|
|
51
|
-
if (value >= lo &&
|
|
53
|
+
if (value >= lo &&
|
|
54
|
+
value <= lo + range.h &&
|
|
55
|
+
(value - lo) % (range.d || 1) === 0) {
|
|
52
56
|
if (range.e && range.e.indexOf(value - lo) !== -1) {
|
|
53
57
|
continue;
|
|
54
58
|
}
|
|
@@ -59,7 +63,9 @@ function matchMap(value, ranges) {
|
|
|
59
63
|
}
|
|
60
64
|
const Table_A_1_ranges = createRangeTable("221,13-1b,5f-,40-10,51-f,11-3,3-3,2-2,2-4,8,2,15,2d,28-8,88,48,27-,3-5,11-20,27-,8,28,3-5,12,18,b-a,1c-4,6-16,2-d,2-2,2,1b-4,17-9,8f-,10,f,1f-2,1c-34,33-14e,4,36-,13-,6-2,1a-f,4,9-,3-,17,8,2-2,5-,2,8-,3-,4-8,2-3,3,6-,16-6,2-,7-3,3-,17,8,3,3,3-,2,6-3,3-,4-a,5,2-6,10-b,4,8,2,4,17,8,3,6-,b,4,4-,2-e,2-4,b-10,4,9-,3-,17,8,3-,5-,9-2,3-,4-7,3-3,3,4-3,c-10,3,7-2,4,5-2,3,2,3-2,3-2,4-2,9,4-3,6-2,4,5-8,2-e,d-d,4,9,4,18,b,6-3,8,4,5-6,3-8,3-3,b-11,3,9,4,18,b,6-3,8,4,5-6,3-6,2,3-3,b-11,3,9,4,18,11-3,7-,4,5-8,2-7,3-3,b-11,3,13-2,19,a,2-,8-2,2-3,7,2,9-11,4-b,3b-3,1e-24,3,2-,3,2-,2-5,5,8,4,2,2-,3,e,4-,6,2,7-,b-,3-21,49,23-5,1c-3,9,25,10-,2-2f,23,6,3,8-2,5-5,1b-45,27-9,2a-,2-3,5b-4,45-4,53-5,8,40,2,5-,8,2,5-,28,2,5-,20,2,5-,8,2,5-,8,8,18,20,2,5-,8,28,14-5,1d-22,56-b,277-8,1e-2,52-e,e,8-a,18-8,15-b,e,4,3-b,5e-2,b-15,10,b-5,59-7,2b-555,9d-3,5b-5,17-,7-,27-,7-,9,2,2,2,20-,36,10,f-,7,14-,4,a,54-3,2-6,6-5,9-,1c-10,13-1d,1c-14,3c-,10-6,32-b,240-30,28-18,c-14,a0,115-,3,66-,b-76,5,5-,1d,24,2,5-2,2,8-,35-2,19,f-10,1d-3,311-37f,1b,5a-b,d7-19,d-3,41,57-,68-4,29-3,5f,29-37,2e-2,25-c,2c-2,4e-3,30,78-3,64-,20,19b7-49,51a7-59,48e-2,38-738,2ba5-5b,222f-,3c-94,8-b,6-4,1b,6,2,3,3,6d-20,16e-f,41-,37-7,2e-2,11-f,5-b,18-,b,14,5-3,6,88-,2,bf-2,7-,7-,7-,4-2,8,8-9,8-2ff,20,5-b,1c-b4,27-,27-cbb1,f7-9,28-2,b5-221,56,48,3-,2-,3-,5,d,2,5,3,42,5-,9,8,1d,5,6,2-2,8,153-3,123-3,33-27fd,a6da-5128,21f-5df,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3,2-1d,61-ff7d");
|
|
61
65
|
// @TODO: Make this relative...
|
|
62
|
-
const Table_B_1_flags = "ad,34f,1806,180b,180c,180d,200b,200c,200d,2060,feff"
|
|
66
|
+
const Table_B_1_flags = "ad,34f,1806,180b,180c,180d,200b,200c,200d,2060,feff"
|
|
67
|
+
.split(",")
|
|
68
|
+
.map((v) => parseInt(v, 16));
|
|
63
69
|
const Table_B_2_ranges = [
|
|
64
70
|
{ h: 25, s: 32, l: 65 },
|
|
65
71
|
{ h: 30, s: 32, e: [23], l: 127 },
|
|
@@ -102,7 +108,7 @@ const Table_B_2_ranges = [
|
|
|
102
108
|
{ h: 24, s: -119601, e: [17], l: 58 },
|
|
103
109
|
{ h: 24, s: -119659, e: [17], l: 58 },
|
|
104
110
|
{ h: 24, s: -119717, e: [17], l: 58 },
|
|
105
|
-
{ h: 24, s: -119775, e: [17], l: 58 }
|
|
111
|
+
{ h: 24, s: -119775, e: [17], l: 58 },
|
|
106
112
|
];
|
|
107
113
|
const Table_B_2_lut_abs = createTable("b5:3bc,c3:ff,7:73,2:253,5:254,3:256,1:257,5:259,1:25b,3:260,1:263,2:269,1:268,5:26f,1:272,2:275,7:280,3:283,5:288,3:28a,1:28b,5:292,3f:195,1:1bf,29:19e,125:3b9,8b:3b2,1:3b8,1:3c5,3:3c6,1:3c0,1a:3ba,1:3c1,1:3c3,2:3b8,1:3b5,1bc9:3b9,1c:1f76,1:1f77,f:1f7a,1:1f7b,d:1f78,1:1f79,1:1f7c,1:1f7d,107:63,5:25b,4:68,1:68,1:68,3:69,1:69,1:6c,3:6e,4:70,1:71,1:72,1:72,1:72,7:7a,2:3c9,2:7a,2:6b,1:e5,1:62,1:63,3:65,1:66,2:6d,b:3b3,1:3c0,6:64,1b574:3b8,1a:3c3,20:3b8,1a:3c3,20:3b8,1a:3c3,20:3b8,1a:3c3,20:3b8,1a:3c3");
|
|
108
114
|
const Table_B_2_lut_rel = createTable("179:1,2:1,2:1,5:1,2:1,a:4f,a:1,8:1,2:1,2:1,3:1,5:1,3:1,4:1,2:1,3:1,4:1,8:2,1:1,2:2,1:1,2:2,27:2,195:26,2:25,1:25,1:25,2:40,2:3f,1:3f,33:1,11:-6,1:-9,1ac7:-3a,6d:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,b:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,c:-8,2:-8,2:-8,2:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,49:-8,1:-8,1:-4a,1:-4a,d:-56,1:-56,1:-56,1:-56,d:-8,1:-8,f:-8,1:-8,3:-7");
|
|
@@ -110,7 +116,9 @@ const Table_B_2_complex = createTable("df:00730073,51:00690307,19:02BC006E,a7:00
|
|
|
110
116
|
const Table_C_ranges = createRangeTable("80-20,2a0-,39c,32,f71,18e,7f2-f,19-7,30-4,7-5,f81-b,5,a800-20ff,4d1-1f,110,fa-6,d174-7,2e84-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,2,1f-5f,ff7f-20001");
|
|
111
117
|
function flatten(values) {
|
|
112
118
|
return values.reduce((accum, value) => {
|
|
113
|
-
value.forEach((value) => {
|
|
119
|
+
value.forEach((value) => {
|
|
120
|
+
accum.push(value);
|
|
121
|
+
});
|
|
114
122
|
return accum;
|
|
115
123
|
}, []);
|
|
116
124
|
}
|
|
@@ -181,7 +189,9 @@ function nameprep(value) {
|
|
|
181
189
|
// IDNA extras
|
|
182
190
|
let name = (0, utf8_1._toUtf8String)(codes);
|
|
183
191
|
// IDNA: 4.2.3.1
|
|
184
|
-
if (name.substring(0, 1) === "-" ||
|
|
192
|
+
if (name.substring(0, 1) === "-" ||
|
|
193
|
+
name.substring(2, 4) === "--" ||
|
|
194
|
+
name.substring(name.length - 1) === "-") {
|
|
185
195
|
throw new Error("invalid hyphen");
|
|
186
196
|
}
|
|
187
197
|
return name;
|
package/lib/idna.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"idna.js","sourceRoot":"","sources":["../src.ts/idna.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;
|
|
1
|
+
{"version":3,"file":"idna.js","sourceRoot":"","sources":["../src.ts/idna.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAmKb,4CAEC;AAED,4CAsBC;AAED,0CAEC;AAED,4BAiEC;AAlQD,iCAIgB;AAYhB,SAAS,MAAM,CAAC,IAAY;IACxB,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;IAChC,CAAC;IACD,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACtC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,SAAS,WAAW,CAChB,IAAY,EACZ,IAAuC;IAEvC,IAAI,CAAC,IAAI,EAAE,CAAC;QACR,IAAI,GAAG,UAAU,KAAa;YAC1B,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;QACjC,CAAC,CAAC;IACN,CAAC;IAED,IAAI,EAAE,GAAG,CAAC,CAAC;IAEX,IAAI,MAAM,GAAU,EAAE,CAAC;IACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC7B,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC5B,EAAE,IAAI,QAAQ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d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { formatBytes32String, parseBytes32String } from "./bytes32";
|
|
2
2
|
import { nameprep } from "./idna";
|
|
3
3
|
import { _toEscapedUtf8String, toUtf8Bytes, toUtf8CodePoints, toUtf8String, UnicodeNormalizationForm, Utf8ErrorFunc, Utf8ErrorFuncs, Utf8ErrorReason } from "./utf8";
|
|
4
|
-
export { _toEscapedUtf8String, toUtf8Bytes, toUtf8CodePoints, toUtf8String, Utf8ErrorFunc, Utf8ErrorFuncs, Utf8ErrorReason, UnicodeNormalizationForm, formatBytes32String, parseBytes32String, nameprep };
|
|
4
|
+
export { _toEscapedUtf8String, toUtf8Bytes, toUtf8CodePoints, toUtf8String, Utf8ErrorFunc, Utf8ErrorFuncs, Utf8ErrorReason, UnicodeNormalizationForm, formatBytes32String, parseBytes32String, nameprep, };
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src.ts/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src.ts/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EACH,oBAAoB,EACpB,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,wBAAwB,EACxB,aAAa,EACb,cAAc,EACd,eAAe,EAClB,MAAM,QAAQ,CAAC;AAEhB,OAAO,EACH,oBAAoB,EACpB,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,eAAe,EACf,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EAClB,QAAQ,GACX,CAAC"}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src.ts/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb,uCAAoE;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src.ts/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb,uCAAoE;AAsBhE,oGAtBK,6BAAmB,OAsBL;AACnB,mGAvB0B,4BAAkB,OAuB1B;AAtBtB,iCAAkC;AAuB9B,yFAvBK,eAAQ,OAuBL;AAtBZ,iCASgB;AAGZ,qGAXA,2BAAoB,OAWA;AACpB,4FAXA,kBAAW,OAWA;AACX,iGAXA,uBAAgB,OAWA;AAChB,6FAXA,mBAAY,OAWA;AAIZ,yGAdA,+BAAwB,OAcA;AAFxB,+FAVA,qBAAc,OAUA;AACd,gGAVA,sBAAe,OAUA"}
|
package/lib/utf8.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utf8.d.ts","sourceRoot":"","sources":["../src.ts/utf8.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,SAAS,EAAE,MAAM,aAAa,CAAC;AAQlD,oBAAY,wBAAwB;IAChC,OAAO,
|
|
1
|
+
{"version":3,"file":"utf8.d.ts","sourceRoot":"","sources":["../src.ts/utf8.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,SAAS,EAAE,MAAM,aAAa,CAAC;AAQlD,oBAAY,wBAAwB;IAChC,OAAO,KAAK;IACZ,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,IAAI,SAAS;CAChB;AAED,oBAAY,eAAe;IAGvB,mBAAmB,iCAAiC;IAIpD,UAAU,yBAAyB;IAInC,OAAO,mBAAmB;IAI1B,gBAAgB,8BAA8B;IAK9C,YAAY,uBAAuB;IAKnC,eAAe,qBAAqB;IAKpC,QAAQ,4BAA4B;CACvC;AAED,MAAM,MAAM,aAAa,GAAG,CACxB,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,EACxB,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,EACrB,YAAY,CAAC,EAAE,MAAM,KACpB,MAAM,CAAC;AAqEZ,eAAO,MAAM,cAAc,EAAE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAAA;CAI1D,CAAC;AAsIH,wBAAgB,WAAW,CACvB,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,wBAA2D,GAClE,UAAU,CAqCZ;AAOD,wBAAgB,oBAAoB,CAChC,KAAK,EAAE,SAAS,EAChB,OAAO,CAAC,EAAE,aAAa,GACxB,MAAM,CAuCR;AAED,wBAAgB,aAAa,CAAC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAa/D;AAED,wBAAgB,YAAY,CACxB,KAAK,EAAE,SAAS,EAChB,OAAO,CAAC,EAAE,aAAa,GACxB,MAAM,CAER;AAED,wBAAgB,gBAAgB,CAC5B,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,wBAA2D,GAClE,KAAK,CAAC,MAAM,CAAC,CAEf"}
|
package/lib/utf8.js
CHANGED
|
@@ -7,7 +7,7 @@ exports._toUtf8String = _toUtf8String;
|
|
|
7
7
|
exports.toUtf8String = toUtf8String;
|
|
8
8
|
exports.toUtf8CodePoints = toUtf8CodePoints;
|
|
9
9
|
const bytes_1 = require("@qevm/bytes");
|
|
10
|
-
const logger_1 = require("@
|
|
10
|
+
const logger_1 = require("@qevm/logger");
|
|
11
11
|
const _version_1 = require("./_version");
|
|
12
12
|
const logger = new logger_1.Logger(_version_1.version);
|
|
13
13
|
///////////////////////////////
|
|
@@ -19,7 +19,6 @@ var UnicodeNormalizationForm;
|
|
|
19
19
|
UnicodeNormalizationForm["NFKC"] = "NFKC";
|
|
20
20
|
UnicodeNormalizationForm["NFKD"] = "NFKD";
|
|
21
21
|
})(UnicodeNormalizationForm || (exports.UnicodeNormalizationForm = UnicodeNormalizationForm = {}));
|
|
22
|
-
;
|
|
23
22
|
var Utf8ErrorReason;
|
|
24
23
|
(function (Utf8ErrorReason) {
|
|
25
24
|
// A continuation byte was present where there was nothing to continue
|
|
@@ -47,13 +46,13 @@ var Utf8ErrorReason;
|
|
|
47
46
|
// - badCodepoint = the computed codepoint; already bounds checked
|
|
48
47
|
Utf8ErrorReason["OVERLONG"] = "overlong representation";
|
|
49
48
|
})(Utf8ErrorReason || (exports.Utf8ErrorReason = Utf8ErrorReason = {}));
|
|
50
|
-
;
|
|
51
49
|
function errorFunc(reason, offset, bytes, output, badCodepoint) {
|
|
52
50
|
return logger.throwArgumentError(`invalid codepoint at offset ${offset}; ${reason}`, "bytes", bytes);
|
|
53
51
|
}
|
|
54
52
|
function ignoreFunc(reason, offset, bytes, output, badCodepoint) {
|
|
55
53
|
// If there is an invalid prefix (including stray continuation), skip any additional continuation bytes
|
|
56
|
-
if (reason === Utf8ErrorReason.BAD_PREFIX ||
|
|
54
|
+
if (reason === Utf8ErrorReason.BAD_PREFIX ||
|
|
55
|
+
reason === Utf8ErrorReason.UNEXPECTED_CONTINUE) {
|
|
57
56
|
let i = 0;
|
|
58
57
|
for (let o = offset + 1; o < bytes.length; o++) {
|
|
59
58
|
if (bytes[o] >> 6 !== 0x02) {
|
|
@@ -86,7 +85,7 @@ function replaceFunc(reason, offset, bytes, output, badCodepoint) {
|
|
|
86
85
|
exports.Utf8ErrorFuncs = Object.freeze({
|
|
87
86
|
error: errorFunc,
|
|
88
87
|
ignore: ignoreFunc,
|
|
89
|
-
replace: replaceFunc
|
|
88
|
+
replace: replaceFunc,
|
|
90
89
|
});
|
|
91
90
|
// http://stackoverflow.com/questions/13356493/decode-utf-8-with-javascript#13691499
|
|
92
91
|
function getUtf8CodePoints(bytes, onError) {
|
|
@@ -146,7 +145,6 @@ function getUtf8CodePoints(bytes, onError) {
|
|
|
146
145
|
res = null;
|
|
147
146
|
break;
|
|
148
147
|
}
|
|
149
|
-
;
|
|
150
148
|
res = (res << 6) | (nextChar & 0x3f);
|
|
151
149
|
i++;
|
|
152
150
|
}
|
|
@@ -210,41 +208,53 @@ function toUtf8Bytes(str, form = UnicodeNormalizationForm.current) {
|
|
|
210
208
|
}
|
|
211
209
|
return (0, bytes_1.arrayify)(result);
|
|
212
210
|
}
|
|
213
|
-
;
|
|
214
211
|
function escapeChar(value) {
|
|
215
|
-
const hex =
|
|
212
|
+
const hex = "0000" + value.toString(16);
|
|
216
213
|
return "\\u" + hex.substring(hex.length - 4);
|
|
217
214
|
}
|
|
218
215
|
function _toEscapedUtf8String(bytes, onError) {
|
|
219
|
-
return '"' +
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
216
|
+
return ('"' +
|
|
217
|
+
getUtf8CodePoints(bytes, onError)
|
|
218
|
+
.map((codePoint) => {
|
|
219
|
+
if (codePoint < 256) {
|
|
220
|
+
switch (codePoint) {
|
|
221
|
+
case 8:
|
|
222
|
+
return "\\b";
|
|
223
|
+
case 9:
|
|
224
|
+
return "\\t";
|
|
225
|
+
case 10:
|
|
226
|
+
return "\\n";
|
|
227
|
+
case 13:
|
|
228
|
+
return "\\r";
|
|
229
|
+
case 34:
|
|
230
|
+
return '\\"';
|
|
231
|
+
case 92:
|
|
232
|
+
return "\\\\";
|
|
233
|
+
}
|
|
234
|
+
if (codePoint >= 32 && codePoint < 127) {
|
|
235
|
+
return String.fromCharCode(codePoint);
|
|
236
|
+
}
|
|
228
237
|
}
|
|
229
|
-
if (codePoint
|
|
230
|
-
return
|
|
238
|
+
if (codePoint <= 0xffff) {
|
|
239
|
+
return escapeChar(codePoint);
|
|
231
240
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}).join("") + '"';
|
|
241
|
+
codePoint -= 0x10000;
|
|
242
|
+
return (escapeChar(((codePoint >> 10) & 0x3ff) + 0xd800) +
|
|
243
|
+
escapeChar((codePoint & 0x3ff) + 0xdc00));
|
|
244
|
+
})
|
|
245
|
+
.join("") +
|
|
246
|
+
'"');
|
|
239
247
|
}
|
|
240
248
|
function _toUtf8String(codePoints) {
|
|
241
|
-
return codePoints
|
|
249
|
+
return codePoints
|
|
250
|
+
.map((codePoint) => {
|
|
242
251
|
if (codePoint <= 0xffff) {
|
|
243
252
|
return String.fromCharCode(codePoint);
|
|
244
253
|
}
|
|
245
254
|
codePoint -= 0x10000;
|
|
246
|
-
return String.fromCharCode(((
|
|
247
|
-
})
|
|
255
|
+
return String.fromCharCode(((codePoint >> 10) & 0x3ff) + 0xd800, (codePoint & 0x3ff) + 0xdc00);
|
|
256
|
+
})
|
|
257
|
+
.join("");
|
|
248
258
|
}
|
|
249
259
|
function toUtf8String(bytes, onError) {
|
|
250
260
|
return _toUtf8String(getUtf8CodePoints(bytes, onError));
|
package/lib/utf8.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utf8.js","sourceRoot":"","sources":["../src.ts/utf8.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;
|
|
1
|
+
{"version":3,"file":"utf8.js","sourceRoot":"","sources":["../src.ts/utf8.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAwQb,kCAwCC;AAOD,oDA0CC;AAED,sCAaC;AAED,oCAKC;AAED,4CAKC;AA5XD,uCAAkD;AAElD,yCAAsC;AACtC,yCAAqC;AACrC,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,kBAAO,CAAC,CAAC;AAEnC,+BAA+B;AAE/B,IAAY,wBAMX;AAND,WAAY,wBAAwB;IAChC,wCAAY,CAAA;IACZ,uCAAW,CAAA;IACX,uCAAW,CAAA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AC,SAAS,CAAC,CAAC;QAC1C,CAAC;QACD,SAAS,IAAI,OAAO,CAAC;QACrB,OAAO,MAAM,CAAC,YAAY,CACtB,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,GAAG,KAAK,CAAC,GAAG,MAAM,EACpC,CAAC,SAAS,GAAG,KAAK,CAAC,GAAG,MAAM,CAC/B,CAAC;IACN,CAAC,CAAC;SACD,IAAI,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC;AAED,SAAgB,YAAY,CACxB,KAAgB,EAChB,OAAuB;IAEvB,OAAO,aAAa,CAAC,iBAAiB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,SAAgB,gBAAgB,CAC5B,GAAW,EACX,OAAiC,wBAAwB,CAAC,OAAO;IAEjE,OAAO,iBAAiB,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;AACrD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
2
|
+
"contributors": [
|
|
3
|
+
"Eugene Kuleshov <kulevgen32@gmail.com>",
|
|
4
|
+
"Richard Moore <me@ricmoo.com>"
|
|
5
|
+
],
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@qevm/bytes": "^5.7.2",
|
|
8
|
+
"@qevm/constants": "^5.7.2",
|
|
9
|
+
"@qevm/logger": "^5.7.1"
|
|
10
|
+
},
|
|
11
|
+
"description": "String utility functions.",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"QEVM",
|
|
14
|
+
"QuantumEVM",
|
|
15
|
+
"qethers",
|
|
16
|
+
"strings",
|
|
17
|
+
"utf8"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"main": "./lib/index.js",
|
|
21
|
+
"module": "./lib.esm/index.js",
|
|
22
|
+
"name": "@qevm/strings",
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
28
|
+
},
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"tarballHash": "0xbde9a4dad59a25a6b1956cf36146ddcceb251b39b2761ac4899b24876656c496",
|
|
31
|
+
"types": "./lib/index.d.ts",
|
|
32
|
+
"version": "5.7.2"
|
|
29
33
|
}
|
package/src.ts/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "strings/5.7.
|
|
1
|
+
export const version = "strings/5.7.2";
|
package/src.ts/bytes32.ts
CHANGED
|
@@ -5,31 +5,36 @@ import { arrayify, BytesLike, concat, hexlify } from "@qevm/bytes";
|
|
|
5
5
|
|
|
6
6
|
import { toUtf8Bytes, toUtf8String } from "./utf8";
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
export function formatBytes32String(text: string): string {
|
|
10
|
-
|
|
11
9
|
// Get the bytes
|
|
12
10
|
const bytes = toUtf8Bytes(text);
|
|
13
11
|
|
|
14
12
|
// Check we have room for null-termination
|
|
15
|
-
if (bytes.length > 31) {
|
|
13
|
+
if (bytes.length > 31) {
|
|
14
|
+
throw new Error("bytes32 string must be less than 32 bytes");
|
|
15
|
+
}
|
|
16
16
|
|
|
17
17
|
// Zero-pad (implicitly null-terminates)
|
|
18
|
-
return hexlify(concat([
|
|
18
|
+
return hexlify(concat([bytes, HashZero]).slice(0, 32));
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function parseBytes32String(bytes: BytesLike): string {
|
|
22
22
|
const data = arrayify(bytes);
|
|
23
23
|
|
|
24
24
|
// Must be 32 bytes with a null-termination
|
|
25
|
-
if (data.length !== 32) {
|
|
26
|
-
|
|
25
|
+
if (data.length !== 32) {
|
|
26
|
+
throw new Error("invalid bytes32 - not 32 bytes long");
|
|
27
|
+
}
|
|
28
|
+
if (data[31] !== 0) {
|
|
29
|
+
throw new Error("invalid bytes32 string - no null terminator");
|
|
30
|
+
}
|
|
27
31
|
|
|
28
32
|
// Find the null termination
|
|
29
33
|
let length = 31;
|
|
30
|
-
while (data[length - 1] === 0) {
|
|
34
|
+
while (data[length - 1] === 0) {
|
|
35
|
+
length--;
|
|
36
|
+
}
|
|
31
37
|
|
|
32
38
|
// Determine the string value
|
|
33
39
|
return toUtf8String(data.slice(0, length));
|
|
34
40
|
}
|
|
35
|
-
|
package/src.ts/idna.ts
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
toUtf8CodePoints,
|
|
5
|
+
_toUtf8String,
|
|
6
|
+
UnicodeNormalizationForm,
|
|
7
|
+
} from "./utf8";
|
|
4
8
|
|
|
5
9
|
type Ranged = {
|
|
6
|
-
l: number
|
|
7
|
-
h: number
|
|
8
|
-
d?: number
|
|
9
|
-
s?: number
|
|
10
|
-
e?: Array<number
|
|
10
|
+
l: number; // Lo value
|
|
11
|
+
h: number; // High value (less the lo)
|
|
12
|
+
d?: number; // Delta/stride (default: 1)
|
|
13
|
+
s?: number; // Shift (default: 1)
|
|
14
|
+
e?: Array<number>; // Exceptions to skip
|
|
11
15
|
};
|
|
12
16
|
|
|
13
|
-
type Table = { [
|
|
17
|
+
type Table = { [src: number]: Array<number> };
|
|
14
18
|
|
|
15
19
|
function bytes2(data: string): Array<number> {
|
|
16
|
-
if (
|
|
20
|
+
if (data.length % 4 !== 0) {
|
|
21
|
+
throw new Error("bad data");
|
|
22
|
+
}
|
|
17
23
|
let result = [];
|
|
18
24
|
for (let i = 0; i < data.length; i += 4) {
|
|
19
25
|
result.push(parseInt(data.substring(i, i + 4), 16));
|
|
@@ -21,14 +27,19 @@ function bytes2(data: string): Array<number> {
|
|
|
21
27
|
return result;
|
|
22
28
|
}
|
|
23
29
|
|
|
24
|
-
function createTable(
|
|
30
|
+
function createTable(
|
|
31
|
+
data: string,
|
|
32
|
+
func?: (value: string) => Array<number>,
|
|
33
|
+
): Table {
|
|
25
34
|
if (!func) {
|
|
26
|
-
func = function(value: string) {
|
|
35
|
+
func = function (value: string) {
|
|
36
|
+
return [parseInt(value, 16)];
|
|
37
|
+
};
|
|
27
38
|
}
|
|
28
39
|
|
|
29
40
|
let lo = 0;
|
|
30
41
|
|
|
31
|
-
let result: Table = {
|
|
42
|
+
let result: Table = {};
|
|
32
43
|
data.split(",").forEach((pair) => {
|
|
33
44
|
let comps = pair.split(":");
|
|
34
45
|
lo += parseInt(comps[0], 16);
|
|
@@ -59,36 +70,46 @@ function matchMap(value: number, ranges: Array<Ranged>): Ranged {
|
|
|
59
70
|
for (let i = 0; i < ranges.length; i++) {
|
|
60
71
|
let range = ranges[i];
|
|
61
72
|
lo += range.l;
|
|
62
|
-
if (
|
|
63
|
-
|
|
73
|
+
if (
|
|
74
|
+
value >= lo &&
|
|
75
|
+
value <= lo + range.h &&
|
|
76
|
+
(value - lo) % (range.d || 1) === 0
|
|
77
|
+
) {
|
|
78
|
+
if (range.e && range.e.indexOf(value - lo) !== -1) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
64
81
|
return range;
|
|
65
82
|
}
|
|
66
83
|
}
|
|
67
84
|
return null;
|
|
68
85
|
}
|
|
69
86
|
|
|
70
|
-
const Table_A_1_ranges = createRangeTable(
|
|
87
|
+
const Table_A_1_ranges = createRangeTable(
|
|
88
|
+
"221,13-1b,5f-,40-10,51-f,11-3,3-3,2-2,2-4,8,2,15,2d,28-8,88,48,27-,3-5,11-20,27-,8,28,3-5,12,18,b-a,1c-4,6-16,2-d,2-2,2,1b-4,17-9,8f-,10,f,1f-2,1c-34,33-14e,4,36-,13-,6-2,1a-f,4,9-,3-,17,8,2-2,5-,2,8-,3-,4-8,2-3,3,6-,16-6,2-,7-3,3-,17,8,3,3,3-,2,6-3,3-,4-a,5,2-6,10-b,4,8,2,4,17,8,3,6-,b,4,4-,2-e,2-4,b-10,4,9-,3-,17,8,3-,5-,9-2,3-,4-7,3-3,3,4-3,c-10,3,7-2,4,5-2,3,2,3-2,3-2,4-2,9,4-3,6-2,4,5-8,2-e,d-d,4,9,4,18,b,6-3,8,4,5-6,3-8,3-3,b-11,3,9,4,18,b,6-3,8,4,5-6,3-6,2,3-3,b-11,3,9,4,18,11-3,7-,4,5-8,2-7,3-3,b-11,3,13-2,19,a,2-,8-2,2-3,7,2,9-11,4-b,3b-3,1e-24,3,2-,3,2-,2-5,5,8,4,2,2-,3,e,4-,6,2,7-,b-,3-21,49,23-5,1c-3,9,25,10-,2-2f,23,6,3,8-2,5-5,1b-45,27-9,2a-,2-3,5b-4,45-4,53-5,8,40,2,5-,8,2,5-,28,2,5-,20,2,5-,8,2,5-,8,8,18,20,2,5-,8,28,14-5,1d-22,56-b,277-8,1e-2,52-e,e,8-a,18-8,15-b,e,4,3-b,5e-2,b-15,10,b-5,59-7,2b-555,9d-3,5b-5,17-,7-,27-,7-,9,2,2,2,20-,36,10,f-,7,14-,4,a,54-3,2-6,6-5,9-,1c-10,13-1d,1c-14,3c-,10-6,32-b,240-30,28-18,c-14,a0,115-,3,66-,b-76,5,5-,1d,24,2,5-2,2,8-,35-2,19,f-10,1d-3,311-37f,1b,5a-b,d7-19,d-3,41,57-,68-4,29-3,5f,29-37,2e-2,25-c,2c-2,4e-3,30,78-3,64-,20,19b7-49,51a7-59,48e-2,38-738,2ba5-5b,222f-,3c-94,8-b,6-4,1b,6,2,3,3,6d-20,16e-f,41-,37-7,2e-2,11-f,5-b,18-,b,14,5-3,6,88-,2,bf-2,7-,7-,7-,4-2,8,8-9,8-2ff,20,5-b,1c-b4,27-,27-cbb1,f7-9,28-2,b5-221,56,48,3-,2-,3-,5,d,2,5,3,42,5-,9,8,1d,5,6,2-2,8,153-3,123-3,33-27fd,a6da-5128,21f-5df,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3,2-1d,61-ff7d",
|
|
89
|
+
);
|
|
71
90
|
|
|
72
91
|
// @TODO: Make this relative...
|
|
73
|
-
const Table_B_1_flags = "ad,34f,1806,180b,180c,180d,200b,200c,200d,2060,feff"
|
|
92
|
+
const Table_B_1_flags = "ad,34f,1806,180b,180c,180d,200b,200c,200d,2060,feff"
|
|
93
|
+
.split(",")
|
|
94
|
+
.map((v) => parseInt(v, 16));
|
|
74
95
|
|
|
75
96
|
const Table_B_2_ranges: Array<Ranged> = [
|
|
76
97
|
{ h: 25, s: 32, l: 65 },
|
|
77
|
-
{ h: 30, s: 32, e: [
|
|
78
|
-
{ h: 54, s: 1, e: [
|
|
98
|
+
{ h: 30, s: 32, e: [23], l: 127 },
|
|
99
|
+
{ h: 54, s: 1, e: [48], l: 64, d: 2 },
|
|
79
100
|
{ h: 14, s: 1, l: 57, d: 2 },
|
|
80
101
|
{ h: 44, s: 1, l: 17, d: 2 },
|
|
81
|
-
{ h: 10, s: 1, e: [
|
|
102
|
+
{ h: 10, s: 1, e: [2, 6, 8], l: 61, d: 2 },
|
|
82
103
|
{ h: 16, s: 1, l: 68, d: 2 },
|
|
83
|
-
{ h: 84, s: 1, e: [
|
|
84
|
-
{ h: 26, s: 32, e: [
|
|
104
|
+
{ h: 84, s: 1, e: [18, 24, 66], l: 19, d: 2 },
|
|
105
|
+
{ h: 26, s: 32, e: [17], l: 435 },
|
|
85
106
|
{ h: 22, s: 1, l: 71, d: 2 },
|
|
86
107
|
{ h: 15, s: 80, l: 40 },
|
|
87
108
|
{ h: 31, s: 32, l: 16 },
|
|
88
109
|
{ h: 32, s: 1, l: 80, d: 2 },
|
|
89
110
|
{ h: 52, s: 1, l: 42, d: 2 },
|
|
90
111
|
{ h: 12, s: 1, l: 55, d: 2 },
|
|
91
|
-
{ h: 40, s: 1, e: [
|
|
112
|
+
{ h: 40, s: 1, e: [38], l: 15, d: 2 },
|
|
92
113
|
{ h: 14, s: 1, l: 48, d: 2 },
|
|
93
114
|
{ h: 37, s: 48, l: 49 },
|
|
94
115
|
{ h: 148, s: 1, l: 6351, d: 2 },
|
|
@@ -100,34 +121,44 @@ const Table_B_2_ranges: Array<Ranged> = [
|
|
|
100
121
|
{ h: 25, s: -119711, l: 53248 },
|
|
101
122
|
{ h: 25, s: -119763, l: 52 },
|
|
102
123
|
{ h: 25, s: -119815, l: 52 },
|
|
103
|
-
{ h: 25, s: -119867, e: [
|
|
124
|
+
{ h: 25, s: -119867, e: [1, 4, 5, 7, 8, 11, 12, 17], l: 52 },
|
|
104
125
|
{ h: 25, s: -119919, l: 52 },
|
|
105
|
-
{ h: 24, s: -119971, e: [
|
|
106
|
-
{ h: 24, s: -120023, e: [
|
|
126
|
+
{ h: 24, s: -119971, e: [2, 7, 8, 17], l: 52 },
|
|
127
|
+
{ h: 24, s: -120023, e: [2, 7, 13, 15, 16, 17], l: 52 },
|
|
107
128
|
{ h: 25, s: -120075, l: 52 },
|
|
108
129
|
{ h: 25, s: -120127, l: 52 },
|
|
109
130
|
{ h: 25, s: -120179, l: 52 },
|
|
110
131
|
{ h: 25, s: -120231, l: 52 },
|
|
111
132
|
{ h: 25, s: -120283, l: 52 },
|
|
112
133
|
{ h: 25, s: -120335, l: 52 },
|
|
113
|
-
{ h: 24, s: -119543, e: [
|
|
114
|
-
{ h: 24, s: -119601, e: [
|
|
115
|
-
{ h: 24, s: -119659, e: [
|
|
116
|
-
{ h: 24, s: -119717, e: [
|
|
117
|
-
{ h: 24, s: -119775, e: [
|
|
134
|
+
{ h: 24, s: -119543, e: [17], l: 56 },
|
|
135
|
+
{ h: 24, s: -119601, e: [17], l: 58 },
|
|
136
|
+
{ h: 24, s: -119659, e: [17], l: 58 },
|
|
137
|
+
{ h: 24, s: -119717, e: [17], l: 58 },
|
|
138
|
+
{ h: 24, s: -119775, e: [17], l: 58 },
|
|
118
139
|
];
|
|
119
|
-
const Table_B_2_lut_abs = createTable(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
140
|
+
const Table_B_2_lut_abs = createTable(
|
|
141
|
+
"b5:3bc,c3:ff,7:73,2:253,5:254,3:256,1:257,5:259,1:25b,3:260,1:263,2:269,1:268,5:26f,1:272,2:275,7:280,3:283,5:288,3:28a,1:28b,5:292,3f:195,1:1bf,29:19e,125:3b9,8b:3b2,1:3b8,1:3c5,3:3c6,1:3c0,1a:3ba,1:3c1,1:3c3,2:3b8,1:3b5,1bc9:3b9,1c:1f76,1:1f77,f:1f7a,1:1f7b,d:1f78,1:1f79,1:1f7c,1:1f7d,107:63,5:25b,4:68,1:68,1:68,3:69,1:69,1:6c,3:6e,4:70,1:71,1:72,1:72,1:72,7:7a,2:3c9,2:7a,2:6b,1:e5,1:62,1:63,3:65,1:66,2:6d,b:3b3,1:3c0,6:64,1b574:3b8,1a:3c3,20:3b8,1a:3c3,20:3b8,1a:3c3,20:3b8,1a:3c3,20:3b8,1a:3c3",
|
|
142
|
+
);
|
|
143
|
+
const Table_B_2_lut_rel = createTable(
|
|
144
|
+
"179:1,2:1,2:1,5:1,2:1,a:4f,a:1,8:1,2:1,2:1,3:1,5:1,3:1,4:1,2:1,3:1,4:1,8:2,1:1,2:2,1:1,2:2,27:2,195:26,2:25,1:25,1:25,2:40,2:3f,1:3f,33:1,11:-6,1:-9,1ac7:-3a,6d:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,b:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,c:-8,2:-8,2:-8,2:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,49:-8,1:-8,1:-4a,1:-4a,d:-56,1:-56,1:-56,1:-56,d:-8,1:-8,f:-8,1:-8,3:-7",
|
|
145
|
+
);
|
|
146
|
+
const Table_B_2_complex = createTable(
|
|
147
|
+
"df:00730073,51:00690307,19:02BC006E,a7:006A030C,18a:002003B9,16:03B903080301,20:03C503080301,1d7:05650582,190f:00680331,1:00740308,1:0077030A,1:0079030A,1:006102BE,b6:03C50313,2:03C503130300,2:03C503130301,2:03C503130342,2a:1F0003B9,1:1F0103B9,1:1F0203B9,1:1F0303B9,1:1F0403B9,1:1F0503B9,1:1F0603B9,1:1F0703B9,1:1F0003B9,1:1F0103B9,1:1F0203B9,1:1F0303B9,1:1F0403B9,1:1F0503B9,1:1F0603B9,1:1F0703B9,1:1F2003B9,1:1F2103B9,1:1F2203B9,1:1F2303B9,1:1F2403B9,1:1F2503B9,1:1F2603B9,1:1F2703B9,1:1F2003B9,1:1F2103B9,1:1F2203B9,1:1F2303B9,1:1F2403B9,1:1F2503B9,1:1F2603B9,1:1F2703B9,1:1F6003B9,1:1F6103B9,1:1F6203B9,1:1F6303B9,1:1F6403B9,1:1F6503B9,1:1F6603B9,1:1F6703B9,1:1F6003B9,1:1F6103B9,1:1F6203B9,1:1F6303B9,1:1F6403B9,1:1F6503B9,1:1F6603B9,1:1F6703B9,3:1F7003B9,1:03B103B9,1:03AC03B9,2:03B10342,1:03B1034203B9,5:03B103B9,6:1F7403B9,1:03B703B9,1:03AE03B9,2:03B70342,1:03B7034203B9,5:03B703B9,6:03B903080300,1:03B903080301,3:03B90342,1:03B903080342,b:03C503080300,1:03C503080301,1:03C10313,2:03C50342,1:03C503080342,b:1F7C03B9,1:03C903B9,1:03CE03B9,2:03C90342,1:03C9034203B9,5:03C903B9,ac:00720073,5b:00B00063,6:00B00066,d:006E006F,a:0073006D,1:00740065006C,1:0074006D,124f:006800700061,2:00610075,2:006F0076,b:00700061,1:006E0061,1:03BC0061,1:006D0061,1:006B0061,1:006B0062,1:006D0062,1:00670062,3:00700066,1:006E0066,1:03BC0066,4:0068007A,1:006B0068007A,1:006D0068007A,1:00670068007A,1:00740068007A,15:00700061,1:006B00700061,1:006D00700061,1:006700700061,8:00700076,1:006E0076,1:03BC0076,1:006D0076,1:006B0076,1:006D0076,1:00700077,1:006E0077,1:03BC0077,1:006D0077,1:006B0077,1:006D0077,1:006B03C9,1:006D03C9,2:00620071,3:00632215006B0067,1:0063006F002E,1:00640062,1:00670079,2:00680070,2:006B006B,1:006B006D,9:00700068,2:00700070006D,1:00700072,2:00730076,1:00770062,c723:00660066,1:00660069,1:0066006C,1:006600660069,1:00660066006C,1:00730074,1:00730074,d:05740576,1:05740565,1:0574056B,1:057E0576,1:0574056D",
|
|
148
|
+
bytes2,
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const Table_C_ranges = createRangeTable(
|
|
152
|
+
"80-20,2a0-,39c,32,f71,18e,7f2-f,19-7,30-4,7-5,f81-b,5,a800-20ff,4d1-1f,110,fa-6,d174-7,2e84-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,2,1f-5f,ff7f-20001",
|
|
153
|
+
);
|
|
125
154
|
|
|
126
155
|
function flatten(values: Array<Array<number>>): Array<number> {
|
|
127
156
|
return values.reduce((accum, value) => {
|
|
128
|
-
value.forEach((value) => {
|
|
157
|
+
value.forEach((value) => {
|
|
158
|
+
accum.push(value);
|
|
159
|
+
});
|
|
129
160
|
return accum;
|
|
130
|
-
}, [
|
|
161
|
+
}, []);
|
|
131
162
|
}
|
|
132
163
|
|
|
133
164
|
export function _nameprepTableA1(codepoint: number): boolean {
|
|
@@ -136,16 +167,24 @@ export function _nameprepTableA1(codepoint: number): boolean {
|
|
|
136
167
|
|
|
137
168
|
export function _nameprepTableB2(codepoint: number): Array<number> {
|
|
138
169
|
let range = matchMap(codepoint, Table_B_2_ranges);
|
|
139
|
-
if (range) {
|
|
170
|
+
if (range) {
|
|
171
|
+
return [codepoint + range.s];
|
|
172
|
+
}
|
|
140
173
|
|
|
141
174
|
let codes = Table_B_2_lut_abs[codepoint];
|
|
142
|
-
if (codes) {
|
|
175
|
+
if (codes) {
|
|
176
|
+
return codes;
|
|
177
|
+
}
|
|
143
178
|
|
|
144
179
|
let shift = Table_B_2_lut_rel[codepoint];
|
|
145
|
-
if (shift) {
|
|
180
|
+
if (shift) {
|
|
181
|
+
return [codepoint + shift[0]];
|
|
182
|
+
}
|
|
146
183
|
|
|
147
184
|
let complex = Table_B_2_complex[codepoint];
|
|
148
|
-
if (complex) {
|
|
185
|
+
if (complex) {
|
|
186
|
+
return complex;
|
|
187
|
+
}
|
|
149
188
|
|
|
150
189
|
return null;
|
|
151
190
|
}
|
|
@@ -155,30 +194,42 @@ export function _nameprepTableC(codepoint: number): boolean {
|
|
|
155
194
|
}
|
|
156
195
|
|
|
157
196
|
export function nameprep(value: string): string {
|
|
158
|
-
|
|
159
197
|
// This allows platforms with incomplete normalize to bypass
|
|
160
198
|
// it for very basic names which the built-in toLowerCase
|
|
161
199
|
// will certainly handle correctly
|
|
162
|
-
if (value.match(/^[a-z0-9-]*$/i) && value.length <= 59) {
|
|
200
|
+
if (value.match(/^[a-z0-9-]*$/i) && value.length <= 59) {
|
|
201
|
+
return value.toLowerCase();
|
|
202
|
+
}
|
|
163
203
|
|
|
164
204
|
// Get the code points (keeping the current normalization)
|
|
165
205
|
let codes = toUtf8CodePoints(value);
|
|
166
206
|
|
|
167
|
-
codes = flatten(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
207
|
+
codes = flatten(
|
|
208
|
+
codes.map((code) => {
|
|
209
|
+
// Substitute Table B.1 (Maps to Nothing)
|
|
210
|
+
if (Table_B_1_flags.indexOf(code) >= 0) {
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
if (code >= 0xfe00 && code <= 0xfe0f) {
|
|
214
|
+
return [];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Substitute Table B.2 (Case Folding)
|
|
218
|
+
let codesTableB2 = _nameprepTableB2(code);
|
|
219
|
+
if (codesTableB2) {
|
|
220
|
+
return codesTableB2;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// No Substitution
|
|
224
|
+
return [code];
|
|
225
|
+
}),
|
|
226
|
+
);
|
|
179
227
|
|
|
180
228
|
// Normalize using form KC
|
|
181
|
-
codes = toUtf8CodePoints(
|
|
229
|
+
codes = toUtf8CodePoints(
|
|
230
|
+
_toUtf8String(codes),
|
|
231
|
+
UnicodeNormalizationForm.NFKC,
|
|
232
|
+
);
|
|
182
233
|
|
|
183
234
|
// Prohibit Tables C.1.2, C.2.2, C.3, C.4, C.5, C.6, C.7, C.8, C.9
|
|
184
235
|
codes.forEach((code) => {
|
|
@@ -198,10 +249,13 @@ export function nameprep(value: string): string {
|
|
|
198
249
|
let name = _toUtf8String(codes);
|
|
199
250
|
|
|
200
251
|
// IDNA: 4.2.3.1
|
|
201
|
-
if (
|
|
252
|
+
if (
|
|
253
|
+
name.substring(0, 1) === "-" ||
|
|
254
|
+
name.substring(2, 4) === "--" ||
|
|
255
|
+
name.substring(name.length - 1) === "-"
|
|
256
|
+
) {
|
|
202
257
|
throw new Error("invalid hyphen");
|
|
203
258
|
}
|
|
204
259
|
|
|
205
260
|
return name;
|
|
206
261
|
}
|
|
207
|
-
|
package/src.ts/index.ts
CHANGED
|
@@ -2,22 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
import { formatBytes32String, parseBytes32String } from "./bytes32";
|
|
4
4
|
import { nameprep } from "./idna";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
_toEscapedUtf8String,
|
|
7
|
+
toUtf8Bytes,
|
|
8
|
+
toUtf8CodePoints,
|
|
9
|
+
toUtf8String,
|
|
10
|
+
UnicodeNormalizationForm,
|
|
11
|
+
Utf8ErrorFunc,
|
|
12
|
+
Utf8ErrorFuncs,
|
|
13
|
+
Utf8ErrorReason,
|
|
14
|
+
} from "./utf8";
|
|
6
15
|
|
|
7
16
|
export {
|
|
8
17
|
_toEscapedUtf8String,
|
|
9
18
|
toUtf8Bytes,
|
|
10
19
|
toUtf8CodePoints,
|
|
11
20
|
toUtf8String,
|
|
12
|
-
|
|
13
21
|
Utf8ErrorFunc,
|
|
14
22
|
Utf8ErrorFuncs,
|
|
15
23
|
Utf8ErrorReason,
|
|
16
|
-
|
|
17
24
|
UnicodeNormalizationForm,
|
|
18
|
-
|
|
19
25
|
formatBytes32String,
|
|
20
26
|
parseBytes32String,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
27
|
+
nameprep,
|
|
28
|
+
};
|
package/src.ts/utf8.ts
CHANGED
|
@@ -2,67 +2,92 @@
|
|
|
2
2
|
|
|
3
3
|
import { arrayify, BytesLike } from "@qevm/bytes";
|
|
4
4
|
|
|
5
|
-
import { Logger } from "@
|
|
5
|
+
import { Logger } from "@qevm/logger";
|
|
6
6
|
import { version } from "./_version";
|
|
7
7
|
const logger = new Logger(version);
|
|
8
8
|
|
|
9
9
|
///////////////////////////////
|
|
10
10
|
|
|
11
11
|
export enum UnicodeNormalizationForm {
|
|
12
|
-
current
|
|
13
|
-
NFC
|
|
14
|
-
NFD
|
|
15
|
-
NFKC
|
|
16
|
-
NFKD
|
|
17
|
-
}
|
|
12
|
+
current = "",
|
|
13
|
+
NFC = "NFC",
|
|
14
|
+
NFD = "NFD",
|
|
15
|
+
NFKC = "NFKC",
|
|
16
|
+
NFKD = "NFKD",
|
|
17
|
+
}
|
|
18
18
|
|
|
19
19
|
export enum Utf8ErrorReason {
|
|
20
20
|
// A continuation byte was present where there was nothing to continue
|
|
21
21
|
// - offset = the index the codepoint began in
|
|
22
|
-
UNEXPECTED_CONTINUE
|
|
22
|
+
UNEXPECTED_CONTINUE = "unexpected continuation byte",
|
|
23
23
|
|
|
24
24
|
// An invalid (non-continuation) byte to start a UTF-8 codepoint was found
|
|
25
25
|
// - offset = the index the codepoint began in
|
|
26
|
-
BAD_PREFIX
|
|
26
|
+
BAD_PREFIX = "bad codepoint prefix",
|
|
27
27
|
|
|
28
28
|
// The string is too short to process the expected codepoint
|
|
29
29
|
// - offset = the index the codepoint began in
|
|
30
|
-
OVERRUN
|
|
30
|
+
OVERRUN = "string overrun",
|
|
31
31
|
|
|
32
32
|
// A missing continuation byte was expected but not found
|
|
33
33
|
// - offset = the index the continuation byte was expected at
|
|
34
|
-
MISSING_CONTINUE
|
|
34
|
+
MISSING_CONTINUE = "missing continuation byte",
|
|
35
35
|
|
|
36
36
|
// The computed code point is outside the range for UTF-8
|
|
37
37
|
// - offset = start of this codepoint
|
|
38
38
|
// - badCodepoint = the computed codepoint; outside the UTF-8 range
|
|
39
|
-
OUT_OF_RANGE
|
|
39
|
+
OUT_OF_RANGE = "out of UTF-8 range",
|
|
40
40
|
|
|
41
41
|
// UTF-8 strings may not contain UTF-16 surrogate pairs
|
|
42
42
|
// - offset = start of this codepoint
|
|
43
43
|
// - badCodepoint = the computed codepoint; inside the UTF-16 surrogate range
|
|
44
|
-
UTF16_SURROGATE
|
|
44
|
+
UTF16_SURROGATE = "UTF-16 surrogate",
|
|
45
45
|
|
|
46
46
|
// The string is an overlong representation
|
|
47
47
|
// - offset = start of this codepoint
|
|
48
48
|
// - badCodepoint = the computed codepoint; already bounds checked
|
|
49
|
-
OVERLONG
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
export type Utf8ErrorFunc = (reason: Utf8ErrorReason, offset: number, bytes: ArrayLike<number>, output: Array<number>, badCodepoint?: number) => number;
|
|
54
|
-
|
|
55
|
-
function errorFunc(reason: Utf8ErrorReason, offset: number, bytes: ArrayLike<number>, output: Array<number>, badCodepoint?: number): number {
|
|
56
|
-
return logger.throwArgumentError(`invalid codepoint at offset ${ offset }; ${ reason }`, "bytes", bytes);
|
|
49
|
+
OVERLONG = "overlong representation",
|
|
57
50
|
}
|
|
58
51
|
|
|
59
|
-
|
|
52
|
+
export type Utf8ErrorFunc = (
|
|
53
|
+
reason: Utf8ErrorReason,
|
|
54
|
+
offset: number,
|
|
55
|
+
bytes: ArrayLike<number>,
|
|
56
|
+
output: Array<number>,
|
|
57
|
+
badCodepoint?: number,
|
|
58
|
+
) => number;
|
|
59
|
+
|
|
60
|
+
function errorFunc(
|
|
61
|
+
reason: Utf8ErrorReason,
|
|
62
|
+
offset: number,
|
|
63
|
+
bytes: ArrayLike<number>,
|
|
64
|
+
output: Array<number>,
|
|
65
|
+
badCodepoint?: number,
|
|
66
|
+
): number {
|
|
67
|
+
return logger.throwArgumentError(
|
|
68
|
+
`invalid codepoint at offset ${offset}; ${reason}`,
|
|
69
|
+
"bytes",
|
|
70
|
+
bytes,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
60
73
|
|
|
74
|
+
function ignoreFunc(
|
|
75
|
+
reason: Utf8ErrorReason,
|
|
76
|
+
offset: number,
|
|
77
|
+
bytes: ArrayLike<number>,
|
|
78
|
+
output: Array<number>,
|
|
79
|
+
badCodepoint?: number,
|
|
80
|
+
): number {
|
|
61
81
|
// If there is an invalid prefix (including stray continuation), skip any additional continuation bytes
|
|
62
|
-
if (
|
|
82
|
+
if (
|
|
83
|
+
reason === Utf8ErrorReason.BAD_PREFIX ||
|
|
84
|
+
reason === Utf8ErrorReason.UNEXPECTED_CONTINUE
|
|
85
|
+
) {
|
|
63
86
|
let i = 0;
|
|
64
87
|
for (let o = offset + 1; o < bytes.length; o++) {
|
|
65
|
-
if (bytes[o] >> 6 !== 0x02) {
|
|
88
|
+
if (bytes[o] >> 6 !== 0x02) {
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
66
91
|
i++;
|
|
67
92
|
}
|
|
68
93
|
return i;
|
|
@@ -78,8 +103,13 @@ function ignoreFunc(reason: Utf8ErrorReason, offset: number, bytes: ArrayLike<nu
|
|
|
78
103
|
return 0;
|
|
79
104
|
}
|
|
80
105
|
|
|
81
|
-
function replaceFunc(
|
|
82
|
-
|
|
106
|
+
function replaceFunc(
|
|
107
|
+
reason: Utf8ErrorReason,
|
|
108
|
+
offset: number,
|
|
109
|
+
bytes: ArrayLike<number>,
|
|
110
|
+
output: Array<number>,
|
|
111
|
+
badCodepoint?: number,
|
|
112
|
+
): number {
|
|
83
113
|
// Overlong representations are otherwise "valid" code points; just non-deistingtished
|
|
84
114
|
if (reason === Utf8ErrorReason.OVERLONG) {
|
|
85
115
|
output.push(badCodepoint);
|
|
@@ -94,15 +124,20 @@ function replaceFunc(reason: Utf8ErrorReason, offset: number, bytes: ArrayLike<n
|
|
|
94
124
|
}
|
|
95
125
|
|
|
96
126
|
// Common error handing strategies
|
|
97
|
-
export const Utf8ErrorFuncs: { [
|
|
127
|
+
export const Utf8ErrorFuncs: { [name: string]: Utf8ErrorFunc } = Object.freeze({
|
|
98
128
|
error: errorFunc,
|
|
99
129
|
ignore: ignoreFunc,
|
|
100
|
-
replace: replaceFunc
|
|
130
|
+
replace: replaceFunc,
|
|
101
131
|
});
|
|
102
132
|
|
|
103
133
|
// http://stackoverflow.com/questions/13356493/decode-utf-8-with-javascript#13691499
|
|
104
|
-
function getUtf8CodePoints(
|
|
105
|
-
|
|
134
|
+
function getUtf8CodePoints(
|
|
135
|
+
bytes: BytesLike,
|
|
136
|
+
onError?: Utf8ErrorFunc,
|
|
137
|
+
): Array<number> {
|
|
138
|
+
if (onError == null) {
|
|
139
|
+
onError = Utf8ErrorFuncs.error;
|
|
140
|
+
}
|
|
106
141
|
|
|
107
142
|
bytes = arrayify(bytes);
|
|
108
143
|
|
|
@@ -110,8 +145,7 @@ function getUtf8CodePoints(bytes: BytesLike, onError?: Utf8ErrorFunc): Array<num
|
|
|
110
145
|
let i = 0;
|
|
111
146
|
|
|
112
147
|
// Invalid bytes are ignored
|
|
113
|
-
while(i < bytes.length) {
|
|
114
|
-
|
|
148
|
+
while (i < bytes.length) {
|
|
115
149
|
const c = bytes[i++];
|
|
116
150
|
|
|
117
151
|
// 0xxx xxxx
|
|
@@ -129,19 +163,23 @@ function getUtf8CodePoints(bytes: BytesLike, onError?: Utf8ErrorFunc): Array<num
|
|
|
129
163
|
extraLength = 1;
|
|
130
164
|
overlongMask = 0x7f;
|
|
131
165
|
|
|
132
|
-
|
|
166
|
+
// 1110 xxxx 10xx xxxx 10xx xxxx
|
|
133
167
|
} else if ((c & 0xf0) === 0xe0) {
|
|
134
168
|
extraLength = 2;
|
|
135
169
|
overlongMask = 0x7ff;
|
|
136
170
|
|
|
137
|
-
|
|
171
|
+
// 1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx
|
|
138
172
|
} else if ((c & 0xf8) === 0xf0) {
|
|
139
173
|
extraLength = 3;
|
|
140
174
|
overlongMask = 0xffff;
|
|
141
|
-
|
|
142
175
|
} else {
|
|
143
176
|
if ((c & 0xc0) === 0x80) {
|
|
144
|
-
i += onError(
|
|
177
|
+
i += onError(
|
|
178
|
+
Utf8ErrorReason.UNEXPECTED_CONTINUE,
|
|
179
|
+
i - 1,
|
|
180
|
+
bytes,
|
|
181
|
+
result,
|
|
182
|
+
);
|
|
145
183
|
} else {
|
|
146
184
|
i += onError(Utf8ErrorReason.BAD_PREFIX, i - 1, bytes, result);
|
|
147
185
|
}
|
|
@@ -162,33 +200,58 @@ function getUtf8CodePoints(bytes: BytesLike, onError?: Utf8ErrorFunc): Array<num
|
|
|
162
200
|
|
|
163
201
|
// Invalid continuation byte
|
|
164
202
|
if ((nextChar & 0xc0) != 0x80) {
|
|
165
|
-
i += onError(
|
|
203
|
+
i += onError(
|
|
204
|
+
Utf8ErrorReason.MISSING_CONTINUE,
|
|
205
|
+
i,
|
|
206
|
+
bytes,
|
|
207
|
+
result,
|
|
208
|
+
);
|
|
166
209
|
res = null;
|
|
167
210
|
break;
|
|
168
|
-
}
|
|
211
|
+
}
|
|
169
212
|
|
|
170
213
|
res = (res << 6) | (nextChar & 0x3f);
|
|
171
214
|
i++;
|
|
172
215
|
}
|
|
173
216
|
|
|
174
217
|
// See above loop for invalid continuation byte
|
|
175
|
-
if (res === null) {
|
|
218
|
+
if (res === null) {
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
176
221
|
|
|
177
222
|
// Maximum code point
|
|
178
223
|
if (res > 0x10ffff) {
|
|
179
|
-
i += onError(
|
|
224
|
+
i += onError(
|
|
225
|
+
Utf8ErrorReason.OUT_OF_RANGE,
|
|
226
|
+
i - 1 - extraLength,
|
|
227
|
+
bytes,
|
|
228
|
+
result,
|
|
229
|
+
res,
|
|
230
|
+
);
|
|
180
231
|
continue;
|
|
181
232
|
}
|
|
182
233
|
|
|
183
234
|
// Reserved for UTF-16 surrogate halves
|
|
184
235
|
if (res >= 0xd800 && res <= 0xdfff) {
|
|
185
|
-
i += onError(
|
|
236
|
+
i += onError(
|
|
237
|
+
Utf8ErrorReason.UTF16_SURROGATE,
|
|
238
|
+
i - 1 - extraLength,
|
|
239
|
+
bytes,
|
|
240
|
+
result,
|
|
241
|
+
res,
|
|
242
|
+
);
|
|
186
243
|
continue;
|
|
187
244
|
}
|
|
188
245
|
|
|
189
246
|
// Check for overlong sequences (more bytes than needed)
|
|
190
247
|
if (res <= overlongMask) {
|
|
191
|
-
i += onError(
|
|
248
|
+
i += onError(
|
|
249
|
+
Utf8ErrorReason.OVERLONG,
|
|
250
|
+
i - 1 - extraLength,
|
|
251
|
+
bytes,
|
|
252
|
+
result,
|
|
253
|
+
res,
|
|
254
|
+
);
|
|
192
255
|
continue;
|
|
193
256
|
}
|
|
194
257
|
|
|
@@ -199,8 +262,10 @@ function getUtf8CodePoints(bytes: BytesLike, onError?: Utf8ErrorFunc): Array<num
|
|
|
199
262
|
}
|
|
200
263
|
|
|
201
264
|
// http://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array
|
|
202
|
-
export function toUtf8Bytes(
|
|
203
|
-
|
|
265
|
+
export function toUtf8Bytes(
|
|
266
|
+
str: string,
|
|
267
|
+
form: UnicodeNormalizationForm = UnicodeNormalizationForm.current,
|
|
268
|
+
): Uint8Array {
|
|
204
269
|
if (form != UnicodeNormalizationForm.current) {
|
|
205
270
|
logger.checkNormalize();
|
|
206
271
|
str = str.normalize(form);
|
|
@@ -212,11 +277,9 @@ export function toUtf8Bytes(str: string, form: UnicodeNormalizationForm = Unicod
|
|
|
212
277
|
|
|
213
278
|
if (c < 0x80) {
|
|
214
279
|
result.push(c);
|
|
215
|
-
|
|
216
280
|
} else if (c < 0x800) {
|
|
217
281
|
result.push((c >> 6) | 0xc0);
|
|
218
282
|
result.push((c & 0x3f) | 0x80);
|
|
219
|
-
|
|
220
283
|
} else if ((c & 0xfc00) == 0xd800) {
|
|
221
284
|
i++;
|
|
222
285
|
const c2 = str.charCodeAt(i);
|
|
@@ -231,7 +294,6 @@ export function toUtf8Bytes(str: string, form: UnicodeNormalizationForm = Unicod
|
|
|
231
294
|
result.push(((pair >> 12) & 0x3f) | 0x80);
|
|
232
295
|
result.push(((pair >> 6) & 0x3f) | 0x80);
|
|
233
296
|
result.push((pair & 0x3f) | 0x80);
|
|
234
|
-
|
|
235
297
|
} else {
|
|
236
298
|
result.push((c >> 12) | 0xe0);
|
|
237
299
|
result.push(((c >> 6) & 0x3f) | 0x80);
|
|
@@ -240,56 +302,82 @@ export function toUtf8Bytes(str: string, form: UnicodeNormalizationForm = Unicod
|
|
|
240
302
|
}
|
|
241
303
|
|
|
242
304
|
return arrayify(result);
|
|
243
|
-
}
|
|
305
|
+
}
|
|
244
306
|
|
|
245
307
|
function escapeChar(value: number) {
|
|
246
|
-
const hex =
|
|
308
|
+
const hex = "0000" + value.toString(16);
|
|
247
309
|
return "\\u" + hex.substring(hex.length - 4);
|
|
248
310
|
}
|
|
249
311
|
|
|
250
|
-
export function _toEscapedUtf8String(
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
312
|
+
export function _toEscapedUtf8String(
|
|
313
|
+
bytes: BytesLike,
|
|
314
|
+
onError?: Utf8ErrorFunc,
|
|
315
|
+
): string {
|
|
316
|
+
return (
|
|
317
|
+
'"' +
|
|
318
|
+
getUtf8CodePoints(bytes, onError)
|
|
319
|
+
.map((codePoint) => {
|
|
320
|
+
if (codePoint < 256) {
|
|
321
|
+
switch (codePoint) {
|
|
322
|
+
case 8:
|
|
323
|
+
return "\\b";
|
|
324
|
+
case 9:
|
|
325
|
+
return "\\t";
|
|
326
|
+
case 10:
|
|
327
|
+
return "\\n";
|
|
328
|
+
case 13:
|
|
329
|
+
return "\\r";
|
|
330
|
+
case 34:
|
|
331
|
+
return '\\"';
|
|
332
|
+
case 92:
|
|
333
|
+
return "\\\\";
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (codePoint >= 32 && codePoint < 127) {
|
|
337
|
+
return String.fromCharCode(codePoint);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (codePoint <= 0xffff) {
|
|
342
|
+
return escapeChar(codePoint);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
codePoint -= 0x10000;
|
|
346
|
+
return (
|
|
347
|
+
escapeChar(((codePoint >> 10) & 0x3ff) + 0xd800) +
|
|
348
|
+
escapeChar((codePoint & 0x3ff) + 0xdc00)
|
|
349
|
+
);
|
|
350
|
+
})
|
|
351
|
+
.join("") +
|
|
352
|
+
'"'
|
|
353
|
+
);
|
|
274
354
|
}
|
|
275
355
|
|
|
276
356
|
export function _toUtf8String(codePoints: Array<number>): string {
|
|
277
|
-
return codePoints
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
(
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
357
|
+
return codePoints
|
|
358
|
+
.map((codePoint) => {
|
|
359
|
+
if (codePoint <= 0xffff) {
|
|
360
|
+
return String.fromCharCode(codePoint);
|
|
361
|
+
}
|
|
362
|
+
codePoint -= 0x10000;
|
|
363
|
+
return String.fromCharCode(
|
|
364
|
+
((codePoint >> 10) & 0x3ff) + 0xd800,
|
|
365
|
+
(codePoint & 0x3ff) + 0xdc00,
|
|
366
|
+
);
|
|
367
|
+
})
|
|
368
|
+
.join("");
|
|
287
369
|
}
|
|
288
370
|
|
|
289
|
-
export function toUtf8String(
|
|
371
|
+
export function toUtf8String(
|
|
372
|
+
bytes: BytesLike,
|
|
373
|
+
onError?: Utf8ErrorFunc,
|
|
374
|
+
): string {
|
|
290
375
|
return _toUtf8String(getUtf8CodePoints(bytes, onError));
|
|
291
376
|
}
|
|
292
377
|
|
|
293
|
-
export function toUtf8CodePoints(
|
|
378
|
+
export function toUtf8CodePoints(
|
|
379
|
+
str: string,
|
|
380
|
+
form: UnicodeNormalizationForm = UnicodeNormalizationForm.current,
|
|
381
|
+
): Array<number> {
|
|
294
382
|
return getUtf8CodePoints(toUtf8Bytes(str, form));
|
|
295
383
|
}
|