From da852076ce5253a4a56dd236f862a735594a126d Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 16 May 2020 17:44:25 +0200 Subject: [PATCH] Whitespace simplification --- .../java/eu/faircode/email/HtmlHelper.java | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index 16cc97c298..94e379545e 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -1827,8 +1827,6 @@ public class HtmlHelper { for (int i = 0; i < block.size(); ) { tnode = block.get(i); text = tnode.getWholeText(); - if (text.contains("7,80")) - Log.i("Here"); if ("-- ".equals(text)) { i++; @@ -1848,6 +1846,14 @@ public class HtmlHelper { text = text.substring(index); } + // Remove multiple trailing whitespace + index = text.length() - 1; + while (isWhiteSpace(text, index) && + (i == block.size() - 1 || index == 0 || isWhiteSpace(text, index - 1))) + index--; + + text = text.substring(0, index + 1); + tnode.text(text); if (TextUtils.isEmpty(text)) @@ -1856,27 +1862,14 @@ public class HtmlHelper { i++; } - // Remove trailing whitespace - int i = block.size(); - while (i > 0) { - tnode = block.get(i - 1); + // Remove last trailing whitespace + if (block.size() > 0) { + tnode = block.get(block.size() - 1); text = tnode.getWholeText(); - index = text.length() - 1; - if (isWhiteSpace(text, index)) { - index--; - while (isWhiteSpace(text, index)) - index--; - - text = text.substring(0, index + 1); - + if (endsWithWhitespace(text)) { + text = text.substring(0, text.length() - 1); tnode.text(text); - - if (TextUtils.isEmpty(text)) - i--; - else - break; - } else - break; + } } if (debug) {