From 086d68dff191a83f08040cd5c9d70741086922f2 Mon Sep 17 00:00:00 2001 From: Samuel Mendes Date: Mon, 29 Mar 2021 20:02:24 +0200 Subject: [PATCH] Fix UCS-2 size computing --- segments_calculator.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/segments_calculator.js b/segments_calculator.js index 88b12ce..f28f476 100644 --- a/segments_calculator.js +++ b/segments_calculator.js @@ -219,8 +219,6 @@ class GSM7EncodedChar extends EncodedChar { // Represent a UCS-2 encoded character -// UCS-2 is of fixed length and requires 2 code units per character -// a UCS-2 code unit is an octet (8bits) class UCS2EncodedChar extends EncodedChar { constructor(char, graphemeSize) { super(char); @@ -229,16 +227,16 @@ class UCS2EncodedChar extends EncodedChar { if (char.length === 2) { this.codeUnits = [char.charCodeAt(0), char.charCodeAt(1)]; } else { - this.codeUnits = [0x00, char.charCodeAt(0)]; + this.codeUnits = [char.charCodeAt(0)]; } } static codeUnitSizeInBits() { - return 8; // UCS-2 code units are 8bits long + return 16; } sizeInBits() { - return 16 * this.graphemeSize; // UCS-2 characters are always 2 code units -> 16bits + return 16 * this.raw.length; } }