001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.commons.text.matcher; 019 020/** 021 * Determines if a character array portion matches. 022 * 023 * @since 1.3 024 */ 025public interface StringMatcher { 026 027 /** 028 * Returns the number of matching characters, zero for no match. 029 * <p> 030 * This method is called to check for a match. The parameter <code>pos</code> represents the current position to be 031 * checked in the string <code>buffer</code> (a character array which must not be changed). The API guarantees that 032 * <code>pos</code> is a valid index for <code>buffer</code>. 033 * <p> 034 * The character array may be larger than the active area to be matched. Only values in the buffer between the 035 * specified indices may be accessed. 036 * <p> 037 * The matching code may check one character or many. It may check characters preceding <code>pos</code> as well as 038 * those after, so long as no checks exceed the bounds specified. 039 * <p> 040 * It must return zero for no match, or a positive number if a match was found. The number indicates the number of 041 * characters that matched. 042 * 043 * @param buffer 044 * the text content to match against, do not change 045 * @param pos 046 * the starting position for the match, valid for buffer 047 * @param bufferStart 048 * the first active index in the buffer, valid for buffer 049 * @param bufferEnd 050 * the end index (exclusive) of the active buffer, valid for buffer 051 * @return the number of matching characters, or zero if there is no match 052 */ 053 int isMatch(char[] buffer, int pos, int bufferStart, int bufferEnd); 054 055}