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/*
1269N/A * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A */
0N/Apackage org.opensolaris.opengrok.analysis;
0N/A
0N/Aimport java.io.Reader;
1269N/Aimport java.util.Arrays;
0N/Aimport org.apache.lucene.analysis.Tokenizer;
1318N/Aimport org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
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[]={'.'};
1318N/A private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.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;
1318N/A termAtt.copyBuffer(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) {
1269N/A buf = Arrays.copyOf(buf, buf.length * 2);
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 }
1318N/A termAtt.copyBuffer(buf, 0, i);
928N/A return true;
394N/A }
0N/A}