@Test public void getOffsetCariageReturnAndLineFeedAsSingleOffset() { LineOffsets lineOffsets = new LineOffsets("\r\nfoo"); assertThat(lineOffsets.getOffset(1, 0)).isEqualTo(0); assertThat(lineOffsets.getOffset(2, 0)).isEqualTo(1); }
public int getOffset(int line, int column) { if (line < 1) { throw new IllegalArgumentException(); } if (column < 0) { throw new IllegalArgumentException(); } if (lineOffsets.containsKey(line)) { return Math.min(lineOffsets.get(line) + column, endOffset); } else { return endOffset; } }
LineOffsets { public int getOffset(int line, int column) { if (line < 1) { throw new IllegalArgumentException(); } if (column < 0) { throw new IllegalArgumentException(); } if (lineOffsets.containsKey(line)) { return Math.min(lineOffsets.get(line) + column, endOffset); } else { return endOffset; } } }
LineOffsets { public int getOffset(int line, int column) { if (line < 1) { throw new IllegalArgumentException(); } if (column < 0) { throw new IllegalArgumentException(); } if (lineOffsets.containsKey(line)) { return Math.min(lineOffsets.get(line) + column, endOffset); } else { return endOffset; } } LineOffsets(String code); }
LineOffsets { public int getOffset(int line, int column) { if (line < 1) { throw new IllegalArgumentException(); } if (column < 0) { throw new IllegalArgumentException(); } if (lineOffsets.containsKey(line)) { return Math.min(lineOffsets.get(line) + column, endOffset); } else { return endOffset; } } LineOffsets(String code); int getStartOffset(Token token); int getEndOffset(Token token); int getOffset(int line, int column); }
LineOffsets { public int getOffset(int line, int column) { if (line < 1) { throw new IllegalArgumentException(); } if (column < 0) { throw new IllegalArgumentException(); } if (lineOffsets.containsKey(line)) { return Math.min(lineOffsets.get(line) + column, endOffset); } else { return endOffset; } } LineOffsets(String code); int getStartOffset(Token token); int getEndOffset(Token token); int getOffset(int line, int column);  }