@Test public void testTranslate() { final String INPUT = "abc\tdef\t\t12345678\t1\t1234567\tabc"; int tbsz = 8; assertEquals(0, ExpandTabsReader.translate(INPUT, 0, tbsz)); assertEquals(2, ExpandTabsReader.translate(INPUT, 2, tbsz)); assertEquals(3, ExpandTabsReader.translate(INPUT, 3, tbsz)); assertEquals(8, ExpandTabsReader.translate(INPUT, 4, tbsz)); assertEquals(10, ExpandTabsReader.translate(INPUT, 6, tbsz)); assertEquals(11, ExpandTabsReader.translate(INPUT, 7, tbsz)); assertEquals(16, ExpandTabsReader.translate(INPUT, 8, tbsz)); assertEquals(24, ExpandTabsReader.translate(INPUT, 9, tbsz)); assertEquals(31, ExpandTabsReader.translate(INPUT, 16, tbsz)); assertEquals(32, ExpandTabsReader.translate(INPUT, 17, tbsz)); assertEquals(40, ExpandTabsReader.translate(INPUT, 18, tbsz)); assertEquals(41, ExpandTabsReader.translate(INPUT, 19, tbsz)); assertEquals(48, ExpandTabsReader.translate(INPUT, 20, tbsz)); assertEquals(54, ExpandTabsReader.translate(INPUT, 26, tbsz)); assertEquals(55, ExpandTabsReader.translate(INPUT, 27, tbsz)); assertEquals(56, ExpandTabsReader.translate(INPUT, 28, tbsz)); }
public static int translate(String line, int column, int tabSize) { if (column < 0) { throw new IllegalArgumentException("`column' is negative"); } if (column > line.length()) { throw new IllegalArgumentException("`column' is out of bounds"); } if (tabSize < 1) { return column; } int newColumn = 0; for (int i = 0; i < column; ++i) { char c = line.charAt(i); switch (c) { case '\t': newColumn += tabSize - (newColumn % tabSize); break; default: ++newColumn; break; } } return newColumn; }
ExpandTabsReader extends FilterReader { public static int translate(String line, int column, int tabSize) { if (column < 0) { throw new IllegalArgumentException("`column' is negative"); } if (column > line.length()) { throw new IllegalArgumentException("`column' is out of bounds"); } if (tabSize < 1) { return column; } int newColumn = 0; for (int i = 0; i < column; ++i) { char c = line.charAt(i); switch (c) { case '\t': newColumn += tabSize - (newColumn % tabSize); break; default: ++newColumn; break; } } return newColumn; } }
ExpandTabsReader extends FilterReader { public static int translate(String line, int column, int tabSize) { if (column < 0) { throw new IllegalArgumentException("`column' is negative"); } if (column > line.length()) { throw new IllegalArgumentException("`column' is out of bounds"); } if (tabSize < 1) { return column; } int newColumn = 0; for (int i = 0; i < column; ++i) { char c = line.charAt(i); switch (c) { case '\t': newColumn += tabSize - (newColumn % tabSize); break; default: ++newColumn; break; } } return newColumn; } ExpandTabsReader(Reader in, int tabSize); }
ExpandTabsReader extends FilterReader { public static int translate(String line, int column, int tabSize) { if (column < 0) { throw new IllegalArgumentException("`column' is negative"); } if (column > line.length()) { throw new IllegalArgumentException("`column' is out of bounds"); } if (tabSize < 1) { return column; } int newColumn = 0; for (int i = 0; i < column; ++i) { char c = line.charAt(i); switch (c) { case '\t': newColumn += tabSize - (newColumn % tabSize); break; default: ++newColumn; break; } } return newColumn; } ExpandTabsReader(Reader in, int tabSize); static Reader wrap(Reader in, Project p); static Reader wrap(Reader in, int tabSize); static int translate(String line, int column, int tabSize); @Override int read(); @Override int read(char[] cbuf, int off, int len); @Override long skip(long n); @Override boolean markSupported(); }
ExpandTabsReader extends FilterReader { public static int translate(String line, int column, int tabSize) { if (column < 0) { throw new IllegalArgumentException("`column' is negative"); } if (column > line.length()) { throw new IllegalArgumentException("`column' is out of bounds"); } if (tabSize < 1) { return column; } int newColumn = 0; for (int i = 0; i < column; ++i) { char c = line.charAt(i); switch (c) { case '\t': newColumn += tabSize - (newColumn % tabSize); break; default: ++newColumn; break; } } return newColumn; } ExpandTabsReader(Reader in, int tabSize); static Reader wrap(Reader in, Project p); static Reader wrap(Reader in, int tabSize); static int translate(String line, int column, int tabSize); @Override int read(); @Override int read(char[] cbuf, int off, int len); @Override long skip(long n); @Override boolean markSupported();  }