1 /*
2 * This file is part of dependency-check-core.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * Copyright (c) 2013 Jeremy Long. All Rights Reserved.
17 */
18 package org.owasp.dependencycheck.data.lucene;
19
20 import java.io.Reader;
21 import org.apache.lucene.analysis.util.CharTokenizer;
22 import org.apache.lucene.util.Version;
23
24 /**
25 * Tokenizes the input breaking it into tokens when non-alpha/numeric characters are found.
26 *
27 * @author Jeremy Long
28 */
29 public class AlphaNumericTokenizer extends CharTokenizer {
30
31 /**
32 * Constructs a new AlphaNumericTokenizer.
33 *
34 * @param matchVersion the lucene version
35 * @param in the Reader
36 */
37 public AlphaNumericTokenizer(Version matchVersion, Reader in) {
38 super(matchVersion, in);
39 }
40
41 /**
42 * Constructs a new AlphaNumericTokenizer.
43 *
44 * @param matchVersion the lucene version
45 * @param factory the AttributeFactory
46 * @param in the Reader
47 */
48 public AlphaNumericTokenizer(Version matchVersion, AttributeFactory factory, Reader in) {
49 super(matchVersion, factory, in);
50 }
51
52 /**
53 * Determines if the char passed in is part of a token.
54 *
55 * @param c the char being analyzed
56 * @return true if the char is a letter or digit, otherwise false
57 */
58 @Override
59 protected boolean isTokenChar(int c) {
60 return Character.isLetter(c) || Character.isDigit(c);
61 }
62 }