* Performs encode on given content. * @protected * @param {Chain} content * @return {number[]|string|Uint8Array|Chain} Encoded content
(content)
| 110 | * @return {number[]|string|Uint8Array|Chain} Encoded content |
| 111 | */ |
| 112 | performEncode (content) { |
| 113 | const { alphabet, codes, codeLength } = this._getVariant() |
| 114 | const aChar = this.getSettingValue('aMark').getCharAt(0) |
| 115 | const bChar = this.getSettingValue('bMark').getCharAt(0) |
| 116 | |
| 117 | // Prepare content |
| 118 | const lowercaseContent = content.toLowerCase() |
| 119 | |
| 120 | // Map input to alphabet codes |
| 121 | let result = '' |
| 122 | let codeIndex |
| 123 | |
| 124 | for (let i = 0; i < lowercaseContent.getLength(); i++) { |
| 125 | codeIndex = alphabet.indexOf(lowercaseContent.getCharAt(i)) |
| 126 | if (codeIndex !== -1) { |
| 127 | result += codes[codeIndex] |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | // Map code marks, if not using the defaults |
| 132 | if (aChar !== 'a' || bChar !== 'b') { |
| 133 | result = result |
| 134 | .split('') |
| 135 | .map(mark => mark === 'a' ? aChar : bChar) |
| 136 | .join('') |
| 137 | } |
| 138 | |
| 139 | // Chunk codes separated by a whitespace |
| 140 | return ArrayUtil.chunk(Chain.wrap(result).getChars(), codeLength) |
| 141 | .map(slice => slice.join('')) |
| 142 | .join(' ') |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Performs decode on given content. |
nothing calls this directly
no test coverage detected