X-Git-Url: http://gitweb.fperrin.net/?p=DictionaryPC.git;a=blobdiff_plain;f=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2Fengine%2FWiktionarySplitter.java;h=3cee85da6a2a89743f53be952239e4aea8f87d0f;hp=28b11bc669f3cbdb146a4a41c4dc2afc802ae2a9;hb=4c7701228aff69ceb4dffd23ed319382b5f0a55c;hpb=cde823acd318d713335c4ec5ea35e708063abea5 diff --git a/src/com/hughes/android/dictionary/engine/WiktionarySplitter.java b/src/com/hughes/android/dictionary/engine/WiktionarySplitter.java index 28b11bc..3cee85d 100644 --- a/src/com/hughes/android/dictionary/engine/WiktionarySplitter.java +++ b/src/com/hughes/android/dictionary/engine/WiktionarySplitter.java @@ -199,14 +199,15 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler { String text = textBuilder.toString(); String translingual = ""; + int start = 0; + final Matcher startMatcher = headingStart.matcher(text); - while (text.length() > 0) { + while (start < text.length()) { // Find start. - final Matcher startMatcher = headingStart.matcher(text); - if (!startMatcher.find()) { + if (!startMatcher.find(start)) { return; } - text = text.substring(startMatcher.end()); + start = startMatcher.end(); final String heading = startMatcher.group(); @@ -218,10 +219,10 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler { final Pattern endPattern = getEndPattern(depth); final Matcher endMatcher = endPattern.matcher(text); - if (endMatcher.find()) { + if (endMatcher.find(start)) { int end = endMatcher.start(); - translingual = text.substring(0, endMatcher.start()); - text = text.substring(end); + translingual = text.substring(start, end); + start = end; continue; } } @@ -234,13 +235,13 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler { final Matcher endMatcher = endPattern.matcher(text); final int end; - if (endMatcher.find()) { + if (endMatcher.find(start)) { end = endMatcher.start(); } else { end = text.length(); } - String sectionText = text.substring(0, end); + String sectionText = text.substring(start, end); // Hack to remove empty dummy section from French if (sectionText.startsWith("\n=== {{S|étymologie}} ===\n: {{ébauche-étym")) { int dummy_end = sectionText.indexOf("}}", 41) + 2; @@ -262,7 +263,7 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler { throw new RuntimeException(e); } - text = text.substring(end); + start = end; break; } }