From 4aa80e7385e417e818d6aec70a349f503fda3369 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 19 Jul 2019 17:33:57 +0800 Subject: [PATCH 1/2] up --- .../model/analyzeRule/AnalyzeByJSonPath.kt | 16 ++++---- .../app/model/analyzeRule/AnalyzeByJSoup.kt | 40 +++++++------------ .../app/model/analyzeRule/AnalyzeByXPath.kt | 25 ++++++------ 3 files changed, 36 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSonPath.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSonPath.kt index 79c6fa28e..1f4ee7779 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSonPath.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSonPath.kt @@ -24,10 +24,10 @@ class AnalyzeByJSonPath { val rules: Array val elementsType: String if (rule.contains("&&")) { - rules = rule.split("&&".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + rules = rule.split("&&").dropLastWhile { it.isEmpty() }.toTypedArray() elementsType = "&" } else { - rules = rule.split("\\|\\|".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + rules = rule.split("||").dropLastWhile { it.isEmpty() }.toTypedArray() elementsType = "|" } if (rules.size == 1) { @@ -82,15 +82,15 @@ class AnalyzeByJSonPath { val elementsType: String when { rule.contains("&&") -> { - rules = rule.split("&&".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + rules = rule.split("&&").dropLastWhile { it.isEmpty() }.toTypedArray() elementsType = "&" } rule.contains("%%") -> { - rules = rule.split("%%".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + rules = rule.split("%%").dropLastWhile { it.isEmpty() }.toTypedArray() elementsType = "%" } else -> { - rules = rule.split("\\|\\|".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + rules = rule.split("||").dropLastWhile { it.isEmpty() }.toTypedArray() elementsType = "|" } } @@ -159,15 +159,15 @@ class AnalyzeByJSonPath { val rules: Array when { rule.contains("&&") -> { - rules = rule.split("&&".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + rules = rule.split("&&").dropLastWhile { it.isEmpty() }.toTypedArray() elementsType = "&" } rule.contains("%%") -> { - rules = rule.split("%%".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + rules = rule.split("%%").dropLastWhile { it.isEmpty() }.toTypedArray() elementsType = "%" } else -> { - rules = rule.split("\\|\\|".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + rules = rule.split("||").dropLastWhile { it.isEmpty() }.toTypedArray() elementsType = "|" } } diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt index 7f4167271..538ad607f 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt @@ -79,23 +79,17 @@ class AnalyzeByJSoup { val elementsType: String val ruleStrS: Array when { - sourceRule.elementsRule.contains("&") -> { + sourceRule.elementsRule.contains("&&") -> { elementsType = "&" - ruleStrS = - sourceRule.elementsRule.split("&+".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + ruleStrS = sourceRule.elementsRule.split("&&").dropLastWhile { it.isEmpty() }.toTypedArray() } sourceRule.elementsRule.contains("%%") -> { elementsType = "%" - ruleStrS = - sourceRule.elementsRule.split("%%".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + ruleStrS = sourceRule.elementsRule.split("%%").dropLastWhile { it.isEmpty() }.toTypedArray() } else -> { elementsType = "|" - ruleStrS = if (sourceRule.isCss) { - sourceRule.elementsRule.split("\\|\\|".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() - } else { - sourceRule.elementsRule.split("\\|+".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() - } + ruleStrS = sourceRule.elementsRule.split("||").dropLastWhile { it.isEmpty() }.toTypedArray() } } val results = ArrayList>() @@ -148,21 +142,17 @@ class AnalyzeByJSoup { val elementsType: String val ruleStrS: Array when { - sourceRule.elementsRule.contains("&") -> { + sourceRule.elementsRule.contains("&&") -> { elementsType = "&" - ruleStrS = sourceRule.elementsRule.split("&+".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + ruleStrS = sourceRule.elementsRule.split("&&").dropLastWhile { it.isEmpty() }.toTypedArray() } - sourceRule.elementsRule.contains("%") -> { + sourceRule.elementsRule.contains("%%") -> { elementsType = "%" - ruleStrS = sourceRule.elementsRule.split("%+".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + ruleStrS = sourceRule.elementsRule.split("%%").dropLastWhile { it.isEmpty() }.toTypedArray() } else -> { elementsType = "|" - ruleStrS = if (sourceRule.isCss) { - sourceRule.elementsRule.split("\\|\\|".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() - } else { - sourceRule.elementsRule.split("\\|+".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() - } + ruleStrS = sourceRule.elementsRule.split("||").dropLastWhile { it.isEmpty() }.toTypedArray() } } val elementsList = ArrayList() @@ -225,7 +215,7 @@ class AnalyzeByJSoup { private fun getElementsSingle(temp: Element, rule: String): Elements { val elements = Elements() try { - val rs = rule.trim { it <= ' ' }.split("@".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + val rs = rule.trim { it <= ' ' }.split("@").dropLastWhile { it.isEmpty() }.toTypedArray() if (rs.size > 1) { elements.add(temp) for (rl in rs) { @@ -237,15 +227,15 @@ class AnalyzeByJSoup { elements.addAll(es) } } else { - val rulePcx = rule.split("!".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + val rulePcx = rule.split("!").dropLastWhile { it.isEmpty() }.toTypedArray() val rulePc = - rulePcx[0].trim { it <= ' ' }.split(">".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + rulePcx[0].trim { it <= ' ' }.split(">").dropLastWhile { it.isEmpty() }.toTypedArray() val rules = - rulePc[0].trim { it <= ' ' }.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + rulePc[0].trim { it <= ' ' }.split(".").dropLastWhile { it.isEmpty() }.toTypedArray() var filterRules: Array? = null var needFilterElements = rulePc.size > 1 && !isEmpty(rulePc[1].trim { it <= ' ' }) if (needFilterElements) { - filterRules = rulePc[1].trim { it <= ' ' }.split("\\.".toRegex()).dropLastWhile { it.isEmpty() } + filterRules = rulePc[1].trim { it <= ' ' }.split(".").dropLastWhile { it.isEmpty() } .toTypedArray() filterRules[0] = filterRules[0].trim { it <= ' ' } val validKeys = listOf("class", "id", "tag", "text") @@ -344,7 +334,7 @@ class AnalyzeByJSoup { } var elements = Elements() elements.add(element) - val rules = ruleStr.split("@".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + val rules = ruleStr.split("@").dropLastWhile { it.isEmpty() }.toTypedArray() for (i in 0 until rules.size - 1) { val es = Elements() for (elt in elements) { diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt index eca6674c2..726fb943a 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt @@ -34,13 +34,13 @@ class AnalyzeByXPath { val elementsType: String val rules: Array if (xPath.contains("&&")) { - rules = xPath.split("&&".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + rules = xPath.split("&&").dropLastWhile { it.isEmpty() }.toTypedArray() elementsType = "&" } else if (xPath.contains("%%")) { - rules = xPath.split("%%".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + rules = xPath.split("%%").dropLastWhile { it.isEmpty() }.toTypedArray() elementsType = "%" } else { - rules = xPath.split("\\|\\|".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + rules = xPath.split("||").dropLastWhile { it.isEmpty() }.toTypedArray() elementsType = "|" } if (rules.size == 1) { @@ -80,13 +80,13 @@ class AnalyzeByXPath { val elementsType: String val rules: Array if (xPath.contains("&&")) { - rules = xPath.split("&&".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + rules = xPath.split("&&").dropLastWhile { it.isEmpty() }.toTypedArray() elementsType = "&" } else if (xPath.contains("%%")) { - rules = xPath.split("%%".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + rules = xPath.split("%%").dropLastWhile { it.isEmpty() }.toTypedArray() elementsType = "%" } else { - rules = xPath.split("\\|\\|".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + rules = xPath.split("||").dropLastWhile { it.isEmpty() }.toTypedArray() elementsType = "|" } if (rules.size == 1) { @@ -132,17 +132,18 @@ class AnalyzeByXPath { val rules: Array val elementsType: String if (rule.contains("&&")) { - rules = rule.split("&&".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + rules = rule.split("&&").dropLastWhile { it.isEmpty() }.toTypedArray() elementsType = "&" } else { - rules = rule.split("\\|\\|".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + rules = rule.split("||").dropLastWhile { it.isEmpty() }.toTypedArray() elementsType = "|" } if (rules.size == 1) { - /*Object object = jxDocument.selOne(rule); - result = object instanceof Element ? ((Element) object).html() : (String) object;*/ - val jxNodes = jxDocument!!.selN(rule) ?: return null - return TextUtils.join(",", jxNodes) + val jxNodes = jxDocument?.selN(rule) + jxNodes?.let { + TextUtils.join(",", jxNodes) + } + return null } else { val sb = StringBuilder() for (rl in rules) { From 24e98561c95ea1f329863be8382fffa93af88d06 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 19 Jul 2019 17:45:40 +0800 Subject: [PATCH 2/2] up --- .../app/model/analyzeRule/AnalyzeByXPath.kt | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt index 726fb943a..3ba6a3e26 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt @@ -33,15 +33,19 @@ class AnalyzeByXPath { val jxNodes = ArrayList() val elementsType: String val rules: Array - if (xPath.contains("&&")) { - rules = xPath.split("&&").dropLastWhile { it.isEmpty() }.toTypedArray() - elementsType = "&" - } else if (xPath.contains("%%")) { - rules = xPath.split("%%").dropLastWhile { it.isEmpty() }.toTypedArray() - elementsType = "%" - } else { - rules = xPath.split("||").dropLastWhile { it.isEmpty() }.toTypedArray() - elementsType = "|" + when { + xPath.contains("&&") -> { + rules = xPath.split("&&").dropLastWhile { it.isEmpty() }.toTypedArray() + elementsType = "&" + } + xPath.contains("%%") -> { + rules = xPath.split("%%").dropLastWhile { it.isEmpty() }.toTypedArray() + elementsType = "%" + } + else -> { + rules = xPath.split("||").dropLastWhile { it.isEmpty() }.toTypedArray() + elementsType = "|" + } } if (rules.size == 1) { return jxDocument!!.selN(rules[0]) @@ -79,15 +83,19 @@ class AnalyzeByXPath { val result = ArrayList() val elementsType: String val rules: Array - if (xPath.contains("&&")) { - rules = xPath.split("&&").dropLastWhile { it.isEmpty() }.toTypedArray() - elementsType = "&" - } else if (xPath.contains("%%")) { - rules = xPath.split("%%").dropLastWhile { it.isEmpty() }.toTypedArray() - elementsType = "%" - } else { - rules = xPath.split("||").dropLastWhile { it.isEmpty() }.toTypedArray() - elementsType = "|" + when { + xPath.contains("&&") -> { + rules = xPath.split("&&").dropLastWhile { it.isEmpty() }.toTypedArray() + elementsType = "&" + } + xPath.contains("%%") -> { + rules = xPath.split("%%").dropLastWhile { it.isEmpty() }.toTypedArray() + elementsType = "%" + } + else -> { + rules = xPath.split("||").dropLastWhile { it.isEmpty() }.toTypedArray() + elementsType = "|" + } } if (rules.size == 1) { val jxNodes = jxDocument!!.selN(xPath)