|
|
@ -306,22 +306,6 @@ class AnalyzeRule(private var book: BaseBook? = null) { |
|
|
|
return vRuleStr |
|
|
|
return vRuleStr |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 替换@get |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private fun replaceGet(ruleStr: String): String { |
|
|
|
|
|
|
|
var vRuleStr = ruleStr |
|
|
|
|
|
|
|
val getMatcher = getPattern.matcher(vRuleStr) |
|
|
|
|
|
|
|
while (getMatcher.find()) { |
|
|
|
|
|
|
|
var value = "" |
|
|
|
|
|
|
|
book?.variableMap?.get(getMatcher.group(1))?.let { |
|
|
|
|
|
|
|
value = it |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
vRuleStr = vRuleStr.replace(getMatcher.group(), value) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return vRuleStr |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 正则替换 |
|
|
|
* 正则替换 |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -454,11 +438,41 @@ class AnalyzeRule(private var book: BaseBook? = null) { |
|
|
|
} |
|
|
|
} |
|
|
|
//分离put |
|
|
|
//分离put |
|
|
|
rule = splitPutRule(rule, putMap) |
|
|
|
rule = splitPutRule(rule, putMap) |
|
|
|
//get替换 |
|
|
|
//get,{{ }},$, 替换 |
|
|
|
rule = replaceGet(rule) |
|
|
|
var start = 0 |
|
|
|
// 拆分表达式替换规则 |
|
|
|
var tmp: String |
|
|
|
if (mode != Mode.Js) { |
|
|
|
val evalMatcher = evalPattern.matcher(rule) |
|
|
|
AnalyzeByRegex.splitRegexRule(rule, ruleParam, ruleType) |
|
|
|
while (evalMatcher.find()) { |
|
|
|
|
|
|
|
if (evalMatcher.start() > start) { |
|
|
|
|
|
|
|
tmp = rule.substring(start, evalMatcher.start()) |
|
|
|
|
|
|
|
ruleType.add(0) |
|
|
|
|
|
|
|
ruleParam.add(tmp) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tmp = evalMatcher.group() |
|
|
|
|
|
|
|
when { |
|
|
|
|
|
|
|
tmp.startsWith("$") -> { |
|
|
|
|
|
|
|
ruleType.add(tmp.substring(1).toInt()) |
|
|
|
|
|
|
|
ruleParam.add(tmp) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tmp.startsWith("@get:", true) -> { |
|
|
|
|
|
|
|
ruleType.add(-2) |
|
|
|
|
|
|
|
ruleParam.add(tmp.substring(6, tmp.lastIndex)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tmp.startsWith("{{") -> { |
|
|
|
|
|
|
|
ruleType.add(-1) |
|
|
|
|
|
|
|
ruleParam.add(tmp.substring(2, tmp.length - 2)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> { |
|
|
|
|
|
|
|
ruleType.add(0) |
|
|
|
|
|
|
|
ruleParam.add(tmp) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
start = evalMatcher.end() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (rule.length > start) { |
|
|
|
|
|
|
|
tmp = rule.substring(start) |
|
|
|
|
|
|
|
ruleType.add(0) |
|
|
|
|
|
|
|
ruleParam.add(tmp) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -468,7 +482,8 @@ class AnalyzeRule(private var book: BaseBook? = null) { |
|
|
|
var j = ruleParam.size |
|
|
|
var j = ruleParam.size |
|
|
|
while (j-- > 0) { |
|
|
|
while (j-- > 0) { |
|
|
|
val regType = ruleType[j] |
|
|
|
val regType = ruleType[j] |
|
|
|
if (regType > 0) { |
|
|
|
when { |
|
|
|
|
|
|
|
regType > 0 -> { |
|
|
|
@Suppress("UNCHECKED_CAST") |
|
|
|
@Suppress("UNCHECKED_CAST") |
|
|
|
val resultList = result as List<String?> |
|
|
|
val resultList = result as List<String?> |
|
|
|
if (resultList.size > regType) { |
|
|
|
if (resultList.size > regType) { |
|
|
@ -476,7 +491,8 @@ class AnalyzeRule(private var book: BaseBook? = null) { |
|
|
|
infoVal.insert(0, resultList[regType]) |
|
|
|
infoVal.insert(0, resultList[regType]) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (regType < 0) { |
|
|
|
} |
|
|
|
|
|
|
|
regType == -1 -> { |
|
|
|
val jsEval: Any = evalJS(ruleParam[j], result) |
|
|
|
val jsEval: Any = evalJS(ruleParam[j], result) |
|
|
|
if (jsEval is String) { |
|
|
|
if (jsEval is String) { |
|
|
|
infoVal.insert(0, jsEval) |
|
|
|
infoVal.insert(0, jsEval) |
|
|
@ -485,8 +501,11 @@ class AnalyzeRule(private var book: BaseBook? = null) { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
infoVal.insert(0, jsEval.toString()) |
|
|
|
infoVal.insert(0, jsEval.toString()) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} |
|
|
|
infoVal.insert(0, ruleParam[j]) |
|
|
|
regType == -2 -> { |
|
|
|
|
|
|
|
infoVal.insert(0, get(ruleParam[j])) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> infoVal.insert(0, ruleParam[j]) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
rule = infoVal.toString() |
|
|
|
rule = infoVal.toString() |
|
|
@ -503,8 +522,8 @@ class AnalyzeRule(private var book: BaseBook? = null) { |
|
|
|
return value |
|
|
|
return value |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
operator fun get(key: String): String? { |
|
|
|
operator fun get(key: String): String { |
|
|
|
return book?.variableMap?.get(key) |
|
|
|
return book?.variableMap?.get(key) ?: "" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -523,6 +542,10 @@ class AnalyzeRule(private var book: BaseBook? = null) { |
|
|
|
companion object { |
|
|
|
companion object { |
|
|
|
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( |
|
|
|
|
|
|
|
"@get:\\{[^}]+?\\}|\\{\\{[\\w\\W]*?\\}\\}|\\$\\d{1,2}", |
|
|
|
|
|
|
|
Pattern.CASE_INSENSITIVE |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|