needed for applet search
[jalview.git] / src / com / stevesoft / pat / Boundary.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 import java.util.Hashtable;\r
10 \r
11 /** This class implements the word boundary pattern element: \b. */\r
12 class Boundary extends Pattern {\r
13     public String toString() {\r
14         return "\\b"+nextString();\r
15     }\r
16     boolean isAChar(char c) {\r
17         if(c >= 'a' && c <= 'z')\r
18             return true;\r
19         if(c >= 'A' && c <= 'Z')\r
20             return true;\r
21         if(c >= '0' && c <= '9')\r
22             return true;\r
23         if(c == '_')\r
24             return true;\r
25         return false;\r
26     }\r
27     boolean matchLeft(int pos,Pthings pt) {\r
28         if(pos <= 0)\r
29             return true;\r
30         if(isAChar(pt.src.charAt(pos))\r
31                 && isAChar(pt.src.charAt(pos-1)))\r
32             return false;\r
33         return true;\r
34     }\r
35     boolean matchRight(int pos,Pthings pt) {\r
36         if(pos < 0) return false;\r
37         if(pos+1 >= pt.src.length())\r
38             return true;\r
39         if(isAChar(pt.src.charAt(pos))\r
40                 && isAChar(pt.src.charAt(pos+1)))\r
41             return false;\r
42         return true;\r
43     }\r
44     public int matchInternal(int pos,Pthings pt) {\r
45         if(matchRight(pos-1,pt) || matchLeft(pos,pt))\r
46             return nextMatch(pos,pt);\r
47         return -1;\r
48     }\r
49     public patInt maxChars() { return new patInt(0); }\r
50     public Pattern clone1(Hashtable h) { return new Boundary(); }\r
51 };\r