MCPcopy Create free account
hub / github.com/cryptii/cryptii / translateMarks

Method translateMarks

src/Encoder/MorseCode.js:404–428  ·  view source on GitHub ↗

* Runs from start to end through the string and replaces marks. * Removes parts that can't be recognized. * @protected * @param {string} string * @param {string[]} fromMarks * @param {string[]} toMarks * @return {string}

(string, fromMarks, toMarks)

Source from the content-addressed store, hash-verified

402 * @return {string}
403 */
404 static translateMarks (string, fromMarks, toMarks) {
405 let result = ''
406 let i = -1
407 let j, mark, markRecognized
408
409 // Go through string
410 while (++i < string.length) {
411 markRecognized = false
412 j = -1
413
414 // Find a mark that needs replacement
415 while (!markRecognized && ++j < fromMarks.length) {
416 mark = fromMarks[j]
417 markRecognized = string.substr(i, mark.length) === mark
418
419 if (markRecognized) {
420 // Append replacement mark to haystack
421 result += toMarks[j]
422 i += mark.length - 1
423 }
424 }
425 }
426
427 return result
428 }
429}

Callers 3

performDecodeMethod · 0.80
encodeCharacterMethod · 0.80
decodeCodeMethod · 0.80

Calls 1

substrMethod · 0.80

Tested by

no test coverage detected