From 8e9416848951c3928bf38f1331c91e17aa65a80d Mon Sep 17 00:00:00 2001 From: GKF Date: Wed, 12 Dec 2018 11:17:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kunfei/bookshelf/model/analyzeRule/AnalyzeByJSoup.java | 4 ++-- .../com/kunfei/bookshelf/model/analyzeRule/AnalyzeRule.java | 6 +++--- .../main/java/com/kunfei/bookshelf/utils/StringUtils.java | 6 ++++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/kunfei/bookshelf/model/analyzeRule/AnalyzeByJSoup.java b/app/src/main/java/com/kunfei/bookshelf/model/analyzeRule/AnalyzeByJSoup.java index 7a5b6c53c2..c7bb16730f 100644 --- a/app/src/main/java/com/kunfei/bookshelf/model/analyzeRule/AnalyzeByJSoup.java +++ b/app/src/main/java/com/kunfei/bookshelf/model/analyzeRule/AnalyzeByJSoup.java @@ -2,8 +2,8 @@ import android.text.TextUtils; -import com.kunfei.bookshelf.utils.NetworkUtil; import com.kunfei.bookshelf.help.FormatWebText; +import com.kunfei.bookshelf.utils.StringUtils; import org.jsoup.nodes.Element; import org.jsoup.nodes.TextNode; @@ -409,7 +409,7 @@ class SourceRule { String replacement = ""; SourceRule(String ruleStr) { - if (ruleStr.toUpperCase().startsWith("@CSS:")) { + if (StringUtils.startWithIgnoreCase(ruleStr, "@CSS:")) { isCss = true; elementsRule = ruleStr.substring(5); return; diff --git a/app/src/main/java/com/kunfei/bookshelf/model/analyzeRule/AnalyzeRule.java b/app/src/main/java/com/kunfei/bookshelf/model/analyzeRule/AnalyzeRule.java index 20ad88df1d..5b50208154 100644 --- a/app/src/main/java/com/kunfei/bookshelf/model/analyzeRule/AnalyzeRule.java +++ b/app/src/main/java/com/kunfei/bookshelf/model/analyzeRule/AnalyzeRule.java @@ -156,13 +156,13 @@ class SourceRule { String js; SourceRule(String ruleStr) { - if (_isJSON && !ruleStr.startsWith("@JSon:")) + if (_isJSON && !StringUtils.startWithIgnoreCase(ruleStr, "@JSON:")) throw new AssertionError("Content analyze"); String str[] = ruleStr.split("@js:"); - if (str[0].startsWith("@XPath:")) { + if (StringUtils.startWithIgnoreCase(str[0], "@XPath:")) { mode = Mode.XPath; rule = str[0].substring(7); - } else if (str[0].startsWith("@JSon:")) { + } else if (StringUtils.startWithIgnoreCase(str[0], "@JSon:")) { mode = Mode.JSon; rule = str[0].substring(6); } else { diff --git a/app/src/main/java/com/kunfei/bookshelf/utils/StringUtils.java b/app/src/main/java/com/kunfei/bookshelf/utils/StringUtils.java index 6141d0b217..b005ed2ed3 100644 --- a/app/src/main/java/com/kunfei/bookshelf/utils/StringUtils.java +++ b/app/src/main/java/com/kunfei/bookshelf/utils/StringUtils.java @@ -249,4 +249,10 @@ public static boolean isJSONType(String str) { return result; } + public static boolean startWithIgnoreCase(String src, String obj) { + if (obj.length() > src.length()) { + return false; + } + return src.substring(0, obj.length()).equalsIgnoreCase(obj); + } }