格式化代码

pull/1112/head
gedoor 3 years ago
parent 306fc67901
commit ca57577711
  1. 39
      app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt

@ -115,13 +115,13 @@ class RuleAnalyzer(data: String, code: Boolean = false) {
//其中js只要符合语法,就不用避开任何阅读关键字,自由发挥 //其中js只要符合语法,就不用避开任何阅读关键字,自由发挥
fun chompJsBalanced( fun chompJsBalanced(
f: ((Char) -> Boolean?) = { f: ((Char) -> Boolean?) = {
when (it) { when (it) {
'{' -> true //开始嵌套一层 '{' -> true //开始嵌套一层
'}' -> false //闭合一层嵌套 '}' -> false //闭合一层嵌套
else -> null else -> null
}
} }
}
): Boolean { ): Boolean {
var pos = pos //声明变量记录临时处理位置 var pos = pos //声明变量记录临时处理位置
var depth = 0 //嵌套深度 var depth = 0 //嵌套深度
@ -139,11 +139,11 @@ class RuleAnalyzer(data: String, code: Boolean = false) {
var c = queue[pos++] var c = queue[pos++]
if (c != '\\') { //非转义字符 if (c != '\\') { //非转义字符
if (c == '\'' && !commits && !commit && !regex && !inDoubleQuote && !inOtherQuote) inSingleQuote = if (c == '\'' && !commits && !commit && !regex && !inDoubleQuote && !inOtherQuote) inSingleQuote =
!inSingleQuote //匹配具有语法功能的单引号 !inSingleQuote //匹配具有语法功能的单引号
else if (c == '"' && !commits && !commit && !regex && !inSingleQuote && !inOtherQuote) inDoubleQuote = else if (c == '"' && !commits && !commit && !regex && !inSingleQuote && !inOtherQuote) inDoubleQuote =
!inDoubleQuote //匹配具有语法功能的双引号 !inDoubleQuote //匹配具有语法功能的双引号
else if (c == '`' && !commits && !commit && !regex && !inSingleQuote && !inDoubleQuote) inOtherQuote = else if (c == '`' && !commits && !commit && !regex && !inSingleQuote && !inDoubleQuote) inOtherQuote =
!inOtherQuote //匹配具有语法功能的'`' !inOtherQuote //匹配具有语法功能的'`'
else if (c == '/' && !commits && !commit && !regex && !inSingleQuote && !inDoubleQuote && !inOtherQuote) { //匹配注释或正则起点 else if (c == '/' && !commits && !commit && !regex && !inSingleQuote && !inDoubleQuote && !inOtherQuote) { //匹配注释或正则起点
c = queue[pos++] c = queue[pos++]
when (c) { when (c) {
@ -323,10 +323,10 @@ class RuleAnalyzer(data: String, code: Boolean = false) {
val next = if (queue[pos] == '[') ']' else ')' //平衡组末尾字符 val next = if (queue[pos] == '[') ']' else ')' //平衡组末尾字符
if (!chompBalanced(queue[pos], next)) throw Error( if (!chompBalanced(queue[pos], next)) throw Error(
queue.substring( queue.substring(
0, 0,
start start
) + "后未平衡" ) + "后未平衡"
) //拉出一个筛选器,不平衡则报错 ) //拉出一个筛选器,不平衡则报错
} while (end > pos) } while (end > pos)
@ -383,10 +383,7 @@ class RuleAnalyzer(data: String, code: Boolean = false) {
val next = if (queue[pos] == '[') ']' else ')' //平衡组末尾字符 val next = if (queue[pos] == '[') ']' else ')' //平衡组末尾字符
if (!chompBalanced(queue[pos], next)) throw Error( if (!chompBalanced(queue[pos], next)) throw Error(
queue.substring( queue.substring(0, start) + "后未平衡"
0,
start
) + "后未平衡"
) //拉出一个筛选器,不平衡则报错 ) //拉出一个筛选器,不平衡则报错
} while (end > pos) } while (end > pos)
@ -409,10 +406,10 @@ class RuleAnalyzer(data: String, code: Boolean = false) {
* *
* */ * */
fun innerRule( fun innerRule(
inner: String, inner: String,
startStep: Int = 1, startStep: Int = 1,
endStep: Int = 1, endStep: Int = 1,
fr: (String) -> String? fr: (String) -> String?
): String { ): String {
startX = pos //设置规则起点 startX = pos //设置规则起点

Loading…
Cancel
Save