From 2f1be0c404be9574418298a7ad6af7db77f7b8a8 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 6 Nov 2018 21:00:42 +0100 Subject: [PATCH] removing the helper QuotedPrintable class, it is no longer needed --- .../contacts/pro/helpers/QuotedPrintable.kt | 64 ------------------- 1 file changed, 64 deletions(-) delete mode 100644 app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/QuotedPrintable.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/QuotedPrintable.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/QuotedPrintable.kt deleted file mode 100644 index e39bf43b..00000000 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/QuotedPrintable.kt +++ /dev/null @@ -1,64 +0,0 @@ -package com.simplemobiletools.contacts.pro.helpers - -import java.io.ByteArrayOutputStream -import java.net.URLEncoder - -// https://alvinalexander.com/java/jwarehouse/android/core/java/com/google/android/mms/pdu/QuotedPrintable.java.shtml -object QuotedPrintable { - private const val ESCAPE_CHAR: Byte = '='.toByte() - fun decode(value: String?): String { - val bytes = value?.toByteArray() - if (bytes == null || bytes.isEmpty()) { - return "" - } - - val buffer = ByteArrayOutputStream() - var i = 0 - while (i < bytes.size) { - val b = bytes[i].toInt() - if (b == ESCAPE_CHAR.toInt()) { - try { - if ('\r' == bytes[i + 1].toChar() && '\n' == bytes[i + 2].toChar()) { - i += 3 - continue - } - - val u = Character.digit(bytes[++i].toChar(), 16) - val l = Character.digit(bytes[++i].toChar(), 16) - if (u == -1 || l == -1) { - return "" - } - - buffer.write(((u shl 4) + l).toChar().toInt()) - } catch (e: ArrayIndexOutOfBoundsException) { - return "" - } - - } else { - buffer.write(b) - } - i++ - } - return String(buffer.toByteArray()) - } - - fun encode(value: String): String { - val result = StringBuilder() - value.forEach { - if (it == ' ') { - result.append(' ') - } else { - val urlEncoded = urlEncode(it.toString()) - if (urlEncoded == it.toString()) { - val hex = String.format("%04x", it.toInt()).trimStart('0').toUpperCase() - result.append("=$hex") - } else { - result.append(urlEncoded) - } - } - } - return result.toString() - } - - fun urlEncode(value: String) = URLEncoder.encode(value, "UTF-8").replace("+", " ").replace('%', '=') -}