* Encodes given character to its morse code representation. * @protected * @param {string} char Character to be encoded. * @param {string} shortMark * @param {string} longerMark * @param {string} spaceMark * @return {?string} Morse code representation or null, if not defined.
(char, shortMark, longerMark, spaceMark)
| 350 | * @return {?string} Morse code representation or null, if not defined. |
| 351 | */ |
| 352 | static encodeCharacter (char, shortMark, longerMark, spaceMark) { |
| 353 | // Handle space |
| 354 | if (StringUtil.isWhitespace(char)) { |
| 355 | return spaceMark |
| 356 | } |
| 357 | |
| 358 | // Find char in alphabet |
| 359 | const index = alphabet.indexOf(char) |
| 360 | if (index === -1) { |
| 361 | // Char is not defined |
| 362 | return null |
| 363 | } |
| 364 | |
| 365 | // Translate marks |
| 366 | const code = codeAlphabet[index] |
| 367 | return MorseCodeEncoder.translateMarks( |
| 368 | code, ['.', '-'], [shortMark, longerMark]) |
| 369 | } |
| 370 | |
| 371 | /** |
| 372 | * Decodes given code to its character representation. |
no test coverage detected