From 4022ea68ba1f12d2440432450281d5a4ffb74929 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 23 Oct 2020 17:24:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=AE=80=E7=B9=81=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E6=B2=A1=E6=9C=89=E8=BD=AC=E6=8D=A2=E6=A0=87=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/BookHelp.kt | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 6380d44ed..18222d870 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -324,7 +324,8 @@ object BookHelp { content: String, enableReplace: Boolean, ): List { - var c = content + var title1 = title + var content1 = content if (enableReplace) { synchronized(this) { if (bookName != name || bookOrigin != origin) { @@ -341,10 +342,10 @@ object BookHelp { item.pattern.let { if (it.isNotEmpty()) { try { - c = if (item.isRegex) { - c.replace(it.toRegex(), item.replacement) + content1 = if (item.isRegex) { + content1.replace(it.toRegex(), item.replacement) } else { - c.replace(it, item.replacement) + content1.replace(it, item.replacement) } } catch (e: Exception) { 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() - c.split("\n").forEach { + content1.split("\n").forEach { val str = it.replace("^[\\n\\s\\r]+".toRegex(), "") if (contents.isEmpty()) { - contents.add(title) - if (str != title && str.isNotEmpty()) { + contents.add(title1) + if (str != title1 && str.isNotEmpty()) { contents.add("${ReadBookConfig.paragraphIndent}$str") } } else if (str.isNotEmpty()) { 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 } } \ No newline at end of file