|
|
@ -11,7 +11,10 @@ import io.legado.app.data.entities.BookChapter |
|
|
|
import io.legado.app.data.entities.ReplaceRule |
|
|
|
import io.legado.app.data.entities.ReplaceRule |
|
|
|
import io.legado.app.model.localBook.AnalyzeTxtFile |
|
|
|
import io.legado.app.model.localBook.AnalyzeTxtFile |
|
|
|
import io.legado.app.utils.* |
|
|
|
import io.legado.app.utils.* |
|
|
|
|
|
|
|
import kotlinx.coroutines.Dispatchers.Main |
|
|
|
|
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import org.apache.commons.text.similarity.JaccardSimilarity |
|
|
|
import org.apache.commons.text.similarity.JaccardSimilarity |
|
|
|
|
|
|
|
import org.jetbrains.anko.toast |
|
|
|
import java.io.File |
|
|
|
import java.io.File |
|
|
|
import kotlin.math.min |
|
|
|
import kotlin.math.min |
|
|
|
|
|
|
|
|
|
|
@ -262,7 +265,7 @@ object BookHelp { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun disposeContent( |
|
|
|
suspend fun disposeContent( |
|
|
|
title: String, |
|
|
|
title: String, |
|
|
|
name: String, |
|
|
|
name: String, |
|
|
|
origin: String?, |
|
|
|
origin: String?, |
|
|
@ -272,15 +275,19 @@ object BookHelp { |
|
|
|
var c = content |
|
|
|
var c = content |
|
|
|
if (enableReplace) { |
|
|
|
if (enableReplace) { |
|
|
|
upReplaceRules(name, origin) |
|
|
|
upReplaceRules(name, origin) |
|
|
|
kotlin.runCatching { |
|
|
|
replaceRules.forEach { item -> |
|
|
|
replaceRules.forEach { item -> |
|
|
|
item.pattern.let { |
|
|
|
item.pattern.let { |
|
|
|
if (it.isNotEmpty()) { |
|
|
|
if (it.isNotEmpty()) { |
|
|
|
try { |
|
|
|
c = if (item.isRegex) { |
|
|
|
c = if (item.isRegex) { |
|
|
|
c.replace(it.toRegex(), item.replacement) |
|
|
|
c.replace(it.toRegex(), item.replacement) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
c.replace(it, item.replacement) |
|
|
|
c.replace(it, item.replacement) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
|
|
|
withContext(Main) { |
|
|
|
|
|
|
|
App.INSTANCE.toast("${item.name}替换出错") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|