XMLTreeUtil { public static String tabulate(String src, int tabsCount) { char[] tabs = new char[SPACES_IN_TAB * tabsCount]; fill(tabs, ' '); final StringBuilder builder = new StringBuilder(); final String[] lines = src.split("\n"); for (int i = 0; i < lines.length - 1; i++) { builder.append(tabs) .append(lines[i]) .append('\n'); } builder.append(tabs) .append(lines[lines.length - 1]); return builder.toString(); } private  XMLTreeUtil(); static byte[] insertBetween(byte[] src, int left, int right, String content); static byte[] insertInto(byte[] src, int pos, String content); static T single(List<T> target); static int lastIndexOf(byte[] src, char c, int fromIdx); static int level(Element element); static int openTagLength(NewElement element); static int closeTagLength(NewElement element); static int attributeLength(NewAttribute attribute); static String tabulate(String src, int tabsCount); static Element asElement(Node node); static List<Element> asElements(NodeList list); static List<R> asElements(NodeList list, ElementMapper<? extends R> mapper); static int indexOf(byte[] src, byte[] target, int fromIdx); static int indexOfAttributeName(byte[] src, byte[] target, int fromIdx); static byte[] replaceAll(byte[] src, byte[] target, byte[] replacement); static int rootStart(byte[] xml); static final Charset UTF_8; static final int SPACES_IN_TAB; }
@Test public void shouldTabulateOneLineString() { final String src = "text here"; assertEquals(tabulate(src, 2), " " + src); }
@Test public void shouldTabulateMultilineString() { final String src = "first line\nsecond line"; assertEquals(tabulate(src, 1), " first line\n second line"); }