1 package org.apache.lucene.analysis.util;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 /** Some commonly-used stemming functions */
21 public class StemmerUtil {
23 * Returns true if the character array starts with the suffix.
25 * @param s Input Buffer
26 * @param len length of input buffer
27 * @param prefix Prefix string to test
28 * @return true if <code>s</code> starts with <code>prefix</code>
30 public static boolean startsWith(char s[], int len, String prefix) {
31 final int prefixLen = prefix.length();
34 for (int i = 0; i < prefixLen; i++)
35 if (s[i] != prefix.charAt(i))
41 * Returns true if the character array ends with the suffix.
43 * @param s Input Buffer
44 * @param len length of input buffer
45 * @param suffix Suffix string to test
46 * @return true if <code>s</code> ends with <code>suffix</code>
48 public static boolean endsWith(char s[], int len, String suffix) {
49 final int suffixLen = suffix.length();
52 for (int i = suffixLen - 1; i >= 0; i--)
53 if (s[len -(suffixLen - i)] != suffix.charAt(i))
60 * Returns true if the character array ends with the suffix.
62 * @param s Input Buffer
63 * @param len length of input buffer
64 * @param suffix Suffix string to test
65 * @return true if <code>s</code> ends with <code>suffix</code>
67 public static boolean endsWith(char s[], int len, char suffix[]) {
68 final int suffixLen = suffix.length;
71 for (int i = suffixLen - 1; i >= 0; i--)
72 if (s[len -(suffixLen - i)] != suffix[i])
79 * Delete a character in-place
81 * @param s Input Buffer
82 * @param pos Position of character to delete
83 * @param len length of input buffer
84 * @return length of input buffer after deletion
86 public static int delete(char s[], int pos, int len) {
88 System.arraycopy(s, pos + 1, s, pos, len - pos - 1);
94 * Delete n characters in-place
96 * @param s Input Buffer
97 * @param pos Position of character to delete
98 * @param len Length of input buffer
99 * @param nChars number of characters to delete
100 * @return length of input buffer after deletion
102 public static int deleteN(char s[], int pos, int len, int nChars) {
103 // TODO: speed up, this is silly
104 for (int i = 0; i < nChars; i++)
105 len = delete(s, pos, len);