From 197762b9a3c4403135f3345811e7911fc957583c Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 29 Aug 2022 16:47:53 +0200 Subject: [PATCH] Trim names --- .../main/java/eu/faircode/email/EntityAnswer.java | 3 +++ app/src/main/java/eu/faircode/email/Helper.java | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/EntityAnswer.java b/app/src/main/java/eu/faircode/email/EntityAnswer.java index ae16904220..7a3a5b0d45 100644 --- a/app/src/main/java/eu/faircode/email/EntityAnswer.java +++ b/app/src/main/java/eu/faircode/email/EntityAnswer.java @@ -170,6 +170,9 @@ public class EntityAnswer implements Serializable { } } + first = Helper.trim(first, "."); + last = Helper.trim(last, "."); + text = text.replace("$name$", fullName == null ? "" : Html.escapeHtml(fullName)); text = text.replace("$firstname$", first == null ? "" : Html.escapeHtml(first)); text = text.replace("$lastname$", last == null ? "" : Html.escapeHtml(last)); diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index 5be79d5182..a13db6a2ea 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -2151,6 +2151,21 @@ public class Helper { return (c == '.' /* Latin */ || c == '。' /* Chinese */); } + static String trim(String value, String chars) { + if (value == null) + return null; + + for (Character kar : chars.toCharArray()) { + String k = kar.toString(); + while (value.startsWith(k)) + value = value.substring(1); + while (value.endsWith(k)) + value = value.substring(0, value.length() - 1); + } + + return value; + } + // Files static {