removing the helper QuotedPrintable class, it is no longer needed

This commit is contained in:
tibbi 2018-11-06 21:00:42 +01:00
parent 2408cabd81
commit 2f1be0c404
1 changed files with 0 additions and 64 deletions

View File

@ -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('%', '=')
}