--- /dev/null
+//\r
+// This software is now distributed according to\r
+// the Lesser Gnu Public License. Please see\r
+// http://www.gnu.org/copyleft/lesser.txt for\r
+// the details.\r
+// -- Happy Computing!\r
+//\r
+package com.stevesoft.pat;\r
+import java.util.Hashtable;\r
+\r
+/** This class implements the word boundary pattern element: \b. */\r
+class Boundary extends Pattern {\r
+ public String toString() {\r
+ return "\\b"+nextString();\r
+ }\r
+ boolean isAChar(char c) {\r
+ if(c >= 'a' && c <= 'z')\r
+ return true;\r
+ if(c >= 'A' && c <= 'Z')\r
+ return true;\r
+ if(c >= '0' && c <= '9')\r
+ return true;\r
+ if(c == '_')\r
+ return true;\r
+ return false;\r
+ }\r
+ boolean matchLeft(int pos,Pthings pt) {\r
+ if(pos <= 0)\r
+ return true;\r
+ if(isAChar(pt.src.charAt(pos))\r
+ && isAChar(pt.src.charAt(pos-1)))\r
+ return false;\r
+ return true;\r
+ }\r
+ boolean matchRight(int pos,Pthings pt) {\r
+ if(pos < 0) return false;\r
+ if(pos+1 >= pt.src.length())\r
+ return true;\r
+ if(isAChar(pt.src.charAt(pos))\r
+ && isAChar(pt.src.charAt(pos+1)))\r
+ return false;\r
+ return true;\r
+ }\r
+ public int matchInternal(int pos,Pthings pt) {\r
+ if(matchRight(pos-1,pt) || matchLeft(pos,pt))\r
+ return nextMatch(pos,pt);\r
+ return -1;\r
+ }\r
+ public patInt maxChars() { return new patInt(0); }\r
+ public Pattern clone1(Hashtable h) { return new Boundary(); }\r
+};\r