From c9f2071e004c41dc1345995102dc573adf9a0cfa Mon Sep 17 00:00:00 2001 From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com> Date: Sun, 4 Jul 2021 14:37:37 +0800 Subject: [PATCH] Update AnalyzeByJSoup.kt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 允许索引作为首规则,此时相对于children。 head@[1]@text 与 head@children[1]@text 等价 --- .../io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt index 4ce3be1bb..be1615a46 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt @@ -213,7 +213,7 @@ class AnalyzeByJSoup(doc: Any) { val curList = mutableListOf() //当前数字区间 var l = "" //暂存数字字符串 - val head = rus[rus.length-1] == ']' //是否为常规索引写法 + val head = rus.last() == ']' //是否为常规索引写法 if(head){ //常规索引写法[index...] @@ -236,7 +236,7 @@ class AnalyzeByJSoup(doc: Any) { else -> { - //为保证查找顺序,区间和单个索引都添加到同一集合 + //为保证查找顺序,区间和单个索引都添加到同一集合 if(curList.isEmpty())indexSet.indexs.add(curInt!!) else{ @@ -265,7 +265,7 @@ class AnalyzeByJSoup(doc: Any) { curMinus = false //重置 } } - } else while (len --> 1) { //阅读原本写法,逆向遍历,至少两位前置字符,如 p. + } else while (len --> 0) { //阅读原本写法,逆向遍历,至少两位前置字符,如 . val rl = rus[len] if (rl == ' ') continue //跳过空格 @@ -314,8 +314,9 @@ class AnalyzeByJSoup(doc: Any) { val rules = ruleStr.split(".") elements.addAll( - when (rules[0]) { - "children" -> temp.children() + if(ruleStr.isEmpty()) temp.children() //允许索引直接作为根元素,此时前置规则为空,效果与children相同 + else when (rules[0]) { + "children" -> temp.children() //允许索引直接作为根元素,此时前置规则为空,效果与children相同 "class" -> temp.getElementsByClass(rules[1]) "tag" -> temp.getElementsByTag(rules[1]) "id" -> Collector.collect(Evaluator.Id(rules[1]), temp)