normalize strings at highlighting at search results
This commit is contained in:
parent
4eac58016a
commit
0c51f054c6
3 changed files with 8 additions and 3 deletions
|
@ -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'
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -236,3 +236,5 @@ fun getDateFormats() = arrayListOf(
|
|||
"MM/dd",
|
||||
"MM.dd"
|
||||
)
|
||||
|
||||
val normalizeRegex = "\\p{InCombiningDiacriticalMarks}+".toRegex()
|
||||
|
|
Loading…
Reference in a new issue