Skip to content

Commit 2d1b9fc

Browse files
author
Samuel Mendes
authored
Fix UCS-2 size computing (#4)
1 parent 3e65791 commit 2d1b9fc

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

segments_calculator.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,6 @@ class GSM7EncodedChar extends EncodedChar {
219219

220220

221221
// Represent a UCS-2 encoded character
222-
// UCS-2 is of fixed length and requires 2 code units per character
223-
// a UCS-2 code unit is an octet (8bits)
224222
class UCS2EncodedChar extends EncodedChar {
225223
constructor(char, graphemeSize) {
226224
super(char);
@@ -229,16 +227,16 @@ class UCS2EncodedChar extends EncodedChar {
229227
if (char.length === 2) {
230228
this.codeUnits = [char.charCodeAt(0), char.charCodeAt(1)];
231229
} else {
232-
this.codeUnits = [0x00, char.charCodeAt(0)];
230+
this.codeUnits = [char.charCodeAt(0)];
233231
}
234232
}
235233

236234
static codeUnitSizeInBits() {
237-
return 8; // UCS-2 code units are 8bits long
235+
return 16;
238236
}
239237

240238
sizeInBits() {
241-
return 16 * this.graphemeSize; // UCS-2 characters are always 2 code units -> 16bits
239+
return 16 * this.raw.length;
242240
}
243241
}
244242

0 commit comments

Comments
 (0)