0
0
mirror of https://github.com/markusfisch/BinaryEye.git synced 2024-09-20 03:52:16 +02:00

Update to latest ZXing C++ wrapper

Which adds a ContentType so we can distinguish between text
and binary content.
This commit is contained in:
Markus Fisch 2022-10-12 21:47:54 +02:00
parent f07c4ac0f4
commit c04b08ab87
4 changed files with 12 additions and 11 deletions

View File

@ -66,5 +66,5 @@ dependencies {
implementation "com.android.support:preference-v14:$support_version"
implementation 'com.github.markusfisch:CameraView:1.9.1'
implementation 'com.github.markusfisch:ScalingImageView:1.4.0'
implementation 'com.github.markusfisch:zxing-cpp:v1.4.0.2'
implementation 'com.github.markusfisch:zxing-cpp:v1.4.0.3'
}

View File

@ -621,6 +621,7 @@ fun Result.redact() = if (
) {
Result(
format,
contentType,
String(
text.toByteArray(Charset.forName("ISO-8859-1")),
Charset.forName("UTF-8")

View File

@ -5,9 +5,6 @@ import android.os.Build
import java.io.UnsupportedEncodingException
import java.net.URLEncoder
private val nonPrintable = "[\\x00-\\x08\\x0e-\\x1f]".toRegex()
fun String.hasNonPrintableCharacters() = nonPrintable.containsMatchIn(this)
private val nonAlNum = "[^a-zA-Z0-9]".toRegex()
private val multipleDots = "[…]+".toRegex()
fun String.foldNonAlNum() = replace(nonAlNum, "")

View File

@ -3,7 +3,7 @@ package de.markusfisch.android.binaryeye.database
import android.os.Parcel
import android.os.Parcelable
import android.text.format.DateFormat
import de.markusfisch.android.binaryeye.app.hasNonPrintableCharacters
import de.markusfisch.android.zxingcpp.ZxingCpp.ContentType
import de.markusfisch.android.zxingcpp.ZxingCpp.Result
data class Scan(
@ -145,12 +145,15 @@ private fun Parcel.readSizedByteArray(): ByteArray? {
fun Result.toScan(): Scan {
val content: String
val raw: ByteArray?
if (text.hasNonPrintableCharacters()) {
content = ""
raw = rawBytes
} else {
content = text
raw = null
when (contentType) {
ContentType.TEXT -> {
content = text
raw = null
}
else -> {
content = ""
raw = rawBytes
}
}
return Scan(
content,