@Test public void dontWrapLongWords() { String longWord = "lalalalalalalalalala"; String expectedWrappedWord = "l\n" + "a\n" + "l\n" + "a\n" + "l\n" + "a\n" + "l\n" + "a\n" + "l\n" + "a\n" + "l\n" + "a\n" + "l\n" + "a\n" + "l\n" + "a\n"; StringUtils.wrapWords(longWord, null, 0, false); }
@Nullable public static String wrapWords(String line, String newLine, int watermark, boolean wrapLongWords) { if (line == null) { return null; } else { if (newLine == null) { newLine = System.lineSeparator(); } if (watermark < 1) { watermark = 1; } int inputLineLength = line.length(); int offset = 0; StringBuilder sb = new StringBuilder(inputLineLength + 32); while (inputLineLength - offset > watermark) { if (line.charAt(offset) == 32) { ++offset; } else { int spaceToWrapAt = line.lastIndexOf(32, watermark + offset); if (spaceToWrapAt >= offset) { sb.append(line.substring(offset, spaceToWrapAt)); sb.append(newLine); offset = spaceToWrapAt + 1; } else if (wrapLongWords) { sb.append(line.substring(offset, watermark + offset)); sb.append(newLine); offset += watermark; } else { spaceToWrapAt = line.indexOf(32, watermark + offset); if (spaceToWrapAt >= 0) { sb.append(line.substring(offset, spaceToWrapAt)); sb.append(newLine); offset = spaceToWrapAt + 1; } else { sb.append(line.substring(offset)); offset = inputLineLength; } } } } sb.append(line.substring(offset)); return sb.toString(); } }
StringUtils { @Nullable public static String wrapWords(String line, String newLine, int watermark, boolean wrapLongWords) { if (line == null) { return null; } else { if (newLine == null) { newLine = System.lineSeparator(); } if (watermark < 1) { watermark = 1; } int inputLineLength = line.length(); int offset = 0; StringBuilder sb = new StringBuilder(inputLineLength + 32); while (inputLineLength - offset > watermark) { if (line.charAt(offset) == 32) { ++offset; } else { int spaceToWrapAt = line.lastIndexOf(32, watermark + offset); if (spaceToWrapAt >= offset) { sb.append(line.substring(offset, spaceToWrapAt)); sb.append(newLine); offset = spaceToWrapAt + 1; } else if (wrapLongWords) { sb.append(line.substring(offset, watermark + offset)); sb.append(newLine); offset += watermark; } else { spaceToWrapAt = line.indexOf(32, watermark + offset); if (spaceToWrapAt >= 0) { sb.append(line.substring(offset, spaceToWrapAt)); sb.append(newLine); offset = spaceToWrapAt + 1; } else { sb.append(line.substring(offset)); offset = inputLineLength; } } } } sb.append(line.substring(offset)); return sb.toString(); } } }
StringUtils { @Nullable public static String wrapWords(String line, String newLine, int watermark, boolean wrapLongWords) { if (line == null) { return null; } else { if (newLine == null) { newLine = System.lineSeparator(); } if (watermark < 1) { watermark = 1; } int inputLineLength = line.length(); int offset = 0; StringBuilder sb = new StringBuilder(inputLineLength + 32); while (inputLineLength - offset > watermark) { if (line.charAt(offset) == 32) { ++offset; } else { int spaceToWrapAt = line.lastIndexOf(32, watermark + offset); if (spaceToWrapAt >= offset) { sb.append(line.substring(offset, spaceToWrapAt)); sb.append(newLine); offset = spaceToWrapAt + 1; } else if (wrapLongWords) { sb.append(line.substring(offset, watermark + offset)); sb.append(newLine); offset += watermark; } else { spaceToWrapAt = line.indexOf(32, watermark + offset); if (spaceToWrapAt >= 0) { sb.append(line.substring(offset, spaceToWrapAt)); sb.append(newLine); offset = spaceToWrapAt + 1; } else { sb.append(line.substring(offset)); offset = inputLineLength; } } } } sb.append(line.substring(offset)); return sb.toString(); } } private  StringUtils(); }
StringUtils { @Nullable public static String wrapWords(String line, String newLine, int watermark, boolean wrapLongWords) { if (line == null) { return null; } else { if (newLine == null) { newLine = System.lineSeparator(); } if (watermark < 1) { watermark = 1; } int inputLineLength = line.length(); int offset = 0; StringBuilder sb = new StringBuilder(inputLineLength + 32); while (inputLineLength - offset > watermark) { if (line.charAt(offset) == 32) { ++offset; } else { int spaceToWrapAt = line.lastIndexOf(32, watermark + offset); if (spaceToWrapAt >= offset) { sb.append(line.substring(offset, spaceToWrapAt)); sb.append(newLine); offset = spaceToWrapAt + 1; } else if (wrapLongWords) { sb.append(line.substring(offset, watermark + offset)); sb.append(newLine); offset += watermark; } else { spaceToWrapAt = line.indexOf(32, watermark + offset); if (spaceToWrapAt >= 0) { sb.append(line.substring(offset, spaceToWrapAt)); sb.append(newLine); offset = spaceToWrapAt + 1; } else { sb.append(line.substring(offset)); offset = inputLineLength; } } } } sb.append(line.substring(offset)); return sb.toString(); } } private  StringUtils(); @Nullable static String asComponentName(String val); @Nullable static String asLanguageName(String val); @NotNull static String getSafeValue(String key, List<Map<String, String>> rows); @NotNull static String getSafeValue(String key, Map<String, String> rows); @NotNull static String wrapSeparator(String line, String separator, String newLine, int watermark); @Nullable static String wrapWords(String line, String newLine, int watermark, boolean wrapLongWords); static boolean isEmpty(String str); static boolean isNotEmpty(String str); static String stripDoubleQuotes(String text); }
StringUtils { @Nullable public static String wrapWords(String line, String newLine, int watermark, boolean wrapLongWords) { if (line == null) { return null; } else { if (newLine == null) { newLine = System.lineSeparator(); } if (watermark < 1) { watermark = 1; } int inputLineLength = line.length(); int offset = 0; StringBuilder sb = new StringBuilder(inputLineLength + 32); while (inputLineLength - offset > watermark) { if (line.charAt(offset) == 32) { ++offset; } else { int spaceToWrapAt = line.lastIndexOf(32, watermark + offset); if (spaceToWrapAt >= offset) { sb.append(line.substring(offset, spaceToWrapAt)); sb.append(newLine); offset = spaceToWrapAt + 1; } else if (wrapLongWords) { sb.append(line.substring(offset, watermark + offset)); sb.append(newLine); offset += watermark; } else { spaceToWrapAt = line.indexOf(32, watermark + offset); if (spaceToWrapAt >= 0) { sb.append(line.substring(offset, spaceToWrapAt)); sb.append(newLine); offset = spaceToWrapAt + 1; } else { sb.append(line.substring(offset)); offset = inputLineLength; } } } } sb.append(line.substring(offset)); return sb.toString(); } } private  StringUtils(); @Nullable static String asComponentName(String val); @Nullable static String asLanguageName(String val); @NotNull static String getSafeValue(String key, List<Map<String, String>> rows); @NotNull static String getSafeValue(String key, Map<String, String> rows); @NotNull static String wrapSeparator(String line, String separator, String newLine, int watermark); @Nullable static String wrapWords(String line, String newLine, int watermark, boolean wrapLongWords); static boolean isEmpty(String str); static boolean isNotEmpty(String str); static String stripDoubleQuotes(String text);  }