From 3fc63b8b6b746849df566e8ecf0d4f23b42014db Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 23 Apr 2020 16:03:56 +0200 Subject: [PATCH] Small character optimizations --- app/src/main/java/eu/faircode/email/Helper.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index d7dbeb55a8..b90639d0e5 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -798,8 +798,9 @@ public class Helper { } static boolean containsControlChars(String text) { + int codePoint; for (int offset = 0; offset < text.length(); ) { - int codePoint = text.codePointAt(offset); + codePoint = text.codePointAt(offset); offset += Character.charCount(codePoint); switch (Character.getType(codePoint)) { case Character.CONTROL: // \p{Cc} @@ -817,8 +818,8 @@ public class Helper { // Get extended ASCII characters byte[] octets = text.getBytes(StandardCharsets.ISO_8859_1); + int bytes; for (int i = 0; i < octets.length; i++) { - int bytes; if ((octets[i] & 0b10000000) == 0b00000000) bytes = 1; else if ((octets[i] & 0b11100000) == 0b11000000) @@ -847,9 +848,10 @@ public class Helper { static boolean isISO8859(String text) { // https://en.wikipedia.org/wiki/ISO/IEC_8859-1 + int c; byte[] octets = text.getBytes(StandardCharsets.ISO_8859_1); for (byte b : octets) { - int c = b & 0xFF; + c = b & 0xFF; if (c < 32) return false; if (c >= 127 && c < 160) @@ -863,11 +865,13 @@ public class Helper { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return true; + int codepoint; + Character.UnicodeScript us; Character.UnicodeScript script = null; for (int i = 0; i < s.length(); ) { - int codepoint = s.codePointAt(i); + codepoint = s.codePointAt(i); i += Character.charCount(codepoint); - Character.UnicodeScript us = Character.UnicodeScript.of(codepoint); + us = Character.UnicodeScript.of(codepoint); if (us.equals(Character.UnicodeScript.COMMON)) continue; if (script == null)