From ef46ae80225a364fca615e2b2920a674be08f8a9 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Jul 2021 15:31:41 +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 --- .../app/model/analyzeRule/AnalyzeRule.kt | 44 +++++-------------- 1 file changed, 12 insertions(+), 32 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 6ea166857..242cdeefa 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 @@ -445,17 +445,21 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { var tmp: String val evalMatcher = evalPattern.matcher(rule) - if (evalMatcher.find()) { - - var modeX = mode == Mode.Js || mode == Mode.Regex - if (evalMatcher.start() > 0) { - tmp = rule.substring(0, evalMatcher.start()) - modeX = modeX || tmp.contains("##") + while (evalMatcher.find()) { + if (evalMatcher.start() > start) { + tmp = rule.substring(start, evalMatcher.start()) + if (mode != Mode.Js && mode != Mode.Regex + && start == 0 && !tmp.contains("##") + ) { + mode = Mode.Regex + } splitRegex(tmp) + } else if (mode != Mode.Js && mode != Mode.Regex + && evalMatcher.start() == 0 + ) { + mode = Mode.Regex } - if (!modeX) mode = Mode.Regex tmp = evalMatcher.group() - when { tmp.startsWith("@get:", true) -> { ruleType.add(getRuleType) @@ -469,32 +473,8 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { splitRegex(tmp) } } - start = evalMatcher.end() - - while (evalMatcher.find()) { - if (evalMatcher.start() > start) { - tmp = rule.substring(start, evalMatcher.start()) - 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)