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
6 // -- Happy Computing!
\r
8 package com.stevesoft.pat;
\r
9 import java.util.Hashtable;
\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
16 boolean isAChar(char c) {
\r
17 if(c >= 'a' && c <= 'z')
\r
19 if(c >= 'A' && c <= 'Z')
\r
21 if(c >= '0' && c <= '9')
\r
27 boolean matchLeft(int pos,Pthings pt) {
\r
30 if(isAChar(pt.src.charAt(pos))
\r
31 && isAChar(pt.src.charAt(pos-1)))
\r
35 boolean matchRight(int pos,Pthings pt) {
\r
36 if(pos < 0) return false;
\r
37 if(pos+1 >= pt.src.length())
\r
39 if(isAChar(pt.src.charAt(pos))
\r
40 && isAChar(pt.src.charAt(pos+1)))
\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
49 public patInt maxChars() { return new patInt(0); }
\r
50 public Pattern clone1(Hashtable h) { return new Boundary(); }
\r