Fix search with non-latin chars #971

This commit is contained in:
J-Jamet
2021-04-29 10:44:12 +02:00
parent f70879581d
commit 006afc6841
5 changed files with 10 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
KeePassDX(3.0.0)
*
* Fix search with non-latin chars #971
KeePassDX(2.9.19)
* Fix search slowdown #964

View File

@@ -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.flattenToAscii
import com.kunzisoft.keepass.utils.StringUtil.removeAccents
import com.kunzisoft.keepass.utils.UuidUtil
class SearchHelper {
@@ -177,13 +177,13 @@ class SearchHelper {
// TODO Search settings
var regularExpression = false
var ignoreCase = true
var flattenToASCII = true
var removeAccents = true
var excludeExpired = false
var searchOnlyInCurrentGroup = false
*/
return stringToCheck.isNotEmpty()
&& stringToCheck.flattenToAscii().contains(
searchParameters.searchQuery.flattenToAscii(), true)
&& stringToCheck.removeAccents().contains(
searchParameters.searchQuery.removeAccents(), true)
}
}
}

View File

@@ -12,19 +12,9 @@ object StringUtil {
return this.replace("[\\r|\\n|\\t|\\s|\\u00A0]+".toRegex(), "")
}
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 String.removeAccents(): String {
return Normalizer.normalize(this, Normalizer.Form.NFD)
.replace("\\p{Mn}+".toRegex(), "")
}
fun ByteArray.toHexString() = joinToString("") { "%02X".format(it) }

View File

@@ -1 +1 @@
*
* Fix search with non-latin chars #971

View File

@@ -1 +1 @@
*
* Correction de la recherche avec des caractères non latin #971