修复简繁转换没有转换标题

pull/440/head
gedoor 5 years ago
parent f7c0f98214
commit 4022ea68ba
  1. 41
      app/src/main/java/io/legado/app/help/BookHelp.kt

@ -324,7 +324,8 @@ object BookHelp {
content: String, content: String,
enableReplace: Boolean, enableReplace: Boolean,
): List<String> { ): List<String> {
var c = content var title1 = title
var content1 = content
if (enableReplace) { if (enableReplace) {
synchronized(this) { synchronized(this) {
if (bookName != name || bookOrigin != origin) { if (bookName != name || bookOrigin != origin) {
@ -341,10 +342,10 @@ object BookHelp {
item.pattern.let { item.pattern.let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
try { try {
c = if (item.isRegex) { content1 = if (item.isRegex) {
c.replace(it.toRegex(), item.replacement) content1.replace(it.toRegex(), item.replacement)
} else { } else {
c.replace(it, item.replacement) content1.replace(it, item.replacement)
} }
} catch (e: Exception) { } catch (e: Exception) {
withContext(Main) { withContext(Main) {
@ -355,28 +356,34 @@ object BookHelp {
} }
} }
} }
try {
when (AppConfig.chineseConverterType) {
1 -> {
title1 = HanLP.convertToSimplifiedChinese(title1)
content1 = HanLP.convertToSimplifiedChinese(content1)
}
2 -> {
title1 = HanLP.convertToTraditionalChinese(title1)
content1 = HanLP.convertToTraditionalChinese(content1)
}
}
} catch (e: Exception) {
withContext(Main) {
App.INSTANCE.toast("简繁转换出错")
}
}
val contents = arrayListOf<String>() val contents = arrayListOf<String>()
c.split("\n").forEach { content1.split("\n").forEach {
val str = it.replace("^[\\n\\s\\r]+".toRegex(), "") val str = it.replace("^[\\n\\s\\r]+".toRegex(), "")
if (contents.isEmpty()) { if (contents.isEmpty()) {
contents.add(title) contents.add(title1)
if (str != title && str.isNotEmpty()) { if (str != title1 && str.isNotEmpty()) {
contents.add("${ReadBookConfig.paragraphIndent}$str") contents.add("${ReadBookConfig.paragraphIndent}$str")
} }
} else if (str.isNotEmpty()) { } else if (str.isNotEmpty()) {
contents.add("${ReadBookConfig.paragraphIndent}$str") contents.add("${ReadBookConfig.paragraphIndent}$str")
} }
} }
try {
when (AppConfig.chineseConverterType) {
1 -> c = HanLP.convertToSimplifiedChinese(c)
2 -> c = HanLP.convertToTraditionalChinese(c)
}
} catch (e: Exception) {
withContext(Main) {
App.INSTANCE.toast("简繁转换出错")
}
}
return contents return contents
} }
} }
Loading…
Cancel
Save