From 42fe73ac35d969a0ea41945c40c117bac7039b97 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 31 Jan 2022 11:31:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/model/webBook/BookChapterList.kt | 9 ++++----- .../main/java/io/legado/app/utils/StringExtensions.kt | 7 +++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt index d76395e20..61b63f48d 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt @@ -11,6 +11,7 @@ import io.legado.app.model.NoStackTraceException import io.legado.app.model.TocEmptyException import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeUrl +import io.legado.app.utils.isTrue import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.async @@ -23,8 +24,6 @@ import splitties.init.appCtx */ object BookChapterList { - private val falseRegex = "\\s*(?i)(null|false|0)\\s*".toRegex() - suspend fun analyzeChapterList( scope: CoroutineScope, bookSource: BookSource, @@ -188,7 +187,7 @@ object BookChapterList { bookChapter.tag = analyzeRule.getString(upTimeRule) val isVolume = analyzeRule.getString(isVolumeRule) bookChapter.isVolume = false - if (isVolume.isNotEmpty() && !isVolume.matches(falseRegex)) { + if (isVolume.isTrue()) { bookChapter.isVolume = true } if (bookChapter.url.isEmpty()) { @@ -203,10 +202,10 @@ object BookChapterList { if (bookChapter.title.isNotEmpty()) { val isVip = analyzeRule.getString(vipRule) val isPay = analyzeRule.getString(payRule) - if (isVip.isNotEmpty() && !isVip.matches(falseRegex)) { + if (isVip.isTrue()) { bookChapter.isVip = true } - if (isPay.isNotEmpty() && !isPay.matches(falseRegex)) { + if (isPay.isTrue()) { bookChapter.isPay = true } chapterList.add(bookChapter) diff --git a/app/src/main/java/io/legado/app/utils/StringExtensions.kt b/app/src/main/java/io/legado/app/utils/StringExtensions.kt index d026812e8..341c8a417 100644 --- a/app/src/main/java/io/legado/app/utils/StringExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/StringExtensions.kt @@ -53,6 +53,13 @@ fun String?.isXml(): Boolean = str.startsWith("<") && str.endsWith(">") } ?: false +fun String?.isTrue(nullIsTrue: Boolean = false): Boolean { + if (this.isNullOrBlank() || this == "null") { + return nullIsTrue + } + return this.matches("\\s*(?i)(true|ok|yes|1)\\s*".toRegex()) +} + fun String.splitNotBlank(vararg delimiter: String): Array = run { this.split(*delimiter).map { it.trim() }.filterNot { it.isBlank() }.toTypedArray() }