JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / unused / com / stevesoft / pat / Boundary.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 /** This class implements the word boundary pattern element: \b. */
13 class Boundary extends Pattern
14 {
15   public String toString()
16   {
17     return "\\b" + nextString();
18   }
19
20   boolean isAChar(char c)
21   {
22     if (c >= 'a' && c <= 'z')
23     {
24       return true;
25     }
26     if (c >= 'A' && c <= 'Z')
27     {
28       return true;
29     }
30     if (c >= '0' && c <= '9')
31     {
32       return true;
33     }
34     if (c == '_')
35     {
36       return true;
37     }
38     return false;
39   }
40
41   boolean matchLeft(int pos, Pthings pt)
42   {
43     if (pos <= 0)
44     {
45       return true;
46     }
47     if (isAChar(pt.src.charAt(pos)) && isAChar(pt.src.charAt(pos - 1)))
48     {
49       return false;
50     }
51     return true;
52   }
53
54   boolean matchRight(int pos, Pthings pt)
55   {
56     if (pos < 0)
57     {
58       return false;
59     }
60     if (pos + 1 >= pt.src.length())
61     {
62       return true;
63     }
64     if (isAChar(pt.src.charAt(pos)) && isAChar(pt.src.charAt(pos + 1)))
65     {
66       return false;
67     }
68     return true;
69   }
70
71   public int matchInternal(int pos, Pthings pt)
72   {
73     if (matchRight(pos - 1, pt) || matchLeft(pos, pt))
74     {
75       return nextMatch(pos, pt);
76     }
77     return -1;
78   }
79
80   public patInt maxChars()
81   {
82     return new patInt(0);
83   }
84
85   public Pattern clone1(Hashtable h)
86   {
87     return new Boundary();
88   }
89 };