Move Regex out of loop

This commit is contained in:
Cuong Tran 2024-04-26 01:32:45 +07:00
parent 6a496de181
commit 6353366e63
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2

View file

@ -321,12 +321,14 @@ abstract class HttpSource : CatalogueSource {
protected open suspend fun fetchRelatedMangaListBySearch(manga: SManga): List<SManga> { protected open suspend fun fetchRelatedMangaListBySearch(manga: SManga): List<SManga> {
fun String.stripKeyword(): List<String> { fun String.stripKeyword(): List<String> {
val regexWhitespace = Regex("\\s+") val regexWhitespace = Regex("\\s+")
// remove special character val regexSpecialCharacters = Regex("[\\[(!~@#$%^&*|,?:\"<>)\\]]")
return replace(Regex("[\\[(!~@#$%^&*|,?:\"<>)\\]]"), " ") val regexNumberOnly = Regex("^\\d+$")
return replace(regexSpecialCharacters, " ")
.split(regexWhitespace) .split(regexWhitespace)
.map { .map {
// remove number only // remove number only
it.replace(Regex("^\\d+$"), "") it.replace(regexNumberOnly, "")
.lowercase(Locale.getDefault()) .lowercase(Locale.getDefault())
} }
// exclude single character // exclude single character