001/* 002 * gnu/regexp/RETokenEnd.java 003 * Copyright (C) 1998-2001 Wes Biggs 004 * 005 * This library is free software; you can redistribute it and/or modify 006 * it under the terms of the GNU Lesser General Public License as published 007 * by the Free Software Foundation; either version 2.1 of the License, or 008 * (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public License 016 * along with this program; if not, write to the Free Software 017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 018 */ 019package gnu.regexp; 020 021final class RETokenEnd extends REToken { 022 /** 023 * Indicates whether this token should match on a line break. 024 */ 025 private String newline; 026 027 RETokenEnd(int subIndex,String newline) { 028 super(subIndex); 029 this.newline = newline; 030 } 031 032 boolean match(CharIndexed input, REMatch mymatch) { 033 char ch = input.charAt(mymatch.index); 034 if (ch == CharIndexed.OUT_OF_BOUNDS) 035 return ((mymatch.eflags & RE.REG_NOTEOL)>0) ? 036 false : next(input, mymatch); 037 if (newline != null) { 038 char z; 039 int i = 0; // position in newline 040 do { 041 z = newline.charAt(i); 042 if (ch != z) return false; 043 ++i; 044 ch = input.charAt(mymatch.index + i); 045 } while (i < newline.length()); 046 047 return next(input, mymatch); 048 } 049 return false; 050 } 051 052 void dump(StringBuffer os) { 053 os.append('$'); 054 } 055}