| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
package com.stevesoft.pat; |
| 9 |
|
|
| 10 |
|
import java.util.Hashtable; |
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| |
|
| 0% |
Uncovered Elements: 108 (108) |
Complexity: 27 |
Complexity Density: 0.42 |
|
| 17 |
|
class FastMulti extends PatternSub |
| 18 |
|
{ |
| 19 |
|
patInt fewestMatches, mostMatches; |
| 20 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 21 |
0 |
public patInt minChars()... |
| 22 |
|
{ |
| 23 |
0 |
return sub.countMinChars().mul(fewestMatches); |
| 24 |
|
} |
| 25 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 26 |
0 |
public patInt maxChars()... |
| 27 |
|
{ |
| 28 |
0 |
return sub.countMaxChars().mul(mostMatches); |
| 29 |
|
} |
| 30 |
|
|
| 31 |
|
public boolean matchFewest = false; |
| 32 |
|
|
| |
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 33 |
0 |
FastMulti(patInt a, patInt b, Pattern p) throws RegSyntax... |
| 34 |
|
{ |
| 35 |
0 |
if (p == null) |
| 36 |
|
{ |
| 37 |
0 |
RegSyntaxError.endItAll( |
| 38 |
|
"Null length pattern " + "followed by *, +, or other Multi."); |
| 39 |
|
} |
| 40 |
0 |
fewestMatches = a; |
| 41 |
0 |
mostMatches = b; |
| 42 |
0 |
sub = p; |
| 43 |
0 |
step = p.countMinChars().intValue(); |
| 44 |
0 |
sub.setParent(null); |
| 45 |
|
} |
| 46 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 47 |
0 |
public String toString()... |
| 48 |
|
{ |
| 49 |
0 |
return sub.toString() + "{" + fewestMatches + "," + mostMatches + "}" |
| 50 |
0 |
+ (matchFewest ? "?" : "") + "(?# <= fast multi)" |
| 51 |
|
+ nextString(); |
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
int step = -1; |
| 55 |
|
|
| |
|
| 0% |
Uncovered Elements: 83 (83) |
Complexity: 19 |
Complexity Density: 0.39 |
|
| 56 |
0 |
public int matchInternal(int pos, Pthings pt)... |
| 57 |
|
{ |
| 58 |
0 |
int m = -1; |
| 59 |
0 |
int i = pos; |
| 60 |
0 |
int endstr = pt.src.length() - step; |
| 61 |
0 |
patInt matches = new patInt(0); |
| 62 |
0 |
if (matchFewest) |
| 63 |
|
{ |
| 64 |
0 |
if (fewestMatches.lessEq(matches)) |
| 65 |
|
{ |
| 66 |
0 |
int ii = nextMatch(i, pt); |
| 67 |
0 |
if (ii >= 0) |
| 68 |
|
{ |
| 69 |
0 |
return ii; |
| 70 |
|
} |
| 71 |
|
} |
| 72 |
0 |
while (i >= 0 && i <= endstr) |
| 73 |
|
{ |
| 74 |
0 |
i = sub.matchInternal(i, pt); |
| 75 |
0 |
if (i >= 0) |
| 76 |
|
{ |
| 77 |
0 |
matches.inc(); |
| 78 |
0 |
if (fewestMatches.lessEq(matches)) |
| 79 |
|
{ |
| 80 |
0 |
int ii = nextMatch(i, pt); |
| 81 |
0 |
if (ii >= 0) |
| 82 |
|
{ |
| 83 |
0 |
return ii; |
| 84 |
|
} |
| 85 |
|
} |
| 86 |
0 |
if (matches.equals(mostMatches)) |
| 87 |
|
{ |
| 88 |
0 |
return -1; |
| 89 |
|
} |
| 90 |
|
} |
| 91 |
|
} |
| 92 |
0 |
return -1; |
| 93 |
|
} |
| 94 |
0 |
int nMatches = 0; |
| 95 |
0 |
while (fewestMatches.intValue() > nMatches) |
| 96 |
|
{ |
| 97 |
0 |
i = sub.matchInternal(i, pt); |
| 98 |
0 |
if (i >= 0) |
| 99 |
|
{ |
| 100 |
0 |
nMatches++; |
| 101 |
|
} |
| 102 |
|
else |
| 103 |
|
{ |
| 104 |
0 |
return -1; |
| 105 |
|
} |
| 106 |
|
} |
| 107 |
0 |
m = i; |
| 108 |
0 |
if (mostMatches.finite()) |
| 109 |
|
{ |
| 110 |
0 |
while (nMatches < mostMatches.intValue()) |
| 111 |
|
{ |
| 112 |
0 |
i = sub.matchInternal(i, pt); |
| 113 |
0 |
if (i >= 0) |
| 114 |
|
{ |
| 115 |
0 |
m = i; |
| 116 |
0 |
nMatches++; |
| 117 |
|
} |
| 118 |
|
else |
| 119 |
|
{ |
| 120 |
0 |
break; |
| 121 |
|
} |
| 122 |
|
} |
| 123 |
|
} |
| 124 |
|
else |
| 125 |
|
{ |
| 126 |
0 |
while (true) |
| 127 |
|
{ |
| 128 |
0 |
i = sub.matchInternal(i, pt); |
| 129 |
0 |
if (i >= 0) |
| 130 |
|
{ |
| 131 |
0 |
m = i; |
| 132 |
0 |
nMatches++; |
| 133 |
|
} |
| 134 |
|
else |
| 135 |
|
{ |
| 136 |
0 |
break; |
| 137 |
|
} |
| 138 |
|
} |
| 139 |
|
} |
| 140 |
0 |
while (m >= pos) |
| 141 |
|
{ |
| 142 |
0 |
int r = nextMatch(m, pt); |
| 143 |
0 |
if (r >= 0) |
| 144 |
|
{ |
| 145 |
0 |
return r; |
| 146 |
|
} |
| 147 |
0 |
m -= step; |
| 148 |
0 |
nMatches--; |
| 149 |
0 |
if (nMatches < fewestMatches.intValue()) |
| 150 |
|
{ |
| 151 |
0 |
return -1; |
| 152 |
|
} |
| 153 |
|
} |
| 154 |
0 |
return -1; |
| 155 |
|
} |
| 156 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 157 |
0 |
public Pattern clone1(Hashtable h)... |
| 158 |
|
{ |
| 159 |
0 |
try |
| 160 |
|
{ |
| 161 |
0 |
FastMulti fm = new FastMulti(fewestMatches, mostMatches, |
| 162 |
|
sub.clone(h)); |
| 163 |
0 |
fm.matchFewest = matchFewest; |
| 164 |
0 |
return fm; |
| 165 |
|
} catch (RegSyntax rs) |
| 166 |
|
{ |
| 167 |
0 |
return null; |
| 168 |
|
} |
| 169 |
|
} |
| 170 |
|
} |