* Decodes given code to its character representation. * @protected * @param {string} rawCode Morse code unit * @param {string} shortMark * @param {string} longerMark * @param {string} spaceMark * @return {?string} Character or null, if not defined.
(rawCode, shortMark, longerMark, spaceMark)
| 378 | * @return {?string} Character or null, if not defined. |
| 379 | */ |
| 380 | static decodeCode (rawCode, shortMark, longerMark, spaceMark) { |
| 381 | // Handle space |
| 382 | if (rawCode === spaceMark) { |
| 383 | return ' ' |
| 384 | } |
| 385 | |
| 386 | // Translate marks |
| 387 | const code = MorseCodeEncoder.translateMarks( |
| 388 | rawCode, [shortMark, longerMark], ['.', '-']) |
| 389 | |
| 390 | // Find code in alphabet |
| 391 | const index = codeAlphabet.indexOf(code) |
| 392 | return index !== -1 ? alphabet[index] : null |
| 393 | } |
| 394 | |
| 395 | /** |
| 396 | * Runs from start to end through the string and replaces marks. |
no test coverage detected