Update AnalyzeByJSoup.kt

允许索引作为首规则,此时相对于children。

head@[1]@text 与 head@children[1]@text 等价
pull/1099/head
bushixuanqi 3 years ago committed by GitHub
parent d8a83f9e15
commit c9f2071e00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt

@ -213,7 +213,7 @@ class AnalyzeByJSoup(doc: Any) {
val curList = mutableListOf<Int?>() //当前数字区间 val curList = mutableListOf<Int?>() //当前数字区间
var l = "" //暂存数字字符串 var l = "" //暂存数字字符串
val head = rus[rus.length-1] == ']' //是否为常规索引写法 val head = rus.last() == ']' //是否为常规索引写法
if(head){ //常规索引写法[index...] if(head){ //常规索引写法[index...]
@ -236,7 +236,7 @@ class AnalyzeByJSoup(doc: Any) {
else -> { else -> {
//为保证查找顺序,区间和单个索引都添加到同一集合 //为保证查找顺序,区间和单个索引都添加到同一集合
if(curList.isEmpty())indexSet.indexs.add(curInt!!) if(curList.isEmpty())indexSet.indexs.add(curInt!!)
else{ else{
@ -265,7 +265,7 @@ class AnalyzeByJSoup(doc: Any) {
curMinus = false //重置 curMinus = false //重置
} }
} }
} else while (len --> 1) { //阅读原本写法,逆向遍历,至少两位前置字符,如 p. } else while (len --> 0) { //阅读原本写法,逆向遍历,至少两位前置字符,如 .
val rl = rus[len] val rl = rus[len]
if (rl == ' ') continue //跳过空格 if (rl == ' ') continue //跳过空格
@ -314,8 +314,9 @@ class AnalyzeByJSoup(doc: Any) {
val rules = ruleStr.split(".") val rules = ruleStr.split(".")
elements.addAll( elements.addAll(
when (rules[0]) { if(ruleStr.isEmpty()) temp.children() //允许索引直接作为根元素,此时前置规则为空,效果与children相同
"children" -> temp.children() else when (rules[0]) {
"children" -> temp.children() //允许索引直接作为根元素,此时前置规则为空,效果与children相同
"class" -> temp.getElementsByClass(rules[1]) "class" -> temp.getElementsByClass(rules[1])
"tag" -> temp.getElementsByTag(rules[1]) "tag" -> temp.getElementsByTag(rules[1])
"id" -> Collector.collect(Evaluator.Id(rules[1]), temp) "id" -> Collector.collect(Evaluator.Id(rules[1]), temp)

Loading…
Cancel
Save