From a091779302680568bd003af9b5bdf7b1f7235349 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 16 May 2020 16:27:37 +0200 Subject: [PATCH] Fixed removing trailing whitespace This is important for right alignment --- .../java/eu/faircode/email/HtmlHelper.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index 1fc7b0019f..d87d7f5af3 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -1826,6 +1826,8 @@ 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++; @@ -1835,14 +1837,11 @@ public class HtmlHelper { // Remove whitespace before/after newlines text = TRIM_WHITESPACE_NL.matcher(text).replaceAll(" "); + // Remove leading whitespace if (i == 0 || endsWithWhitespace(block.get(i - 1).text())) while (startsWithWhiteSpace(text)) text = text.substring(1); - if (i == block.size() - 1) - while (endsWithWhitespace(text)) - text = text.substring(0, text.length() - 1); - tnode.text(text); if (TextUtils.isEmpty(text)) @@ -1851,6 +1850,25 @@ public class HtmlHelper { i++; } + // Remove trailing whitespace + int i = block.size(); + while (i > 0) { + tnode = block.get(i - 1); + text = tnode.getWholeText(); + if (endsWithWhitespace(text)) { + while (endsWithWhitespace(text)) + text = text.substring(0, text.length() - 1); + + tnode.text(text); + + if (TextUtils.isEmpty(text)) + i--; + else + break; + } else + break; + } + if (debug) { if (block.size() > 0) { TextNode first = block.get(0);