X-Git-Url: http://gitweb.fperrin.net/?p=DictionaryPC.git;a=blobdiff_plain;f=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2Fengine%2FWiktionarySplitter.java;h=c1cb09feee66380514a1de7a4aca2a933855e2a6;hp=850dedee2018c7fcf2ea4bb558edefdfb27551a7;hb=5ce5941fa2f306dab71d74db377235c685b70a74;hpb=b60bc4096cf591206cc7ad2e235b88030a9ee65f diff --git a/src/com/hughes/android/dictionary/engine/WiktionarySplitter.java b/src/com/hughes/android/dictionary/engine/WiktionarySplitter.java index 850dede..c1cb09f 100644 --- a/src/com/hughes/android/dictionary/engine/WiktionarySplitter.java +++ b/src/com/hughes/android/dictionary/engine/WiktionarySplitter.java @@ -114,6 +114,14 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler { String lastPageTitle = null; int pageCount = 0; + Pattern endPatterns[] = new Pattern[100]; + + private Pattern getEndPattern(int depth) { + if (endPatterns[depth] == null) + endPatterns[depth] = Pattern.compile(String.format("^={1,%d}[^=].*$", depth), Pattern.MULTILINE); + return endPatterns[depth]; + } + private void endPage() { final String title = titleBuilder.toString(); lastPageTitle = title; @@ -200,7 +208,7 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler { if (heading.indexOf("Translingual") != -1) { // Find end. final int depth = startMatcher.group(1).length(); - final Pattern endPattern = Pattern.compile(String.format("^={1,%d}[^=].*$", depth), Pattern.MULTILINE); + final Pattern endPattern = getEndPattern(depth); final Matcher endMatcher = endPattern.matcher(text); if (endMatcher.find()) { @@ -214,7 +222,7 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler { // Find end. final int depth = startMatcher.group(1).length(); - final Pattern endPattern = Pattern.compile(String.format("^={1,%d}[^=].*$", depth), Pattern.MULTILINE); + final Pattern endPattern = getEndPattern(depth); final Matcher endMatcher = endPattern.matcher(text); final int end;