|
|
@ -1,8 +1,9 @@ |
|
|
|
package io.legado.app.model.analyzeRule |
|
|
|
package io.legado.app.model.analyzeRule |
|
|
|
|
|
|
|
|
|
|
|
import io.legado.app.utils.isJson |
|
|
|
import io.legado.app.utils.isJson |
|
|
|
import java.util.ArrayList |
|
|
|
import java.util.* |
|
|
|
import java.util.regex.Pattern |
|
|
|
import java.util.regex.Pattern |
|
|
|
|
|
|
|
import kotlin.collections.HashMap |
|
|
|
|
|
|
|
|
|
|
|
//通用的规则切分处理 |
|
|
|
//通用的规则切分处理 |
|
|
|
|
|
|
|
|
|
|
@ -70,6 +71,7 @@ class RuleAnalyzer(data: String, code: Boolean = false) { |
|
|
|
} |
|
|
|
} |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 从剩余字串中拉出一个字符串,直到但不包括匹配序列(匹配参数列表中一项即为匹配),或剩余字串用完。 |
|
|
|
* 从剩余字串中拉出一个字符串,直到但不包括匹配序列(匹配参数列表中一项即为匹配),或剩余字串用完。 |
|
|
|
* @param seq 匹配字符串序列 |
|
|
|
* @param seq 匹配字符串序列 |
|
|
@ -380,7 +382,12 @@ class RuleAnalyzer(data: String, code: Boolean = false) { |
|
|
|
val posPre = pos //记录consumeTo匹配位置 |
|
|
|
val posPre = pos //记录consumeTo匹配位置 |
|
|
|
if (consumeTo(endStr)) { |
|
|
|
if (consumeTo(endStr)) { |
|
|
|
val frv = fr(queue.substring(posPre, pos)) |
|
|
|
val frv = fr(queue.substring(posPre, pos)) |
|
|
|
st.append(queue.substring(startX, posPre - startStr.length) + frv) //压入内嵌规则前的内容,及内嵌规则解析得到的字符串 |
|
|
|
st.append( |
|
|
|
|
|
|
|
queue.substring( |
|
|
|
|
|
|
|
startX, |
|
|
|
|
|
|
|
posPre - startStr.length |
|
|
|
|
|
|
|
) + frv |
|
|
|
|
|
|
|
) //压入内嵌规则前的内容,及内嵌规则解析得到的字符串 |
|
|
|
pos += endStr.length //跳过结束字符串 |
|
|
|
pos += endStr.length //跳过结束字符串 |
|
|
|
startX = pos //记录下次规则起点 |
|
|
|
startX = pos //记录下次规则起点 |
|
|
|
} |
|
|
|
} |
|
|
@ -394,8 +401,10 @@ class RuleAnalyzer(data: String, code: Boolean = false) { |
|
|
|
//-----------此处向下的函数和变量都未被使用,但以后要用-------- |
|
|
|
//-----------此处向下的函数和变量都未被使用,但以后要用-------- |
|
|
|
|
|
|
|
|
|
|
|
val ruleTypeList = ArrayList<String>() |
|
|
|
val ruleTypeList = ArrayList<String>() |
|
|
|
|
|
|
|
|
|
|
|
//设置平衡组函数,json或JavaScript时设置成chompCodeBalanced,否则为chompRuleBalanced |
|
|
|
//设置平衡组函数,json或JavaScript时设置成chompCodeBalanced,否则为chompRuleBalanced |
|
|
|
val chompBalanced = if (code) ::chompCodeBalanced else ::chompRuleBalanced |
|
|
|
val chompBalanced = if (code) ::chompCodeBalanced else ::chompRuleBalanced |
|
|
|
|
|
|
|
|
|
|
|
enum class Mode { |
|
|
|
enum class Mode { |
|
|
|
XPath, Json, Default, Js, Regex |
|
|
|
XPath, Json, Default, Js, Regex |
|
|
|
} |
|
|
|
} |
|
|
@ -538,12 +547,13 @@ class RuleAnalyzer(data: String, code: Boolean = false) { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 参数字符串 |
|
|
|
* 参数字符串 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private val STARTSTRURL = arrayOf(",{",) |
|
|
|
private val STARTSTRURL = arrayOf(",{") |
|
|
|
|
|
|
|
|
|
|
|
private val regexPattern = Pattern.compile("\\$\\d{1,2}") |
|
|
|
private val regexPattern = Pattern.compile("\\$\\d{1,2}") |
|
|
|
private val putPattern = Pattern.compile("@put:(\\{[^}]+?\\})", Pattern.CASE_INSENSITIVE) |
|
|
|
private val putPattern = Pattern.compile("@put:(\\{[^}]+?\\})", Pattern.CASE_INSENSITIVE) |
|
|
|
private val getPattern = Pattern.compile("@get:\\{([^}]+?)\\}", Pattern.CASE_INSENSITIVE) |
|
|
|
private val getPattern = Pattern.compile("@get:\\{([^}]+?)\\}", Pattern.CASE_INSENSITIVE) |
|
|
|
private val evalPattern = Pattern.compile("\\{\\{[\\w\\W]*?\\}\\}", Pattern.CASE_INSENSITIVE) |
|
|
|
private val evalPattern = |
|
|
|
|
|
|
|
Pattern.compile("\\{\\{[\\w\\W]*?\\}\\}", Pattern.CASE_INSENSITIVE) |
|
|
|
|
|
|
|
|
|
|
|
val ENDSTR = mapOf( |
|
|
|
val ENDSTR = mapOf( |
|
|
|
"<js>" to "</js>", |
|
|
|
"<js>" to "</js>", |
|
|
@ -553,18 +563,35 @@ class RuleAnalyzer(data: String, code: Boolean = false) { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 规则起始字符串 |
|
|
|
* 规则起始字符串 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private val STARTSTR = arrayOf("@js:","<js>","</js>","##","@@","@" |
|
|
|
private val STARTSTR = arrayOf( |
|
|
|
,"{{@", "{{","}}" |
|
|
|
"@js:", |
|
|
|
,"}" |
|
|
|
"<js>", |
|
|
|
, "{@", "{/", "{$" |
|
|
|
"</js>", |
|
|
|
, "{class" |
|
|
|
"##", |
|
|
|
, "{id" |
|
|
|
"@@", |
|
|
|
, "{tag" |
|
|
|
"@", |
|
|
|
, "{text" |
|
|
|
"{{@", |
|
|
|
, "{children" |
|
|
|
"{{", |
|
|
|
,"/","$","@xpath:","@json:","@css:" |
|
|
|
"}}", |
|
|
|
,"||", "&&", "%%" |
|
|
|
"}", |
|
|
|
,"@get:{","@put:{" |
|
|
|
"{@", |
|
|
|
|
|
|
|
"{/", |
|
|
|
|
|
|
|
"{$", |
|
|
|
|
|
|
|
"{class", |
|
|
|
|
|
|
|
"{id", |
|
|
|
|
|
|
|
"{tag", |
|
|
|
|
|
|
|
"{text", |
|
|
|
|
|
|
|
"{children", |
|
|
|
|
|
|
|
"/", |
|
|
|
|
|
|
|
"$", |
|
|
|
|
|
|
|
"@xpath:", |
|
|
|
|
|
|
|
"@json:", |
|
|
|
|
|
|
|
"@css:", |
|
|
|
|
|
|
|
"||", |
|
|
|
|
|
|
|
"&&", |
|
|
|
|
|
|
|
"%%", |
|
|
|
|
|
|
|
"@get:{", |
|
|
|
|
|
|
|
"@put:{" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|