Jsoup parse from file to reduce memory usage

This commit is contained in:
M66B
2020-02-20 10:07:01 +01:00
parent 48a5278ba0
commit 873a696a52
6 changed files with 50 additions and 13 deletions

View File

@@ -64,6 +64,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -1249,6 +1250,36 @@ public class HtmlHelper {
return (length >= max);
}
static boolean contains(Document d, String[] texts) {
Map<String, Boolean> condition = new HashMap<>();
for (String t : texts)
condition.put(t, false);
for (Element elm : d.select("*"))
for (Node child : elm.childNodes()) {
if (child instanceof TextNode) {
TextNode tnode = ((TextNode) child);
String text = tnode.getWholeText();
for (String t : texts)
if (!condition.get(t) && text.contains(t)) {
condition.put(t, true);
boolean found = true;
for (String c : texts)
if (!condition.get(c)) {
found = false;
break;
}
if (found)
return true;
}
}
}
return false;
}
static Spanned fromHtml(@NonNull String html) {
return fromHtml(html, null, null);
}