* 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)
| 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 | } |
no test coverage detected