PathTokenizer.java revision 1238
0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
407N/A * Common Development and Distribution License (the "License").
0N/A * You may not use this file except in compliance with the License.
0N/A *
0N/A * See LICENSE.txt included in this distribution for the specific
0N/A * language governing permissions and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
0N/A * file and include the License file at LICENSE.txt.
0N/A * If applicable, add the following below this CDDL HEADER, with the
0N/A * fields enclosed by brackets "[]" replaced with your own identifying
0N/A * information: Portions Copyright [yyyy] [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A */
0N/A
0N/A/*
928N/A * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
0N/A * Use is subject to license terms.
0N/A */
0N/Apackage org.opensolaris.opengrok.analysis;
0N/A
0N/Aimport java.io.Reader;
0N/Aimport org.apache.lucene.analysis.Tokenizer;
928N/Aimport org.apache.lucene.analysis.tokenattributes.TermAttribute;
0N/A
0N/Apublic class PathTokenizer extends Tokenizer {
394N/A
937N/A // below should be '/' since we try to convert even windows file separators to unix ones
394N/A private static final char dirSep = '/';
394N/A private boolean dot = false;
1238N/A private static final char ADOT[]={'.'};
1190N/A private final TermAttribute termAtt = addAttribute(TermAttribute.class);
394N/A
394N/A public PathTokenizer(Reader input) {
394N/A super(input);
394N/A }
394N/A
816N/A @Override
928N/A public final boolean incrementToken() throws java.io.IOException {
394N/A if (dot) {
394N/A dot = false;
928N/A termAtt.setTermBuffer(ADOT,0,1);
928N/A return true;
394N/A }
0N/A
394N/A char buf[] = new char[64];
394N/A int c;
394N/A int i = 0;
394N/A do {
394N/A c = input.read();
394N/A if (c == -1) {
928N/A return false;
394N/A }
394N/A } while (c == dirSep);
0N/A
394N/A do {
394N/A if (i >= buf.length) {
394N/A char nb[] = new char[buf.length * 2];
394N/A System.arraycopy(buf, 0, nb, 0, buf.length);
394N/A buf = nb;
394N/A }
394N/A buf[i++] = Character.toLowerCase((char) c);
394N/A c = input.read();
394N/A } while (c != dirSep && c != '.' && !Character.isWhitespace(c) && c != -1);
394N/A if (c == '.') {
394N/A dot = true;
394N/A }
1190N/A termAtt.setTermBuffer(buf, 0, i);
928N/A return true;
394N/A }
0N/A}