|
|
|
@ -360,48 +360,21 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { |
|
|
|
|
fun splitSourceRule(ruleStr: String?, isList: Boolean = false): List<SourceRule> { |
|
|
|
|
if (ruleStr.isNullOrEmpty()) return ArrayList<SourceRule>() |
|
|
|
|
val ruleList = ArrayList<SourceRule>() |
|
|
|
|
//检测Mode |
|
|
|
|
var mMode: Mode = Mode.Default |
|
|
|
|
fun mode(ruleStr0:String)=when { |
|
|
|
|
ruleStr0.startsWith("@@") -> { |
|
|
|
|
mMode = Mode.Default |
|
|
|
|
ruleStr0.substring(2) |
|
|
|
|
} |
|
|
|
|
ruleStr0.startsWith("@XPath:", true) -> { |
|
|
|
|
mMode = Mode.XPath |
|
|
|
|
ruleStr0.substring(7) |
|
|
|
|
} |
|
|
|
|
ruleStr0.startsWith("/") -> {//XPath特征很明显,无需配置单独的识别标头 |
|
|
|
|
mMode = Mode.XPath |
|
|
|
|
ruleStr0 |
|
|
|
|
} |
|
|
|
|
ruleStr0.startsWith("@Json:", true) -> { |
|
|
|
|
mMode = Mode.Json |
|
|
|
|
ruleStr0.substring(6) |
|
|
|
|
} |
|
|
|
|
( ruleStr0[1] == '.' || ruleStr0[1] == '[') && ruleStr0[0] == '$' || isJSON -> { |
|
|
|
|
mMode = Mode.Json |
|
|
|
|
ruleStr0 |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
mMode = Mode.Default |
|
|
|
|
ruleStr0 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//拆分为规则列表 |
|
|
|
|
var start = if(isList && ruleStr.startsWith(":")){ //仅首字符为:时为AllInOne,其实:与伪类选择器冲突,建议改成?更合理 |
|
|
|
|
var start = 0 |
|
|
|
|
//仅首字符为:时为AllInOne,其实:与伪类选择器冲突,建议改成?更合理 |
|
|
|
|
if (isList && ruleStr.startsWith(":")) { |
|
|
|
|
mMode = Mode.Regex |
|
|
|
|
isRegex = true |
|
|
|
|
1 |
|
|
|
|
}else 0 |
|
|
|
|
start = 1 |
|
|
|
|
} |
|
|
|
|
var tmp: String |
|
|
|
|
val jsMatcher = JS_PATTERN.matcher(ruleStr) |
|
|
|
|
while (jsMatcher.find()) { |
|
|
|
|
if (jsMatcher.start() > start) { |
|
|
|
|
tmp = ruleStr.substring(start, jsMatcher.start()).trim { it <= ' ' } |
|
|
|
|
if (tmp.isNotEmpty()) { |
|
|
|
|
ruleList.add(SourceRule(mode(tmp), mMode)) |
|
|
|
|
ruleList.add(SourceRule(tmp, mMode)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ruleList.add(SourceRule(jsMatcher.group(2) ?: jsMatcher.group(1), Mode.Js)) |
|
|
|
@ -411,7 +384,7 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { |
|
|
|
|
if (ruleStr.length > start) { |
|
|
|
|
tmp = ruleStr.substring(start).trim { it <= ' ' } |
|
|
|
|
if (tmp.isNotEmpty()) { |
|
|
|
|
ruleList.add(SourceRule(mode(tmp), mMode)) |
|
|
|
|
ruleList.add(SourceRule(tmp, mMode)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -437,43 +410,56 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { |
|
|
|
|
|
|
|
|
|
init { |
|
|
|
|
this.mode = mainMode |
|
|
|
|
rule = when { |
|
|
|
|
ruleStr.startsWith("@CSS:", true) -> { |
|
|
|
|
mode = Mode.Default |
|
|
|
|
ruleStr |
|
|
|
|
} |
|
|
|
|
ruleStr.startsWith("@@") -> { |
|
|
|
|
mode = Mode.Default |
|
|
|
|
ruleStr.substring(2) |
|
|
|
|
} |
|
|
|
|
ruleStr.startsWith("@XPath:", true) -> { |
|
|
|
|
mode = Mode.XPath |
|
|
|
|
ruleStr.substring(7) |
|
|
|
|
} |
|
|
|
|
ruleStr.startsWith("/") -> {//XPath特征很明显,无需配置单独的识别标头 |
|
|
|
|
mode = Mode.XPath |
|
|
|
|
ruleStr |
|
|
|
|
} |
|
|
|
|
ruleStr.startsWith("@Json:", true) -> { |
|
|
|
|
mode = Mode.Json |
|
|
|
|
ruleStr.substring(6) |
|
|
|
|
} |
|
|
|
|
(ruleStr[1] == '.' || ruleStr[1] == '[') && ruleStr.startsWith("$.") || isJSON -> { |
|
|
|
|
mode = Mode.Json |
|
|
|
|
ruleStr |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
ruleStr |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//分离put |
|
|
|
|
rule = splitPutRule(ruleStr, putMap) |
|
|
|
|
rule = splitPutRule(rule, putMap) |
|
|
|
|
//@get,{{ }}, 拆分 |
|
|
|
|
var start = 0 |
|
|
|
|
var tmp: String |
|
|
|
|
val evalMatcher = evalPattern.matcher(rule) |
|
|
|
|
|
|
|
|
|
if (evalMatcher.find()) { |
|
|
|
|
|
|
|
|
|
var modeX = mode == Mode.Js || mode == Mode.Regex |
|
|
|
|
if (evalMatcher.start() > 0 ) { |
|
|
|
|
tmp = rule.substring(0, evalMatcher.start()) |
|
|
|
|
modeX = modeX || tmp.contains("##") |
|
|
|
|
splitRegex(tmp) |
|
|
|
|
} |
|
|
|
|
if(!modeX)mode = Mode.Regex |
|
|
|
|
tmp = evalMatcher.group() |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
if (mode != Mode.Js && mode != Mode.Regex |
|
|
|
|
&& evalMatcher.start() == 0 |
|
|
|
|
) { |
|
|
|
|
mode = Mode.Regex |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
start = evalMatcher.end() |
|
|
|
|
|
|
|
|
|
while (evalMatcher.find()){ |
|
|
|
|
do { |
|
|
|
|
if (evalMatcher.start() > start) { |
|
|
|
|
tmp = rule.substring(start, evalMatcher.start()) |
|
|
|
|
if (mode != Mode.Js && mode != Mode.Regex |
|
|
|
|
&& start == 0 && !tmp.contains("##") |
|
|
|
|
) { |
|
|
|
|
mode = Mode.Regex |
|
|
|
|
} |
|
|
|
|
splitRegex(tmp) |
|
|
|
|
} |
|
|
|
|
tmp = evalMatcher.group() |
|
|
|
@ -491,9 +477,8 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
start = evalMatcher.end() |
|
|
|
|
} while (evalMatcher.find()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (rule.length > start) { |
|
|
|
|
tmp = rule.substring(start) |
|
|
|
|
splitRegex(tmp) |
|
|
|
|