1 // 2 // This software is now distributed according to 3 // the Lesser Gnu Public License. Please see 4 // http://www.gnu.org/copyleft/lesser.txt for 5 // the details. 6 // -- Happy Computing! 7 // 8 package com.stevesoft.pat; 9 10 /** 11 * This is the same as Skip, except it needs a minimum of two characters in the 12 * initializing String. 13 * 14 * @see com.stevesoft.pat.Skip 15 * @see com.stevesoft.pat.SkipBMH 16 */ 17 public class Skip2 extends Skip 18 { 19 int c1, mask1; 20 Skip2(String s, boolean ign, int offset)21 public Skip2(String s, boolean ign, int offset) 22 { 23 super(s, ign, offset); 24 c1 = s.charAt(1); 25 m1 = 2 == s.length(); 26 if (ign) 27 { 28 mask1 = mkmask(c1); 29 } 30 else 31 { 32 mask1 = 0; 33 } 34 } 35 find(StringLike s, int start, int end)36 public int find(StringLike s, int start, int end) 37 { 38 if (start > end) 39 { 40 return -1; 41 } 42 start += offset; 43 int vend = min(s.length() - 2, end + offset); 44 for (int i = start; i <= vend; i++) 45 { 46 if (0 == (s.charAt(i) & mask) && 0 == (s.charAt(i + 1) & mask1)) 47 { 48 // if(m1||s.regionMatches(ign,i,src,0,src.length()) ) 49 if (m1 || CaseMgr.regionMatches(s, ign, i, src, 0, src.length())) 50 { 51 return i - offset; 52 } 53 } 54 } 55 return -1; 56 } 57 } 58