From a9dfd486032d71fe080964e089cc68cf4d4725f0 Mon Sep 17 00:00:00 2001 From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com> Date: Fri, 16 Jul 2021 16:07:12 +0800 Subject: [PATCH] Update AnalyzeRule.kt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化 --- .../app/model/analyzeRule/AnalyzeRule.kt | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 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 1402fa795..3efbd2f02 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,14 +447,35 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { if(evalMatcher.find()){ var modeX = mode == Mode.Js || mode == Mode.Regex - if(evalMatcher.start() != 0){ - tmp = rule.substring(start, evalMatcher.start()) + if (evalMatcher.start() > 0 ) { + tmp = rule.substring(0, evalMatcher.start()) modeX = modeX || tmp.contains("##") splitRegex(tmp) } if(!modeX)mode = Mode.Regex + tmp = evalMatcher.group() - do{ + 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() + + while (evalMatcher.find()){ + if (evalMatcher.start() > start) { + tmp = rule.substring(start, evalMatcher.start()) + splitRegex(tmp) + } tmp = evalMatcher.group() when { tmp.startsWith("@get:", true) -> { @@ -470,7 +491,7 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { } } start = evalMatcher.end() - }while (evalMatcher.find()) + } } if (rule.length > start) {