Mercurial > hg > Members > nobuyasu > TestNeo4j
view src/howtouse/CharReader.java @ 9:d655c8fef734 draft
fix WikiLinkParser.java
author | one |
---|---|
date | Wed, 22 Aug 2012 01:58:54 +0900 |
parents | d8d0855bcdfd |
children | bf7863a55cd6 |
line wrap: on
line source
package howtouse; public class CharReader { final static char EOFchar = (char) 0; private String text; private int textLength; private int index; private final char LBRANK = '['; private final char RBRANK = ']'; private final char VERBAR = '|'; private final static int LETTER = 1; private final static int[] charKindT = new int[0x10000]; static { for (int i = 0; i < 'A'; i++) charKindT[i] = 0; for (int i = 'A'; i <= 'Z'; i++) charKindT[i] = LETTER; } CharReader() { } public void setText(String str) { text = str; textLength = text.length(); index = 0; } char nextChar() { if (index < textLength) return text.charAt(index++); return EOFchar; } String getToken() { int nextState = 1; StringBuffer buf = new StringBuffer(256); char ch; int index = -1; while (true) { ch = nextChar(); if (ch == EOFchar) return null; switch (nextState) { case 1: if (ch == LBRANK) nextState = 2; break; case 2: if (ch == LBRANK) nextState = 3; else nextState = 1; break; case 3: if (ch == RBRANK) { nextState = 4; } else if (ch == VERBAR) { index = buf.length(); buf.append(ch); } else { buf.append(ch); } break; case 4: if (ch == RBRANK) { if (index == -1) { return buf.toString(); } else{ return buf.substring(0,index); } } else { return null; } } } } }