JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / src / com / stevesoft / pat / Custom.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 /**
13  * Simple custom patterns. See <a
14  * href="http://javaregex.com/code/deriv2.java.html">deriv2.java</a> and <a
15  * href="http://javaregex.com/code/deriv3.java.html">deriv3.java</a> in the
16  * test directory.
17  * 
18  * @see com.stevesoft.pat.CustomEndpoint
19  */
20 class Custom extends PatternSub
21 {
22   String select;
23
24   Validator v;
25
26   int start;
27
28   Custom(String s)
29   {
30     select = s;
31     v = (Validator) Regex.validators.get(s);
32   }
33
34   public int matchInternal(int pos, Pthings pt)
35   {
36     start = pos;
37     return sub.matchInternal(pos, pt);
38   }
39
40   public String toString()
41   {
42     String a = v.argsave == null ? "" : ":" + v.argsave;
43     return "(??" + select + a + ")" + nextString();
44   }
45
46   public patInt minChars()
47   {
48     return v.minChars();
49   }
50
51   public patInt maxChars()
52   {
53     return v.maxChars();
54   }
55
56   Pattern clone1(Hashtable h)
57   {
58     Custom c = new Custom(select);
59     h.put(c, c);
60     h.put(this, c);
61     c.sub = sub.clone(h);
62     return c;
63   }
64 }