pull/2706/head
kunfei 2 years ago
parent a7c7f4a578
commit ec207c98e5
  1. 23
      app/src/main/java/io/legado/app/help/book/ContentProcessor.kt

@ -86,16 +86,25 @@ class ContentProcessor private constructor(
//去除重复标题 //去除重复标题
if (BookHelp.removeSameTitle(book, chapter)) try { if (BookHelp.removeSameTitle(book, chapter)) try {
val name = Pattern.quote(book.name) val name = Pattern.quote(book.name)
val title0 = Pattern.quote(chapter.title) var title = Pattern.quote(chapter.title)
val title1 = Pattern.quote( var matcher = Pattern.compile("^(\\s|\\p{P}|${name})*${title}(\\s)*")
chapter.getDisplayTitle(contentReplaceRules, chineseConvert = false)
)
val titleRegex = "^(\\s|\\p{P}|${name})*(${title0}|${title1})(\\s)*"
val matcher = Pattern.compile(titleRegex)
.matcher(mContent) .matcher(mContent)
if (matcher.find()) { if (matcher.find()) {
mContent = mContent.substring(matcher.end()) mContent = mContent.substring(matcher.end())
sameTitleRemoved = true sameTitleRemoved = true
} else {
title = Pattern.quote(
chapter.getDisplayTitle(
contentReplaceRules,
chineseConvert = false
)
)
matcher = Pattern.compile("^(\\s|\\p{P}|${name})*${title}(\\s)*")
.matcher(mContent)
if (matcher.find()) {
mContent = mContent.substring(matcher.end())
sameTitleRemoved = true
}
} }
} catch (e: Exception) { } catch (e: Exception) {
AppLog.put("去除重复标题出错\n${e.localizedMessage}", e) AppLog.put("去除重复标题出错\n${e.localizedMessage}", e)
@ -143,7 +152,7 @@ class ContentProcessor private constructor(
return BookContent(sameTitleRemoved, contents) return BookContent(sameTitleRemoved, contents)
} }
suspend fun replaceContent(content: String): String { private suspend fun replaceContent(content: String): String {
var mContent = content var mContent = content
mContent = mContent.lines().joinToString("\n") { it.trim() } mContent = mContent.lines().joinToString("\n") { it.trim() }
getContentReplaceRules().forEach { item -> getContentReplaceRules().forEach { item ->

Loading…
Cancel
Save