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 import java.util.Hashtable; 11 12 /** Implements "(?= )" and "(?! )" */ 13 class lookAhead extends Or 14 { 15 boolean reverse; 16 lookAhead(boolean b)17 lookAhead(boolean b) 18 { 19 reverse = b; 20 } 21 getNext()22 public Pattern getNext() 23 { 24 return null; 25 } 26 nextMatch(int pos, Pthings pt)27 public int nextMatch(int pos, Pthings pt) 28 { 29 Pattern p = super.getNext(); 30 if (p != null) 31 { 32 return p.matchInternal(pos, pt); 33 } 34 else 35 { 36 return pos; 37 } 38 } 39 matchInternal(int pos, Pthings pt)40 public int matchInternal(int pos, Pthings pt) 41 { 42 if (super.matchInternal(pos, pt) >= 0) 43 { 44 if (reverse) 45 { 46 return -1; 47 } 48 else 49 { 50 return nextMatch(pos, pt); 51 } 52 } 53 else 54 { 55 if (reverse) 56 { 57 return nextMatch(pos, pt); 58 } 59 else 60 { 61 return -1; 62 } 63 } 64 } 65 leftForm()66 String leftForm() 67 { 68 if (reverse) 69 { 70 return "(?!"; 71 } 72 else 73 { 74 return "(?="; 75 } 76 } 77 minChars()78 public patInt minChars() 79 { 80 return new patInt(0); 81 } 82 maxChars()83 public patInt maxChars() 84 { 85 return new patInt(0); 86 } 87 clone1(Hashtable h)88 Pattern clone1(Hashtable h) 89 { 90 lookAhead la = new lookAhead(reverse); 91 h.put(this, la); 92 h.put(la, la); 93 for (int i = 0; i < v.size(); i++) 94 { 95 la.v.addElement(((Pattern) v.elementAt(i)).clone(h)); 96 } 97 return la; 98 } 99 } 100