From c0c091af3d5ecd11fd46f517e6a1493f1454ceb0 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Thu, 12 Apr 2018 13:31:59 +0200 Subject: [PATCH] StringUtils: justify: fix crash, supports HR lines --- src/be/nikiroo/utils/StringUtils.java | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/be/nikiroo/utils/StringUtils.java b/src/be/nikiroo/utils/StringUtils.java index b8468a1..2c90d29 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; + } } -- 2.27.0