JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / src / com / stevesoft / pat / Backup.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  * Implements the (?<number) Pattern, where number is an integer telling us
14  * how far to back up in the Pattern. Not in perl 5. It also allows
15  * (?>number).
16  */
17 class Backup extends Pattern
18 {
19   int bk;
20
21   Backup(int ii)
22   {
23     bk = ii;
24   }
25
26   public String toString()
27   {
28     return "(?" + (bk < 0 ? ">" + (-bk) : "<" + bk) + ")" + nextString();
29   }
30
31   public int matchInternal(int pos, Pthings pt)
32   {
33     if (pos < bk)
34     {
35       return -1;
36     }
37     return nextMatch(pos - bk, pt);
38   }
39
40   public patInt minChars()
41   {
42     return new patInt(-bk);
43   }
44
45   public patInt maxChars()
46   {
47     return new patInt(-bk);
48   }
49
50   public Pattern clone1(Hashtable h)
51   {
52     return new Backup(bk);
53   }
54 };