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 /** The '^' or the '\A' Pattern, matches the start of a string. */ 13 class Start extends Pattern 14 { 15 boolean retIsStart; 16 Start(boolean b)17 Start(boolean b) 18 { 19 retIsStart = b; 20 } 21 matchInternal(int pos, Pthings pt)22 public int matchInternal(int pos, Pthings pt) 23 { 24 if (retIsStart && pt.mFlag && pos > 0 && pt.src.charAt(pos - 1) == '\n') 25 { 26 return nextMatch(pos, pt); 27 } 28 if (pos == 0) 29 { 30 return nextMatch(pos, pt); 31 } 32 return -1; 33 } 34 toString()35 public String toString() 36 { 37 if (retIsStart) 38 { 39 return "^" + nextString(); 40 } 41 else 42 { 43 return "\\A" + nextString(); 44 } 45 } 46 maxChars()47 public patInt maxChars() 48 { 49 return new patInt(0); 50 } 51 clone1(Hashtable h)52 Pattern clone1(Hashtable h) 53 { 54 return new Start(retIsStart); 55 } 56 }; 57