Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c51f054 authored by tibbi's avatar tibbi
Browse files

normalize strings at highlighting at search results

parent 4eac5801
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ buildscript {
        propMinSdkVersion = 16
        propTargetSdkVersion = propCompileSdkVersion
        propVersionCode = 1
        propVersionName = '4.6.5'
        propVersionName = '4.6.6'
        kotlin_version = '1.2.60'
        support_libs = '27.1.1'
    }
+5 −2
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import com.simplemobiletools.commons.helpers.*
import java.text.Normalizer
import java.text.SimpleDateFormat
import java.util.*

@@ -234,14 +235,14 @@ fun String.highlightTextPart(textToHighlight: String, color: Int, highlightAll:
        return spannableString
    }

    var startIndex = indexOf(textToHighlight, 0, true)
    var startIndex = normalizeString().indexOf(textToHighlight, 0, true)
    val indexes = ArrayList<Int>()
    while (startIndex >= 0) {
        if (startIndex != -1) {
            indexes.add(startIndex)
        }

        startIndex = indexOf(textToHighlight, startIndex + textToHighlight.length, true)
        startIndex = normalizeString().indexOf(textToHighlight, startIndex + textToHighlight.length, true)
        if (!highlightAll) {
            break
        }
@@ -255,6 +256,8 @@ fun String.highlightTextPart(textToHighlight: String, color: Int, highlightAll:
    return spannableString
}

fun String.normalizeString() = Normalizer.normalize(this, Normalizer.Form.NFD).replace(normalizeRegex, "")

fun String.getMimeType(): String {
    val typesMap = HashMap<String, String>().apply {
        put("323", "text/h323")
+2 −0
Original line number Diff line number Diff line
@@ -236,3 +236,5 @@ fun getDateFormats() = arrayListOf(
        "MM/dd",
        "MM.dd"
)

val normalizeRegex = "\\p{InCombiningDiacriticalMarks}+".toRegex()