JAL-1807 still testing
[jalviewjs.git] / unused / com / stevesoft / pat / Multi.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 /**\r
13  * Matches any number of instances of sub Pattern this was the hardest method to\r
14  * write. It implements '+', '*', '?', "{0,10}", "{5,}", "{5}", etc.\r
15  * \r
16  * @see pat.Multi_stage2\r
17  * @see pat.MultiMin\r
18  */\r
19 class Multi extends PatternSub\r
20 {\r
21   patInt a, b;\r
22 \r
23   public patInt minChars()\r
24   {\r
25     return a.mul(p.countMinChars());\r
26   }\r
27 \r
28   public patInt maxChars()\r
29   {\r
30     return b.mul(p.countMaxChars());\r
31   }\r
32 \r
33   Pattern p;\r
34 \r
35   Multi_stage2 st2;\r
36 \r
37   public boolean matchFewest = false;\r
38 \r
39   /**\r
40    * @param a\r
41    *                The fewest number of times the sub pattern can match.\r
42    * @param b\r
43    *                The maximum number of times the sub pattern can match.\r
44    * @param p\r
45    *                The sub pattern.\r
46    * @see Multi_stage2\r
47    * @see MultiMin\r
48    */\r
49   public Multi(patInt a, patInt b, Pattern p) throws RegSyntax\r
50   {\r
51     this.a = a;\r
52     this.b = b;\r
53     this.p = p;\r
54     st2 = new Multi_stage2(a, b, p);\r
55     st2.parent = this;\r
56     sub = st2.sub;\r
57   }\r
58 \r
59   public String toString()\r
60   {\r
61     st2.matchFewest = matchFewest;\r
62     return st2.toString();\r
63   }\r
64 \r
65   public int matchInternal(int pos, Pthings pt)\r
66   {\r
67     try\r
68     {\r
69       st2 = new Multi_stage2(a, b, p);\r
70     } catch (RegSyntax r__)\r
71     {\r
72     }\r
73     st2.matchFewest = matchFewest;\r
74     st2.parent = this;\r
75     return st2.matchInternal(pos, pt);\r
76   }\r
77 \r
78   public Pattern clone1(Hashtable h)\r
79   {\r
80     try\r
81     {\r
82       Multi m = new Multi(a, b, ((Pattern) p).clone(h));\r
83       m.matchFewest = matchFewest;\r
84       return m;\r
85     } catch (RegSyntax rs)\r
86     {\r
87       return null;\r
88     }\r
89   }\r
90 };\r