@Test public final void testFormatToWidth() { String str = "one, two, three, four, five, six, seven, eight"; String expect = " one, two\n" + " three\n" + " four\n" + " five, six\n" + " seven\n" + " eight"; String fmt = Util.formatToWidth(10, " ", str, ", "); System.err.println(fmt); assertTrue("Format not OK", expect.equals(fmt)); }
@Deprecated public static String formatToWidth(int width, String padding, String str, String separator) { if (str.isEmpty()) { return ""; } int padLen = padding.length(); int strLen = str.length(); int sepLen = separator.length(); if (strLen + padLen <= width) { return padding + str; } String[] values = str.split(separator); StringBuilder builder = new StringBuilder(strLen + 4 * padLen + 8 * sepLen); int colpos = width; for (String value : values) { int len = value.length(); if (colpos + sepLen + len <= width) { builder.append(separator); } else { builder.append("\n").append(padding); colpos = padLen; } builder.append(value); colpos += len; } return builder.substring(1); }
Util { @Deprecated public static String formatToWidth(int width, String padding, String str, String separator) { if (str.isEmpty()) { return ""; } int padLen = padding.length(); int strLen = str.length(); int sepLen = separator.length(); if (strLen + padLen <= width) { return padding + str; } String[] values = str.split(separator); StringBuilder builder = new StringBuilder(strLen + 4 * padLen + 8 * sepLen); int colpos = width; for (String value : values) { int len = value.length(); if (colpos + sepLen + len <= width) { builder.append(separator); } else { builder.append("\n").append(padding); colpos = padLen; } builder.append(value); colpos += len; } return builder.substring(1); } }
Util { @Deprecated public static String formatToWidth(int width, String padding, String str, String separator) { if (str.isEmpty()) { return ""; } int padLen = padding.length(); int strLen = str.length(); int sepLen = separator.length(); if (strLen + padLen <= width) { return padding + str; } String[] values = str.split(separator); StringBuilder builder = new StringBuilder(strLen + 4 * padLen + 8 * sepLen); int colpos = width; for (String value : values) { int len = value.length(); if (colpos + sepLen + len <= width) { builder.append(separator); } else { builder.append("\n").append(padding); colpos = padLen; } builder.append(value); colpos += len; } return builder.substring(1); }  }
Util { @Deprecated public static String formatToWidth(int width, String padding, String str, String separator) { if (str.isEmpty()) { return ""; } int padLen = padding.length(); int strLen = str.length(); int sepLen = separator.length(); if (strLen + padLen <= width) { return padding + str; } String[] values = str.split(separator); StringBuilder builder = new StringBuilder(strLen + 4 * padLen + 8 * sepLen); int colpos = width; for (String value : values) { int len = value.length(); if (colpos + sepLen + len <= width) { builder.append(separator); } else { builder.append("\n").append(padding); colpos = padLen; } builder.append(value); colpos += len; } return builder.substring(1); }  static Resource getContext(Repository repository, String ctxID); static Resource[] getContexts(String[] tokens, int pos, Repository repository); static Path getPath(String file); static String getPrefixedValue(Value value, Map<String, String> namespaces); @Deprecated static String formatToWidth(int width, String padding, String str, String separator); }
Util { @Deprecated public static String formatToWidth(int width, String padding, String str, String separator) { if (str.isEmpty()) { return ""; } int padLen = padding.length(); int strLen = str.length(); int sepLen = separator.length(); if (strLen + padLen <= width) { return padding + str; } String[] values = str.split(separator); StringBuilder builder = new StringBuilder(strLen + 4 * padLen + 8 * sepLen); int colpos = width; for (String value : values) { int len = value.length(); if (colpos + sepLen + len <= width) { builder.append(separator); } else { builder.append("\n").append(padding); colpos = padLen; } builder.append(value); colpos += len; } return builder.substring(1); }  static Resource getContext(Repository repository, String ctxID); static Resource[] getContexts(String[] tokens, int pos, Repository repository); static Path getPath(String file); static String getPrefixedValue(Value value, Map<String, String> namespaces); @Deprecated static String formatToWidth(int width, String padding, String str, String separator);  }