From 35425f123ac142890223e0e62df8dcdc2acfe660 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Sun, 19 May 2019 15:23:29 +0200 Subject: [PATCH] StringUtils: new justifyTexts(..) --- src/be/nikiroo/utils/StringUtils.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/be/nikiroo/utils/StringUtils.java b/src/be/nikiroo/utils/StringUtils.java index f7548aec..fa72a4e8 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. * -- 2.27.0