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> {
fun String.stripKeyword(): List<String> {
val regexWhitespace = Regex("\\s+")
// remove special character
return replace(Regex("[\\[(!~@#$%^&*|,?:\"<>)\\]]"), " ")
val regexSpecialCharacters = Regex("[\\[(!~@#$%^&*|,?:\"<>)\\]]")
val regexNumberOnly = Regex("^\\d+$")
return replace(regexSpecialCharacters, " ")
.split(regexWhitespace)
.map {
// remove number only
it.replace(Regex("^\\d+$"), "")
it.replace(regexNumberOnly, "")
.lowercase(Locale.getDefault())
}
// exclude single character