* Performs decode on given content following section 6.2 of RFC 3492. * @protected * @param {Chain} content * @return {number[]|string|Uint8Array|Chain|Promise} Decoded content
(content)
| 251 | * @return {number[]|string|Uint8Array|Chain|Promise} Decoded content |
| 252 | */ |
| 253 | performDecode (content) { |
| 254 | const { |
| 255 | initialBias, |
| 256 | initialN, |
| 257 | tmin, |
| 258 | tmax, |
| 259 | caseSensitivity |
| 260 | } = this.getSettingValues() |
| 261 | |
| 262 | const delimiter = this.getSettingValue('delimiter').getCodePointAt(0) |
| 263 | const base = this.getSettingValue('digitMapping').getLength() |
| 264 | |
| 265 | // Prepare case insensitive content |
| 266 | if (!caseSensitivity) { |
| 267 | content = content.toLowerCase() |
| 268 | } |
| 269 | |
| 270 | // Initialize the state |
| 271 | const input = content.getCodePoints() |
| 272 | const inputLength = input.length |
| 273 | let n = initialN |
| 274 | let bias = initialBias |
| 275 | |
| 276 | // Consume all code points before the last delimiter (if there is one) |
| 277 | // and copy them to output, fail on any non-basic code point |
| 278 | const basicLength = Math.max(input.lastIndexOf(delimiter), 0) |
| 279 | const output = [] |
| 280 | |
| 281 | for (let j = 0; j < basicLength; j++) { |
| 282 | if (!this._isBasic(input[j])) { |
| 283 | throw new InvalidInputError( |
| 284 | `Found unexpected non-basic code point at ${j}`) |
| 285 | } |
| 286 | output.push(input[j]) |
| 287 | } |
| 288 | |
| 289 | let i = 0 |
| 290 | let j = basicLength > 0 ? basicLength + 1 : 0 |
| 291 | let oldi, w, k, digit, t |
| 292 | |
| 293 | while (j < inputLength) { |
| 294 | oldi = i |
| 295 | w = 1 |
| 296 | |
| 297 | for (k = base; true; k += base) { |
| 298 | // Fail if there is no code point to consume next |
| 299 | if (j >= inputLength) { |
| 300 | throw new InvalidInputError('The input ends unexpectedly') |
| 301 | } |
| 302 | |
| 303 | digit = this._digitFromBasicCodePoint(input[j++]) |
| 304 | |
| 305 | if (digit === -1) { |
| 306 | throw new InvalidInputError( |
| 307 | `Found unexpected non-basic code point at ${j - 1}`) |
| 308 | } |
| 309 | |
| 310 | // Overflow detection |
nothing calls this directly
no test coverage detected