优化链接分割规则,避免附加参数中存在 ,{ 时导致规则切错

修复<str0,str2,...{{js}}>这种页数列表写法中,js部分内含 < 或 > 会切割错误的问题

格式化图片和匹配图片规则不在使用同一个正则,加快图片处理速度。

优化<js>和@js处理方法,加快执行速度。

优化一下不需要循环执行却被循环执行的操作
pull/1121/head
bushixuanqi 3 years ago
parent cccfee70ab
commit bd81fd3772
  1. 4
      app/src/main/java/io/legado/app/constant/AppPattern.kt
  2. 19
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  3. 21
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt

@ -5,9 +5,7 @@ import java.util.regex.Pattern
@Suppress("RegExpRedundantEscape")
object AppPattern {
val JS_PATTERN: Pattern =
Pattern.compile("<js>([\\w\\W]+?)</js>", Pattern.CASE_INSENSITIVE)
val JS_PATTERN_END: Pattern =
Pattern.compile("@js:([\\w\\W]+)", Pattern.CASE_INSENSITIVE)
Pattern.compile("<js>([\\w\\W]+?)</js>|@js:([\\w\\W]*)", Pattern.CASE_INSENSITIVE)
val EXP_PATTERN: Pattern = Pattern.compile("\\{\\{([\\w\\W]*?)\\}\\}")
//匹配格式化后的图片格式

@ -3,7 +3,6 @@ package io.legado.app.model.analyzeRule
import android.text.TextUtils
import androidx.annotation.Keep
import io.legado.app.constant.AppConst.SCRIPT_ENGINE
import io.legado.app.constant.AppPattern
import io.legado.app.constant.AppPattern.JS_PATTERN
import io.legado.app.data.entities.BaseBook
import io.legado.app.data.entities.BookChapter
@ -406,23 +405,14 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions {
ruleList.add(SourceRule(mode(tmp), mMode))
}
}
ruleList.add(SourceRule(jsMatcher.group(1)!!, Mode.Js))
ruleList.add(SourceRule(jsMatcher.group(2)?:jsMatcher.group(1), Mode.Js))
start = jsMatcher.end()
}
if (ruleStr.length > start){
val jsMatcherEnd = AppPattern.JS_PATTERN_END.matcher(ruleStr.substring(start))
if(jsMatcherEnd.find()){
tmp = ruleStr.substring(start, jsMatcherEnd.start()).trim { it <= ' ' }
if (tmp.isNotEmpty()) {
ruleList.add(SourceRule(mode(tmp), mMode))
}
ruleList.add(SourceRule(jsMatcherEnd.group(1)!!, Mode.Js))
}else{
tmp = ruleStr.substring(start).trim { it <= ' ' }
if (tmp.isNotEmpty()) {
ruleList.add(SourceRule(mode(tmp), mMode))
}
tmp = ruleStr.substring(start).trim { it <= ' ' }
if (tmp.isNotEmpty()) {
ruleList.add(SourceRule(mode(tmp), mMode))
}
}
@ -672,7 +662,6 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions {
companion object {
private val putPattern = Pattern.compile("@put:(\\{[^}]+?\\})", Pattern.CASE_INSENSITIVE)
private val getPattern = Pattern.compile("@get:\\{([^}]+?)\\}", Pattern.CASE_INSENSITIVE)
private val evalPattern =
Pattern.compile("@get:\\{[^}]+?\\}|\\{\\{[\\w\\W]*?\\}\\}", Pattern.CASE_INSENSITIVE)
private val regexPattern = Pattern.compile("\\$\\d{1,2}")

@ -7,7 +7,6 @@ import com.bumptech.glide.load.model.LazyHeaders
import io.legado.app.constant.AppConst.SCRIPT_ENGINE
import io.legado.app.constant.AppConst.UA_NAME
import io.legado.app.constant.AppPattern.JS_PATTERN
import io.legado.app.constant.AppPattern.JS_PATTERN_END
import io.legado.app.data.entities.BaseBook
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.AppConfig
@ -84,25 +83,13 @@ class AnalyzeUrl(
ruleUrl = tmp.replace("@result", ruleUrl)
}
}
ruleUrl = evalJS(jsMatcher.group(1)!!, ruleUrl) as String
ruleUrl = evalJS(jsMatcher.group(2)?:jsMatcher.group(1), ruleUrl) as String
start = jsMatcher.end()
}
if (ruleUrl.length > start) {
val jsMatcherEnd = JS_PATTERN_END.matcher(ruleUrl.substring(start))
if(jsMatcherEnd.find()){
if (jsMatcherEnd.start() > start) {
tmp =
ruleUrl.substring(start, jsMatcherEnd.start()).trim { it <= ' ' }
if (tmp.isNotEmpty()) {
ruleUrl = tmp.replace("@result", ruleUrl)
}
}
ruleUrl = evalJS(jsMatcherEnd.group(1)!!, ruleUrl) as String
}else{
tmp = ruleUrl.substring(start).trim { it <= ' ' }
if (tmp.isNotEmpty()) {
ruleUrl = tmp.replace("@result", ruleUrl)
}
tmp = ruleUrl.substring(start).trim { it <= ' ' }
if (tmp.isNotEmpty()) {
ruleUrl = tmp.replace("@result", ruleUrl)
}
}
}

Loading…
Cancel
Save