EnTab { public String entabLine(String line) { int N = line.length(), outCol = 0; StringBuilder sb = new StringBuilder(); char ch; int consumedSpaces = 0; for (int inCol = 0; inCol < N; inCol++) { ch = line.charAt(inCol); if (ch == ' ') { logger.info("Got space at " + inCol); if (tabs.isTabStop(inCol)) { logger.info("Got a Tab Stop " + inCol); sb.append('\t'); outCol += consumedSpaces; consumedSpaces = 0; } else { consumedSpaces++; } continue; } while (inCol-1 > outCol) { logger.info("Padding space at " + inCol); sb.append(' '); outCol++; } sb.append(ch); outCol++; } for (int i = 0; i < consumedSpaces; i++) { logger.info("Padding space at end # " + i); sb.append(' '); } return sb.toString(); } EnTab(int n);  EnTab(); int getTabSpacing(); static void main(String[] argv); void entab(BufferedReader is, PrintWriter out); void entab(BufferedReader is, PrintStream out); String entabLine(String line);  }
@Test public void testIdempotency() { assertEquals("", t4.entabLine("")); assertEquals("", t8.entabLine("")); assertEquals(" ", t4.entabLine(" ")); assertEquals(" ", t4.entabLine(" ")); assertEquals("abcde", t4.entabLine("abcde")); }
@Test public void testLeadingTabs() { System.out.println(t4.entabLine(" A")); assertEquals("\tA", t4.entabLine(" A")); }
@Test public void testEmbeddedTabs() { final String entebbe = t4.entabLine(" A B"); System.out.println("testEmbeddedTabs: result " + entebbe.replaceAll("\t", "<TAB>")); assertEquals("\tA\t B", entebbe); }