Formatting
[jalview.git] / src / com / stevesoft / pat / Custom.java
1 //\r
2 // This software is now distributed according to\r
3 // the Lesser Gnu Public License.  Please see\r
4 // http://www.gnu.org/copyleft/lesser.txt for\r
5 // the details.\r
6 //    -- Happy Computing!\r
7 //\r
8 package com.stevesoft.pat;\r
9 \r
10 import java.util.*;\r
11 \r
12 /** Simple custom patterns.  See\r
13     <a href="http://javaregex.com/code/deriv2.java.html">deriv2.java</a>\r
14     and <a href="http://javaregex.com/code/deriv3.java.html">deriv3.java</a>\r
15     in the test directory.\r
16     @see com.stevesoft.pat.CustomEndpoint\r
17  */\r
18 class Custom\r
19     extends PatternSub\r
20 {\r
21   String select;\r
22   Validator v;\r
23   int start;\r
24   Custom(String s)\r
25   {\r
26     select = s;\r
27     v = (Validator) Regex.validators.get(s);\r
28   }\r
29 \r
30   public int matchInternal(int pos, Pthings pt)\r
31   {\r
32     start = pos;\r
33     return sub.matchInternal(pos, pt);\r
34   }\r
35 \r
36   public String toString()\r
37   {\r
38     String a = v.argsave == null ? "" : ":" + v.argsave;\r
39     return "(??" + select + a + ")" + nextString();\r
40   }\r
41 \r
42   public patInt minChars()\r
43   {\r
44     return v.minChars();\r
45   }\r
46 \r
47   public patInt maxChars()\r
48   {\r
49     return v.maxChars();\r
50   }\r
51 \r
52   Pattern clone1(Hashtable h)\r
53   {\r
54     Custom c = new Custom(select);\r
55     h.put(c, c);\r
56     h.put(this, c);\r
57     c.sub = sub.clone(h);\r
58     return c;\r
59   }\r
60 }\r