JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / unused / com / stevesoft / pat / End.java
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.*;
11
12 //class AddToEnd extends RegSyntax {};
13
14 /**
15  * Compiles the '$' or the '\Z' Pattern. It is an error to have further Pattern
16  * elements after '\Z'. It is the end of the String.
17  */
18 class End extends Pattern
19 {
20   boolean retIsEnd;
21
22   End(boolean b)
23   {
24     retIsEnd = b;
25   }
26
27   public int matchInternal(int pos, Pthings pt)
28   {
29     if (retIsEnd && pt.mFlag && pos < pt.src.length())
30     {
31       if (pt.src.charAt(pos) == '\n')
32       {
33         return nextMatch(pos, pt);
34       }
35     }
36     if (pt.src.length() == pos)
37     {
38       return nextMatch(pos, pt);
39     }
40     else if (pos < pt.src.length())
41     {
42       // Access the next character...
43       // this is crucial to making
44       // RegexReader work.
45       pt.src.charAt(pos);
46     }
47     return -1;
48   }
49
50   public String toString()
51   {
52     if (retIsEnd)
53     {
54       return "$";
55     }
56     else
57     {
58       return "\\Z";
59     }
60   }
61
62   public patInt maxChars()
63   {
64     return new patInt(1);
65   }
66
67   public Pattern clone1(Hashtable h)
68   {
69     return new End(retIsEnd);
70   }
71 };