From 2fb74fe9b87565f3d5a6e1815a1ba4f076fd5f6a Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 23 Sep 2020 10:58:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=84=E5=88=99=E8=A7=A3?= =?UTF-8?q?=E6=9E=90bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/model/analyzeRule/AnalyzeRule.kt | 69 ++++++++++--------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index 1b77cdd1a..57b867219 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -447,39 +447,44 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { else -> rule = ruleStr } } - //分离put - rule = splitPutRule(rule, putMap) - //@get,{{ }}, 拆分 - var start = 0 - var tmp: String - val evalMatcher = evalPattern.matcher(rule) - while (evalMatcher.find()) { - if (evalMatcher.start() > start) { - tmp = rule.substring(start, evalMatcher.start()) - if (start == 0 && !tmp.contains("##") && mode != Mode.Js) { - mode = Mode.Regex - } - splitRegex(tmp) - } - tmp = evalMatcher.group() - when { - tmp.startsWith("@get:", true) -> { - ruleType.add(getRuleType) - ruleParam.add(tmp.substring(6, tmp.lastIndex)) - } - tmp.startsWith("{{") -> { - ruleType.add(jsRuleType) - ruleParam.add(tmp.substring(2, tmp.length - 2)) - } - else -> { + if (mode == Mode.Js) { + ruleType.add(defaultRuleType) + ruleParam.add(rule) + } else { + //分离put + rule = splitPutRule(rule, putMap) + //@get,{{ }}, 拆分 + var start = 0 + var tmp: String + val evalMatcher = evalPattern.matcher(rule) + while (evalMatcher.find()) { + if (evalMatcher.start() > start) { + tmp = rule.substring(start, evalMatcher.start()) + if (start == 0 && !tmp.contains("##")) { + mode = Mode.Regex + } splitRegex(tmp) } + tmp = evalMatcher.group() + when { + tmp.startsWith("@get:", true) -> { + ruleType.add(getRuleType) + ruleParam.add(tmp.substring(6, tmp.lastIndex)) + } + tmp.startsWith("{{") -> { + ruleType.add(jsRuleType) + ruleParam.add(tmp.substring(2, tmp.length - 2)) + } + else -> { + splitRegex(tmp) + } + } + start = evalMatcher.end() + } + if (rule.length > start) { + tmp = rule.substring(start) + splitRegex(tmp) } - start = evalMatcher.end() - } - if (rule.length > start) { - tmp = rule.substring(start) - splitRegex(tmp) } } @@ -492,9 +497,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { val ruleStrArray = ruleStr.split("##") val regexMatcher = regexPattern.matcher(ruleStrArray[0]) while (regexMatcher.find()) { - if (mode != Mode.Js) { - mode = Mode.Regex - } + mode = Mode.Regex if (regexMatcher.start() > start) { tmp = ruleStr.substring(start, regexMatcher.start()) ruleType.add(defaultRuleType)