Method
toPos
(int col, int row, String text)
Source from the content-addressed store, hash-verified
| 33 | public class Demo { |
| 34 | |
| 35 | private static int toPos(int col, int row, String text) { |
| 36 | int currentRow = 0; |
| 37 | int currentCol = 0; |
| 38 | int pos = 0; |
| 39 | while (text.length() > pos) { |
| 40 | if (row == currentRow && currentCol == col) { |
| 41 | return pos; |
| 42 | } |
| 43 | if (text.charAt(pos) == '\n') { |
| 44 | currentRow++; |
| 45 | currentCol = 0; |
| 46 | } else { |
| 47 | currentCol++; |
| 48 | } |
| 49 | pos++; |
| 50 | } |
| 51 | return -1; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * MRZ demo. |
Tested by
no test coverage detected