* Performs decode on given content. * @protected * @param {Chain} content * @return {number[]|string|Uint8Array|Chain} Decoded content
(content)
| 149 | * @return {number[]|string|Uint8Array|Chain} Decoded content |
| 150 | */ |
| 151 | performDecode (content) { |
| 152 | const { alphabet, codes, codeLength } = this._getVariant() |
| 153 | const aCodePoint = this.getSettingValue('aMark').getCodePointAt(0) |
| 154 | const bCodePoint = this.getSettingValue('bMark').getCodePointAt(0) |
| 155 | |
| 156 | // Translate content into known marks |
| 157 | const inputCodePoints = content.getCodePoints() |
| 158 | let inputMarks = '' |
| 159 | let i |
| 160 | |
| 161 | for (i = 0; i < inputCodePoints.length; i++) { |
| 162 | switch (inputCodePoints[i]) { |
| 163 | case aCodePoint: |
| 164 | inputMarks += 'a' |
| 165 | break |
| 166 | case bCodePoint: |
| 167 | inputMarks += 'b' |
| 168 | break |
| 169 | default: |
| 170 | // Ignore unknown mark |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | // Group marks into code blocks |
| 175 | const inputCodes = StringUtil.chunk(inputMarks, codeLength) |
| 176 | |
| 177 | // Map each code block to a letter using the alphabet |
| 178 | let result = '' |
| 179 | let codeIndex |
| 180 | for (i = 0; i < inputCodes.length; i++) { |
| 181 | codeIndex = codes.indexOf(inputCodes[i]) |
| 182 | if (codeIndex !== -1) { |
| 183 | result += alphabet[codeIndex] |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | return result |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Composes a spec for the currently selected variant. |
nothing calls this directly
no test coverage detected