-//\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
-\r
-import java.util.*;\r
-\r
-/** A special optimization of multi that is used when the\r
- * common subpattern ".*" is encountered.\r
- */\r
-class DotMulti\r
- extends PatternSub\r
-{\r
- patInt fewestMatches, mostMatches;\r
- public patInt minChars()\r
- {\r
- return fewestMatches;\r
- }\r
-\r
- public patInt maxChars()\r
- {\r
- return mostMatches;\r
- }\r
-\r
- public boolean matchFewest = false;\r
-\r
- StringLike src = null;\r
- int srclength = 0;\r
- boolean dotDoesntMatchCR = true;\r
- DotMulti(patInt a, patInt b)\r
- {\r
- fewestMatches = a;\r
- mostMatches = b;\r
- }\r
-\r
- public String toString()\r
- {\r
- return ".{"\r
- + fewestMatches + "," + mostMatches + "}" +\r
- (matchFewest ? "?" : "") + "(?# <= dot multi)" +\r
- nextString();\r
- }\r
-\r
- final int submatchInternal(int pos, Pthings pt)\r
- {\r
- if (pos < srclength)\r
- {\r
- if (dotDoesntMatchCR)\r
- {\r
- if (src.charAt(pos) != '\n')\r
- {\r
- return 1 + pos;\r
- }\r
- }\r
- else\r
- {\r
- return 1 + pos;\r
- }\r
- }\r
- return -1;\r
- }\r
-\r
- final static int step = 1;\r
- static int idcount = 1;\r
- public int matchInternal(int pos, Pthings pt)\r
- {\r
- int m = -1;\r
- int i = pos;\r
- src = pt.src;\r
- srclength = src.length();\r
- dotDoesntMatchCR = pt.dotDoesntMatchCR;\r
- if (matchFewest)\r
- {\r
- int nMatches = 0;\r
- while (fewestMatches.intValue() > nMatches)\r
- {\r
- i = submatchInternal(i, pt);\r
- if (i < 0)\r
- {\r
- return -1;\r
- }\r
- nMatches++;\r
- }\r
- if (i < 0)\r
- {\r
- return -1;\r
- }\r
- int ii = nextMatch(i, pt);\r
- if (ii >= 0)\r
- {\r
- return ii;\r
- }\r
- if (!mostMatches.finite())\r
- {\r
- while (i >= 0)\r
- {\r
- i = submatchInternal(i, pt);\r
- if (i < 0)\r
- {\r
- return -1;\r
- }\r
- ii = nextMatch(i, pt);\r
- if (ii >= 0)\r
- {\r
- return ii;\r
- }\r
- }\r
- }\r
- else\r
- {\r
- while (i > 0)\r
- {\r
- i = submatchInternal(i, pt);\r
- if (i < 0)\r
- {\r
- return -1;\r
- }\r
- nMatches++;\r
- if (nMatches > mostMatches.intValue())\r
- {\r
- return -1;\r
- }\r
- ii = nextMatch(i, pt);\r
- if (ii >= 0)\r
- {\r
- return ii;\r
- }\r
- }\r
- }\r
- return -1;\r
- }\r
- int nMatches = 0;\r
- while (fewestMatches.intValue() > nMatches)\r
- {\r
- i = submatchInternal(i, pt);\r
- if (i >= 0)\r
- {\r
- nMatches++;\r
- }\r
- else\r
- {\r
- return -1;\r
- }\r
- }\r
- m = i;\r
- if (mostMatches.finite())\r
- {\r
- while (nMatches < mostMatches.intValue())\r
- {\r
- i = submatchInternal(i, pt);\r
- if (i >= 0)\r
- {\r
- m = i;\r
- nMatches++;\r
- }\r
- else\r
- {\r
- break;\r
- }\r
- }\r
- }\r
- else\r
- {\r
- while (true)\r
- {\r
- i = submatchInternal(i, pt);\r
- if (i >= 0)\r
- {\r
- m = i;\r
- nMatches++;\r
- }\r
- else\r
- {\r
- break;\r
- }\r
- }\r
- }\r
- while (m >= pos)\r
- {\r
- int r = nextMatch(m, pt);\r
- if (r >= 0)\r
- {\r
- return r;\r
- }\r
- m -= step;\r
- nMatches--;\r
- if (nMatches < fewestMatches.intValue())\r
- {\r
- return -1;\r
- }\r
- }\r
- return -1;\r
- }\r
-\r
- Pattern clone1(Hashtable h)\r
- {\r
- DotMulti dm = new DotMulti(fewestMatches, mostMatches);\r
- dm.matchFewest = matchFewest;\r
- return dm;\r
- }\r
-}\r
+//
+// This software is now distributed according to
+// the Lesser Gnu Public License. Please see
+// http://www.gnu.org/copyleft/lesser.txt for
+// the details.
+// -- Happy Computing!
+//
+package com.stevesoft.pat;
+
+import java.util.Hashtable;
+
+/**
+ * A special optimization of multi that is used when the common subpattern ".*"
+ * is encountered.
+ */
+class DotMulti extends PatternSub
+{
+ patInt fewestMatches, mostMatches;
+
+ public patInt minChars()
+ {
+ return fewestMatches;
+ }
+
+ public patInt maxChars()
+ {
+ return mostMatches;
+ }
+
+ public boolean matchFewest = false;
+
+ StringLike src = null;
+
+ int srclength = 0;
+
+ boolean dotDoesntMatchCR = true;
+
+ DotMulti(patInt a, patInt b)
+ {
+ fewestMatches = a;
+ mostMatches = b;
+ }
+
+ public String toString()
+ {
+ return ".{" + fewestMatches + "," + mostMatches + "}"
+ + (matchFewest ? "?" : "") + "(?# <= dot multi)" + nextString();
+ }
+
+ final int submatchInternal(int pos, Pthings pt)
+ {
+ if (pos < srclength)
+ {
+ if (dotDoesntMatchCR)
+ {
+ if (src.charAt(pos) != '\n')
+ {
+ return 1 + pos;
+ }
+ }
+ else
+ {
+ return 1 + pos;
+ }
+ }
+ return -1;
+ }
+
+ final static int step = 1;
+
+ static int idcount = 1;
+
+ public int matchInternal(int pos, Pthings pt)
+ {
+ int m = -1;
+ int i = pos;
+ src = pt.src;
+ srclength = src.length();
+ dotDoesntMatchCR = pt.dotDoesntMatchCR;
+ if (matchFewest)
+ {
+ int nMatches = 0;
+ while (fewestMatches.intValue() > nMatches)
+ {
+ i = submatchInternal(i, pt);
+ if (i < 0)
+ {
+ return -1;
+ }
+ nMatches++;
+ }
+ if (i < 0)
+ {
+ return -1;
+ }
+ int ii = nextMatch(i, pt);
+ if (ii >= 0)
+ {
+ return ii;
+ }
+ if (!mostMatches.finite())
+ {
+ while (i >= 0)
+ {
+ i = submatchInternal(i, pt);
+ if (i < 0)
+ {
+ return -1;
+ }
+ ii = nextMatch(i, pt);
+ if (ii >= 0)
+ {
+ return ii;
+ }
+ }
+ }
+ else
+ {
+ while (i > 0)
+ {
+ i = submatchInternal(i, pt);
+ if (i < 0)
+ {
+ return -1;
+ }
+ nMatches++;
+ if (nMatches > mostMatches.intValue())
+ {
+ return -1;
+ }
+ ii = nextMatch(i, pt);
+ if (ii >= 0)
+ {
+ return ii;
+ }
+ }
+ }
+ return -1;
+ }
+ int nMatches = 0;
+ while (fewestMatches.intValue() > nMatches)
+ {
+ i = submatchInternal(i, pt);
+ if (i >= 0)
+ {
+ nMatches++;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+ m = i;
+ if (mostMatches.finite())
+ {
+ while (nMatches < mostMatches.intValue())
+ {
+ i = submatchInternal(i, pt);
+ if (i >= 0)
+ {
+ m = i;
+ nMatches++;
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+ else
+ {
+ while (true)
+ {
+ i = submatchInternal(i, pt);
+ if (i >= 0)
+ {
+ m = i;
+ nMatches++;
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+ while (m >= pos)
+ {
+ int r = nextMatch(m, pt);
+ if (r >= 0)
+ {
+ return r;
+ }
+ m -= step;
+ nMatches--;
+ if (nMatches < fewestMatches.intValue())
+ {
+ return -1;
+ }
+ }
+ return -1;
+ }
+
+ Pattern clone1(Hashtable h)
+ {
+ DotMulti dm = new DotMulti(fewestMatches, mostMatches);
+ dm.matchFewest = matchFewest;
+ return dm;
+ }
+}