ordered-binary 1.1.2 → 1.1.3
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/dist/index.cjs +46 -9
- package/index.js +11 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -216,20 +216,57 @@ function makeStringBuilder() {
|
|
|
216
216
|
let stringBuildCode = '(source) => {';
|
|
217
217
|
let previous = [];
|
|
218
218
|
for (let i = 0; i < 0x30; i++) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
`;
|
|
227
|
-
|
|
219
|
+
let v = fromCharCode((i & 0xf) + 97) + fromCharCode((i >> 4) + 97);
|
|
220
|
+
stringBuildCode += `
|
|
221
|
+
let ${v} = source[position++]
|
|
222
|
+
if (${v} === 0)
|
|
223
|
+
return fromCharCode(${previous})
|
|
224
|
+
else if (${v} >= 0x80)
|
|
225
|
+
${v} = finishUtf8(${v}, source)
|
|
226
|
+
`;
|
|
227
|
+
previous.push(v);
|
|
228
|
+
if (i == 1000000) // this just exists to prevent rollup from doing dead code elimination on finishUtf8
|
|
229
|
+
finishUtf8();
|
|
228
230
|
}
|
|
229
231
|
stringBuildCode += `return fromCharCode(${previous}) + readString(source)}`;
|
|
230
232
|
return stringBuildCode
|
|
231
233
|
}
|
|
232
234
|
|
|
235
|
+
let pendingSurrogate;
|
|
236
|
+
function finishUtf8(byte1, src) {
|
|
237
|
+
if ((byte1 & 0xe0) === 0xc0) {
|
|
238
|
+
// 2 bytes
|
|
239
|
+
const byte2 = src[position++] & 0x3f;
|
|
240
|
+
return ((byte1 & 0x1f) << 6) | byte2
|
|
241
|
+
} else if ((byte1 & 0xf0) === 0xe0) {
|
|
242
|
+
// 3 bytes
|
|
243
|
+
const byte2 = src[position++] & 0x3f;
|
|
244
|
+
const byte3 = src[position++] & 0x3f;
|
|
245
|
+
return ((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3
|
|
246
|
+
} else if ((byte1 & 0xf8) === 0xf0) {
|
|
247
|
+
// 4 bytes
|
|
248
|
+
if (pendingSurrogate) {
|
|
249
|
+
byte1 = pendingSurrogate;
|
|
250
|
+
pendingSurrogate = null;
|
|
251
|
+
position += 3;
|
|
252
|
+
return byte1
|
|
253
|
+
}
|
|
254
|
+
const byte2 = src[position++] & 0x3f;
|
|
255
|
+
const byte3 = src[position++] & 0x3f;
|
|
256
|
+
const byte4 = src[position++] & 0x3f;
|
|
257
|
+
let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
|
|
258
|
+
if (unit > 0xffff) {
|
|
259
|
+
unit -= 0x10000;
|
|
260
|
+
unit = 0xdc00 | (unit & 0x3ff);
|
|
261
|
+
pendingSurrogate = ((unit >>> 10) & 0x3ff) | 0xd800;
|
|
262
|
+
position -= 4; // reset so we can return the next part of the surrogate pair
|
|
263
|
+
}
|
|
264
|
+
return unit
|
|
265
|
+
} else {
|
|
266
|
+
return byte1
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
233
270
|
const enableNullTermination = () => nullTerminate = true;
|
|
234
271
|
|
|
235
272
|
const readString = eval(makeStringBuilder());
|
package/index.js
CHANGED
|
@@ -214,15 +214,17 @@ function makeStringBuilder() {
|
|
|
214
214
|
let stringBuildCode = '(source) => {'
|
|
215
215
|
let previous = []
|
|
216
216
|
for (let i = 0; i < 0x30; i++) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
`
|
|
225
|
-
|
|
217
|
+
let v = fromCharCode((i & 0xf) + 97) + fromCharCode((i >> 4) + 97)
|
|
218
|
+
stringBuildCode += `
|
|
219
|
+
let ${v} = source[position++]
|
|
220
|
+
if (${v} === 0)
|
|
221
|
+
return fromCharCode(${previous})
|
|
222
|
+
else if (${v} >= 0x80)
|
|
223
|
+
${v} = finishUtf8(${v}, source)
|
|
224
|
+
`
|
|
225
|
+
previous.push(v)
|
|
226
|
+
if (i == 1000000) // this just exists to prevent rollup from doing dead code elimination on finishUtf8
|
|
227
|
+
finishUtf8()
|
|
226
228
|
}
|
|
227
229
|
stringBuildCode += `return fromCharCode(${previous}) + readString(source)}`
|
|
228
230
|
return stringBuildCode
|
package/package.json
CHANGED