From: Niki Roo Date: Thu, 12 Apr 2018 11:31:59 +0000 (+0200) Subject: StringUtils: justify: fix crash, supports HR lines X-Git-Tag: fanfix-swing-0.0.1~21^2~207 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=c0c091af3d5ecd11fd46f517e6a1493f1454ceb0;p=fanfix-swing.git StringUtils: justify: fix crash, supports HR lines --- diff --git a/src/be/nikiroo/utils/StringUtils.java b/src/be/nikiroo/utils/StringUtils.java index b8468a13..2c90d29d 100644 --- a/src/be/nikiroo/utils/StringUtils.java +++ b/src/be/nikiroo/utils/StringUtils.java @@ -267,7 +267,8 @@ public class StringUtils { previousLineComplete = current.isEmpty() || previousItemBulletSpacing != null - || (previous != null && isFullLine(previous)); + || (previous != null && isFullLine(previous)) + || isHrLine(current) || isHrLine(previous); } if (previous == null) { @@ -575,7 +576,8 @@ public class StringUtils { static private boolean isItemLine(String line) { String spacing = getItemSpacing(line); - return spacing != null && line.charAt(spacing.length()) == '-'; + return spacing != null && !spacing.isEmpty() + && line.charAt(spacing.length()) == '-'; } static private String getItemSpacing(String line) { @@ -588,4 +590,22 @@ public class StringUtils { return ""; } + + static private boolean isHrLine(CharSequence line) { + int count = 0; + if (line != null) { + for (int i = 0; i < line.length(); i++) { + char car = line.charAt(i); + if (car == ' ' || car == '\t' || car == '*' || car == '-' + || car == '_' || car == '~' || car == '=' || car == '/' + || car == '\\') { + count++; + } else { + return false; + } + } + } + + return count > 2; + } }