mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Faster accent replacement method implementation #964
This commit is contained in:
@@ -29,7 +29,7 @@ import com.kunzisoft.keepass.model.SearchInfo
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_FIELD
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
import com.kunzisoft.keepass.timeout.TimeoutHelper
|
||||
import com.kunzisoft.keepass.utils.StringUtil.removeDiacriticalMarks
|
||||
import com.kunzisoft.keepass.utils.StringUtil.flattenToAscii
|
||||
|
||||
class SearchHelper {
|
||||
|
||||
@@ -165,9 +165,8 @@ class SearchHelper {
|
||||
fun checkSearchQuery(stringToCheck: String, searchParameters: SearchParameters): Boolean {
|
||||
if (stringToCheck.isNotEmpty()
|
||||
&& stringToCheck
|
||||
.removeDiacriticalMarks()
|
||||
.contains(searchParameters.searchQuery
|
||||
.removeDiacriticalMarks(),
|
||||
.flattenToAscii()
|
||||
.contains(searchParameters.searchQuery.flattenToAscii(),
|
||||
searchParameters.ignoreCase)) {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -12,9 +12,19 @@ object StringUtil {
|
||||
return this.replace("[\\r|\\n|\\t|\\s|\\u00A0]+".toRegex(), "")
|
||||
}
|
||||
|
||||
fun String.removeDiacriticalMarks(): String {
|
||||
return "\\p{InCombiningDiacriticalMarks}+".toRegex()
|
||||
.replace(Normalizer.normalize(this, Normalizer.Form.NFD), "")
|
||||
fun String.flattenToAscii(): String {
|
||||
var string = this
|
||||
val out = CharArray(string.length)
|
||||
string = Normalizer.normalize(string, Normalizer.Form.NFD)
|
||||
var j = 0
|
||||
var i = 0
|
||||
val n = string.length
|
||||
while (i < n) {
|
||||
val c = string[i]
|
||||
if (c <= '\u007F') out[j++] = c
|
||||
++i
|
||||
}
|
||||
return String(out)
|
||||
}
|
||||
|
||||
fun ByteArray.toHexString() = joinToString("") { "%02X".format(it) }
|
||||
|
||||
Reference in New Issue
Block a user