X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2Fparser%2FWikiTokenizer.java;h=47aac9488de54449f81399f33b29f3e264f55ac7;hb=794c2989d4ff4c456c9aa1066150c6d51a5aae84;hp=fffe35788ad18d7e9a62427a34bb45ff911c2743;hpb=50408cbdec646b586a7c54d0d0d86e807d6c9657;p=DictionaryPC.git diff --git a/src/com/hughes/android/dictionary/parser/WikiTokenizer.java b/src/com/hughes/android/dictionary/parser/WikiTokenizer.java index fffe357..47aac94 100644 --- a/src/com/hughes/android/dictionary/parser/WikiTokenizer.java +++ b/src/com/hughes/android/dictionary/parser/WikiTokenizer.java @@ -1,3 +1,17 @@ +// Copyright 2011 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package com.hughes.android.dictionary.parser; import java.util.ArrayList; @@ -8,7 +22,19 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public final class WikiTokenizer { - + + public static interface Callback { + void onPlainText(final String text); + void onMarkup(WikiTokenizer wikiTokenizer); + void onWikiLink(WikiTokenizer wikiTokenizer); + void onNewline(WikiTokenizer wikiTokenizer); + void onFunction(final WikiTokenizer tokenizer, String functionName, List functionPositionArgs, + Map functionNamedArgs); + void onHeading(WikiTokenizer wikiTokenizer); + void onListItem(WikiTokenizer wikiTokenizer); + void onComment(WikiTokenizer wikiTokenizer); + } + //private static final Pattern wikiTokenEvent = Pattern.compile("($)", Pattern.MULTILINE); private static final Pattern wikiTokenEvent = Pattern.compile("(" + "\\{\\{|\\}\\}|" + @@ -50,10 +76,15 @@ public final class WikiTokenizer { public WikiTokenizer(final String wikiText) { + this(wikiText, true); + } + + public WikiTokenizer(final String wikiText, final boolean isNewline) { this.wikiText = wikiText; this.matcher = wikiTokenEvent.matcher(wikiText); + justReturnedNewline = isNewline; } - + private void clear() { errors.clear(); tokenStack.clear(); @@ -73,6 +104,44 @@ public final class WikiTokenizer { positionArgs.clear(); namedArgs.clear(); } + + private static final Pattern POSSIBLE_WIKI_TEXT = Pattern.compile( + "\\{\\{|" + + "\\[\\[|" + + "