From: Niki Roo Date: Sun, 19 May 2019 13:23:29 +0000 (+0200) Subject: StringUtils: new justifyTexts(..) X-Git-Tag: fanfix-3.0.1~29^2~45 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=35425f123ac142890223e0e62df8dcdc2acfe660;p=fanfix.git StringUtils: new justifyTexts(..) --- diff --git a/src/be/nikiroo/utils/StringUtils.java b/src/be/nikiroo/utils/StringUtils.java index f7548ae..fa72a4e 100644 --- a/src/be/nikiroo/utils/StringUtils.java +++ b/src/be/nikiroo/utils/StringUtils.java @@ -156,6 +156,30 @@ public class StringUtils { return text; } + /** + * Justify a text into width-sized (at the maximum) lines and return all the + * lines concatenated into a single '\\n'-separated line of text. + * + * @param text + * the {@link String} to justify + * @param width + * the maximum size of the resulting lines + * + * @return a list of justified text lines concatenated into a single + * '\\n'-separated line of text + */ + static public String justifyTexts(String text, int width) { + StringBuilder builder = new StringBuilder(); + for (String line : justifyText(text, width, null)) { + if (builder.length() > 0) { + builder.append('\n'); + } + builder.append(line); + } + + return builder.toString(); + } + /** * Justify a text into width-sized (at the maximum) lines. *