echogarden 3.1.0 → 3.2.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/data/lexicons/heteronyms.en.json +1 -1
- package/data/lexicons/words.en.json +32 -0
- package/dist/api/Synthesis.js +2 -2
- package/dist/api/Synthesis.js.map +1 -1
- package/dist/encodings/Ascii.d.ts +1 -3
- package/dist/encodings/Ascii.d.ts.map +1 -1
- package/dist/encodings/Ascii.js +13 -9
- package/dist/encodings/Ascii.js.map +1 -1
- package/dist/encodings/Base64.d.ts.map +1 -1
- package/dist/encodings/Base64.js +9 -0
- package/dist/encodings/Base64.js.map +1 -1
- package/dist/encodings/Hex.d.ts.map +1 -1
- package/dist/encodings/Hex.js +11 -2
- package/dist/encodings/Hex.js.map +1 -1
- package/dist/encodings/LEB128.d.ts +1 -15
- package/dist/encodings/LEB128.d.ts.map +1 -1
- package/dist/encodings/LEB128.js +1 -247
- package/dist/encodings/LEB128.js.map +1 -1
- package/dist/encodings/Utf16.d.ts +1 -3
- package/dist/encodings/Utf16.d.ts.map +1 -1
- package/dist/encodings/Utf16.js +13 -9
- package/dist/encodings/Utf16.js.map +1 -1
- package/dist/encodings/Utf32.d.ts.map +1 -1
- package/dist/encodings/Utf32.js +6 -0
- package/dist/encodings/Utf32.js.map +1 -1
- package/dist/encodings/Utf8.d.ts +9 -5
- package/dist/encodings/Utf8.d.ts.map +1 -1
- package/dist/encodings/Utf8.js +36 -78
- package/dist/encodings/Utf8.js.map +1 -1
- package/dist/nlp/Segmentation.d.ts.map +1 -1
- package/dist/nlp/Segmentation.js +4 -1
- package/dist/nlp/Segmentation.js.map +1 -1
- package/dist/nlp/TextNormalizer.js +8 -1
- package/dist/nlp/TextNormalizer.js.map +1 -1
- package/dist/synthesis/AzureCognitiveServicesTTS.js +1 -1
- package/dist/synthesis/AzureCognitiveServicesTTS.js.map +1 -1
- package/dist/synthesis/EspeakTTS.js +1 -1
- package/dist/synthesis/EspeakTTS.js.map +1 -1
- package/dist/synthesis/MicrosoftEdgeTTS.js +1 -1
- package/dist/synthesis/MicrosoftEdgeTTS.js.map +1 -1
- package/dist/utilities/FileSystem.d.ts +12 -7
- package/dist/utilities/FileSystem.d.ts.map +1 -1
- package/dist/utilities/FileSystem.js +196 -79
- package/dist/utilities/FileSystem.js.map +1 -1
- package/dist/utilities/FileWriter.d.ts +1 -0
- package/dist/utilities/FileWriter.d.ts.map +1 -1
- package/dist/utilities/FileWriter.js +8 -1
- package/dist/utilities/FileWriter.js.map +1 -1
- package/dist/utilities/ObjectUtilities.d.ts.map +1 -1
- package/dist/utilities/ObjectUtilities.js +15 -13
- package/dist/utilities/ObjectUtilities.js.map +1 -1
- package/dist/utilities/PackageManager.js +2 -2
- package/dist/utilities/PackageManager.js.map +1 -1
- package/dist/utilities/PathUtilities.d.ts +1 -0
- package/dist/utilities/PathUtilities.d.ts.map +1 -1
- package/dist/utilities/PathUtilities.js +18 -0
- package/dist/utilities/PathUtilities.js.map +1 -1
- package/dist/utilities/StringUtilities.d.ts.map +1 -1
- package/dist/utilities/StringUtilities.js.map +1 -1
- package/package.json +8 -7
- package/src/api/Synthesis.ts +2 -2
- package/src/encodings/Ascii.ts +14 -10
- package/src/encodings/Base64.ts +9 -0
- package/src/encodings/Hex.ts +11 -2
- package/src/encodings/Utf16.ts +14 -10
- package/src/encodings/Utf32.ts +6 -0
- package/src/encodings/Utf8.ts +45 -82
- package/src/nlp/Segmentation.ts +5 -1
- package/src/nlp/TextNormalizer.ts +12 -1
- package/src/synthesis/AzureCognitiveServicesTTS.ts +1 -1
- package/src/synthesis/EspeakTTS.ts +1 -1
- package/src/synthesis/MicrosoftEdgeTTS.ts +1 -1
- package/src/utilities/FileSystem.ts +224 -85
- package/src/utilities/FileWriter.ts +11 -1
- package/src/utilities/ObjectUtilities.ts +19 -15
- package/src/utilities/PackageManager.ts +2 -2
- package/src/utilities/PathUtilities.ts +19 -0
- package/src/utilities/StringUtilities.ts +0 -2
- package/src/encodings/HtmlEscape.ts +0 -39
- package/src/encodings/LEB128.ts +0 -362
- package/src/utilities/StringBuilder.ts +0 -45
package/src/encodings/LEB128.ts
DELETED
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
import { DynamicUint8Array, createDynamicUint8Array } from "../data-structures/DynamicTypedArray.js"
|
|
2
|
-
import { logToStderr } from "../utilities/Utilities.js"
|
|
3
|
-
|
|
4
|
-
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
// Encode unsigned integer
|
|
6
|
-
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
|
-
export function encodeUnsignedInt(value: number | bigint, outEncodedData: DynamicUint8Array) {
|
|
8
|
-
if (value < 0) {
|
|
9
|
-
throw new Error(`The negative value ${value} can't be encoded as an unsigned LEB128 integer.`)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (typeof value === 'number') {
|
|
13
|
-
if (value < (2 ** 31)) {
|
|
14
|
-
return encodeUnsignedInt31(value, outEncodedData)
|
|
15
|
-
} else {
|
|
16
|
-
return encodeUnsignedBigInt(BigInt(value), outEncodedData)
|
|
17
|
-
}
|
|
18
|
-
} else {
|
|
19
|
-
return encodeUnsignedBigInt(value, outEncodedData)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function encodeUnsignedInt31(value: number, outEncodedData: DynamicUint8Array) {
|
|
24
|
-
value = value >>> 0
|
|
25
|
-
|
|
26
|
-
if (value < (2 ** 7)) {
|
|
27
|
-
outEncodedData.add(
|
|
28
|
-
value
|
|
29
|
-
)
|
|
30
|
-
} else if (value < (2 ** 14)) {
|
|
31
|
-
outEncodedData.addMany(
|
|
32
|
-
(value & 0b01111111) | 0b10000000,
|
|
33
|
-
value >>> 7
|
|
34
|
-
)
|
|
35
|
-
} else if (value < (2 ** 21)) {
|
|
36
|
-
outEncodedData.addMany(
|
|
37
|
-
(value & 0b01111111) | 0b10000000,
|
|
38
|
-
((value >>> 7) & 0b01111111) | 0b10000000,
|
|
39
|
-
value >>> 14
|
|
40
|
-
)
|
|
41
|
-
} else if (value < (2 ** 28)) {
|
|
42
|
-
outEncodedData.addMany(
|
|
43
|
-
(value & 0b01111111) | 0b10000000,
|
|
44
|
-
((value >>> 7) & 0b01111111) | 0b10000000,
|
|
45
|
-
((value >>> 14) & 0b01111111) | 0b10000000,
|
|
46
|
-
value >>> 21
|
|
47
|
-
)
|
|
48
|
-
} else {
|
|
49
|
-
outEncodedData.addMany(
|
|
50
|
-
(value & 0b01111111) | 0b10000000,
|
|
51
|
-
((value >>> 7) & 0b01111111) | 0b10000000,
|
|
52
|
-
((value >>> 14) & 0b01111111) | 0b10000000,
|
|
53
|
-
((value >>> 21) & 0b01111111) | 0b10000000,
|
|
54
|
-
value >>> 28
|
|
55
|
-
)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return outEncodedData
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function encodeUnsignedBigInt(value: bigint, outEncodedData: DynamicUint8Array) {
|
|
62
|
-
while (true) {
|
|
63
|
-
const lowest7Bits = Number(value & 0b01111111n)
|
|
64
|
-
|
|
65
|
-
value = value >> 7n
|
|
66
|
-
|
|
67
|
-
if (value === 0n) {
|
|
68
|
-
outEncodedData.add(lowest7Bits)
|
|
69
|
-
|
|
70
|
-
return outEncodedData
|
|
71
|
-
} else {
|
|
72
|
-
outEncodedData.add(lowest7Bits | 0b10000000)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
78
|
-
// Decode unsigned integer
|
|
79
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
80
|
-
export function decodeUnsignedInt31Fast(encodedData: ArrayLike<number>, readOffset: number): DecodedValueAndReadOffset {
|
|
81
|
-
const byte0 = encodedData[readOffset++]
|
|
82
|
-
|
|
83
|
-
if ((byte0 & 0b10000000) === 0) {
|
|
84
|
-
const decodedValue =
|
|
85
|
-
byte0
|
|
86
|
-
|
|
87
|
-
return { decodedValue, readOffset }
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const byte1 = encodedData[readOffset++]
|
|
91
|
-
|
|
92
|
-
if ((byte1 & 0b10000000) === 0) {
|
|
93
|
-
const decodedValue =
|
|
94
|
-
(byte0 & 0b01111111) |
|
|
95
|
-
(byte1 & 0b01111111) << 7
|
|
96
|
-
|
|
97
|
-
return { decodedValue, readOffset }
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const byte2 = encodedData[readOffset++]
|
|
101
|
-
|
|
102
|
-
if ((byte2 & 0b10000000) === 0) {
|
|
103
|
-
const decodedValue =
|
|
104
|
-
(byte0 & 0b01111111) |
|
|
105
|
-
(byte1 & 0b01111111) << 7 |
|
|
106
|
-
(byte2 & 0b01111111) << 14
|
|
107
|
-
|
|
108
|
-
return { decodedValue, readOffset }
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const byte3 = encodedData[readOffset++]
|
|
112
|
-
|
|
113
|
-
if ((byte3 & 0b10000000) === 0) {
|
|
114
|
-
const decodedValue =
|
|
115
|
-
(byte0 & 0b01111111) |
|
|
116
|
-
(byte1 & 0b01111111) << 7 |
|
|
117
|
-
(byte2 & 0b01111111) << 14 |
|
|
118
|
-
(byte3 & 0b01111111) << 21
|
|
119
|
-
|
|
120
|
-
return { decodedValue, readOffset }
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const byte4 = encodedData[readOffset++]
|
|
124
|
-
|
|
125
|
-
if ((byte4 & 0b10000000) === 0) {
|
|
126
|
-
const decodedValue =
|
|
127
|
-
(byte0 & 0b01111111) |
|
|
128
|
-
(byte1 & 0b01111111) << 7 |
|
|
129
|
-
(byte2 & 0b01111111) << 14 |
|
|
130
|
-
(byte3 & 0b01111111) << 21 |
|
|
131
|
-
(byte4 & 0b01111111) << 28
|
|
132
|
-
|
|
133
|
-
return { decodedValue, readOffset }
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (readOffset >= encodedData.length) {
|
|
137
|
-
throw new Error(`Invalid LEB128 data. Last encoded byte sequence is truncated.`)
|
|
138
|
-
} else {
|
|
139
|
-
throw new Error(`LEB128 sequence can't be decoded. Encoded byte sequence represents a value that extends beyond the range of a unsigned 32 bit integer.`)
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
144
|
-
// Encode signed integer
|
|
145
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
146
|
-
export function encodeSignedInt32(value: number, outEncodedData: DynamicUint8Array) {
|
|
147
|
-
if (value < -(2 ** 31) || value > (2 ** 31)) {
|
|
148
|
-
throw new Error('Value must be between -(2^31) and 2^31 - 1')
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
while (true) {
|
|
152
|
-
const lowest7Bits = value & 0b01111111
|
|
153
|
-
|
|
154
|
-
value >>= 7
|
|
155
|
-
|
|
156
|
-
if (
|
|
157
|
-
(value === 0 && (lowest7Bits & 0b01000000) === 0) ||
|
|
158
|
-
(value === -1 && (lowest7Bits & 0b01000000) !== 0)) {
|
|
159
|
-
outEncodedData.add(lowest7Bits)
|
|
160
|
-
|
|
161
|
-
return outEncodedData
|
|
162
|
-
} else {
|
|
163
|
-
outEncodedData.add(lowest7Bits | 0b10000000)
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export function encodeSignedInt32Fast(value: number, outEncodedData: DynamicUint8Array) {
|
|
169
|
-
const absValue = Math.abs(value | 0)
|
|
170
|
-
|
|
171
|
-
if (absValue < (2 ** 6)) {
|
|
172
|
-
outEncodedData.add(
|
|
173
|
-
(value & 0b01111111)
|
|
174
|
-
)
|
|
175
|
-
} else if (absValue < (2 ** 13)) {
|
|
176
|
-
outEncodedData.addMany(
|
|
177
|
-
(value & 0b01111111) | 0b10000000,
|
|
178
|
-
(value >> 7) & 0b01111111
|
|
179
|
-
)
|
|
180
|
-
} else if (absValue < (2 ** 20)) {
|
|
181
|
-
outEncodedData.addMany(
|
|
182
|
-
(value & 0b01111111) | 0b10000000,
|
|
183
|
-
((value >> 7) & 0b01111111) | 0b10000000,
|
|
184
|
-
(value >> 14) & 0b01111111
|
|
185
|
-
)
|
|
186
|
-
} else if (absValue < (2 ** 27)) {
|
|
187
|
-
outEncodedData.addMany(
|
|
188
|
-
(value & 0b01111111) | 0b10000000,
|
|
189
|
-
((value >> 7) & 0b01111111) | 0b10000000,
|
|
190
|
-
((value >> 14) & 0b01111111) | 0b10000000,
|
|
191
|
-
(value >> 21) & 0b01111111
|
|
192
|
-
)
|
|
193
|
-
} else {
|
|
194
|
-
outEncodedData.addMany(
|
|
195
|
-
(value & 0b01111111) | 0b10000000,
|
|
196
|
-
((value >> 7) & 0b01111111) | 0b10000000,
|
|
197
|
-
((value >> 14) & 0b01111111) | 0b10000000,
|
|
198
|
-
((value >> 21) & 0b01111111) | 0b10000000,
|
|
199
|
-
(value >> 28) & 0b01111111
|
|
200
|
-
)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return outEncodedData
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
207
|
-
// Decode signed integer
|
|
208
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
209
|
-
export function decodeSignedInt32(encodedData: ArrayLike<number>, readOffset: number): DecodedValueAndReadOffset {
|
|
210
|
-
let decodedValue = 0
|
|
211
|
-
let shiftAmount = 0
|
|
212
|
-
|
|
213
|
-
while (true) {
|
|
214
|
-
const encodedByte = encodedData[readOffset++]
|
|
215
|
-
const lowest7Bits = encodedByte & 0b01111111
|
|
216
|
-
|
|
217
|
-
decodedValue |= lowest7Bits << shiftAmount
|
|
218
|
-
|
|
219
|
-
// If 8th bit is 0, then this is the last byte in the sequence
|
|
220
|
-
if ((encodedByte & 0b10000000) === 0) {
|
|
221
|
-
// If 7th bit is 1, then the value is negative
|
|
222
|
-
if ((encodedByte & 0b01000000) !== 0) {
|
|
223
|
-
// If the value should be negative
|
|
224
|
-
// Ensure that the value is encoded as a negative number by
|
|
225
|
-
// setting all higher bits to 1
|
|
226
|
-
decodedValue |= -1 << Math.min(shiftAmount + 7, 31)
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return { decodedValue, readOffset }
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (readOffset === encodedData.length) {
|
|
233
|
-
throw new Error(`Invalid LEB128 data. Last encoded byte sequence is truncated.`)
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
shiftAmount += 7
|
|
237
|
-
|
|
238
|
-
if (shiftAmount > 31) {
|
|
239
|
-
throw new Error(`LEB128 sequence can't be decoded. Byte sequence extends beyond the range of a signed 32 bit integer.`)
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
export function decodeSignedInt32Fast(encodedData: ArrayLike<number>, readOffset: number) {
|
|
245
|
-
const byte0 = encodedData[readOffset++]
|
|
246
|
-
|
|
247
|
-
if ((byte0 & 0b10000000) === 0) {
|
|
248
|
-
let decodedValue =
|
|
249
|
-
byte0
|
|
250
|
-
|
|
251
|
-
if ((byte0 & 0b01000000) !== 0) {
|
|
252
|
-
decodedValue |= -1 << 7
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
return { decodedValue, readOffset }
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const byte1 = encodedData[readOffset++]
|
|
259
|
-
|
|
260
|
-
if ((byte1 & 0b10000000) === 0) {
|
|
261
|
-
let decodedValue =
|
|
262
|
-
(byte0 & 0b01111111) |
|
|
263
|
-
(byte1 & 0b01111111) << 7
|
|
264
|
-
|
|
265
|
-
if ((byte1 & 0b01000000) !== 0) {
|
|
266
|
-
decodedValue |= -1 << 14
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
return { decodedValue, readOffset }
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
const byte2 = encodedData[readOffset++]
|
|
273
|
-
|
|
274
|
-
if ((byte2 & 0b10000000) === 0) {
|
|
275
|
-
let decodedValue =
|
|
276
|
-
(byte0 & 0b01111111) |
|
|
277
|
-
(byte1 & 0b01111111) << 7 |
|
|
278
|
-
(byte2 & 0b01111111) << 14
|
|
279
|
-
|
|
280
|
-
if ((byte2 & 0b01000000) !== 0) {
|
|
281
|
-
decodedValue |= -1 << 21
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return { decodedValue, readOffset }
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
const byte3 = encodedData[readOffset++]
|
|
288
|
-
|
|
289
|
-
if ((byte3 & 0b10000000) === 0) {
|
|
290
|
-
let decodedValue =
|
|
291
|
-
(byte0 & 0b01111111) |
|
|
292
|
-
(byte1 & 0b01111111) << 7 |
|
|
293
|
-
(byte2 & 0b01111111) << 14 |
|
|
294
|
-
(byte3 & 0b01111111) << 21
|
|
295
|
-
|
|
296
|
-
if ((byte3 & 0b01000000) !== 0) {
|
|
297
|
-
decodedValue |= -1 << 28
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
return { decodedValue, readOffset }
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const byte4 = encodedData[readOffset++]
|
|
304
|
-
|
|
305
|
-
if ((byte4 & 0b10000000) === 0) {
|
|
306
|
-
let decodedValue =
|
|
307
|
-
(byte0 & 0b01111111) |
|
|
308
|
-
(byte1 & 0b01111111) << 7 |
|
|
309
|
-
(byte2 & 0b01111111) << 14 |
|
|
310
|
-
(byte3 & 0b01111111) << 21 |
|
|
311
|
-
(byte4 & 0b01111111) << 28
|
|
312
|
-
|
|
313
|
-
if ((byte4 & 0b01000000) !== 0) {
|
|
314
|
-
decodedValue |= -1 << 31
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
return { decodedValue, readOffset }
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
if (readOffset >= encodedData.length) {
|
|
321
|
-
throw new Error(`Invalid LEB128 data. Last encoded byte sequence is truncated.`)
|
|
322
|
-
} else {
|
|
323
|
-
throw new Error(`LEB128 sequence can't be decoded. Encoded byte sequence represents a value that extends beyond the range of a signed 32 bit integer.`)
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
328
|
-
// Types
|
|
329
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
330
|
-
|
|
331
|
-
export interface DecodedValueAndReadOffset {
|
|
332
|
-
decodedValue: number
|
|
333
|
-
readOffset: number
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
337
|
-
// Tests
|
|
338
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
339
|
-
export function testLeb128Signed() {
|
|
340
|
-
const encodedBytes = createDynamicUint8Array()
|
|
341
|
-
|
|
342
|
-
function runTest(testValue: number) {
|
|
343
|
-
encodedBytes.clear()
|
|
344
|
-
|
|
345
|
-
encodeSignedInt32Fast(testValue, encodedBytes)
|
|
346
|
-
const { decodedValue } = decodeSignedInt32Fast(encodedBytes.elements, 0)
|
|
347
|
-
|
|
348
|
-
if (decodedValue !== testValue) {
|
|
349
|
-
throw new Error(`Expected ${testValue} but got ${decodedValue}`)
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
for (let i = -(2 ** 26); i < 2 ** 26; i++) {
|
|
354
|
-
if (i % 1000000 === 0) {
|
|
355
|
-
logToStderr(i)
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
runTest(i)
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
const x = 1
|
|
362
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { DynamicUint16Array, createDynamicUint16Array } from '../data-structures/DynamicTypedArray.js'
|
|
2
|
-
import { decodeUtf16 } from '../encodings/Utf16.js'
|
|
3
|
-
|
|
4
|
-
export class StringBuilder {
|
|
5
|
-
private outputBuffer: DynamicUint16Array
|
|
6
|
-
|
|
7
|
-
constructor(initialCapacity = 8) {
|
|
8
|
-
this.outputBuffer = createDynamicUint16Array(initialCapacity)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
appendCharCode(charCode: number) {
|
|
12
|
-
this.outputBuffer.add(charCode)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
appendCharCodes(...charCodes: number[]) {
|
|
16
|
-
this.outputBuffer.addArray(charCodes)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
appendCharCodeArray(charCodes: ArrayLike<number>) {
|
|
20
|
-
this.outputBuffer.addArray(charCodes)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
appendString(str: string) {
|
|
24
|
-
const length = str.length
|
|
25
|
-
|
|
26
|
-
for (let i = 0; i < length; i++) {
|
|
27
|
-
this.appendCharCode(str.charCodeAt(i))
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
appendCodePoint(codePoint: number) {
|
|
32
|
-
if (codePoint <= 0xffff) {
|
|
33
|
-
this.appendCharCode(codePoint)
|
|
34
|
-
} else if (codePoint <= 0x10ffff) {
|
|
35
|
-
this.appendCharCode(0xd800 + ((codePoint - 0x10000) >>> 10))
|
|
36
|
-
this.appendCharCode(0xdc00 + ((codePoint - 0x10000) & 1023))
|
|
37
|
-
} else {
|
|
38
|
-
throw new Error(`appendCodePoint: A code point of ${codePoint} cannot be encoded in UTF-16`)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
toString() {
|
|
43
|
-
return decodeUtf16(this.outputBuffer.toTypedArray())
|
|
44
|
-
}
|
|
45
|
-
}
|