| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
package com.stevesoft.pat; |
| 9 |
|
|
| 10 |
|
import java.io.IOException; |
| 11 |
|
import java.io.Reader; |
| 12 |
|
|
| 13 |
|
import com.stevesoft.pat.wrap.StringBufferWrap; |
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| |
|
| 0% |
Uncovered Elements: 146 (146) |
Complexity: 41 |
Complexity Density: 0.47 |
|
| 21 |
|
public class RegexReader extends Reader |
| 22 |
|
{ |
| 23 |
|
RBuffer rb = new RBuffer(new StringBuffer()); |
| 24 |
|
|
| 25 |
|
PartialBuffer wrap = new PartialBuffer(rb.sb); |
| 26 |
|
|
| 27 |
|
boolean moreToRead = true; |
| 28 |
|
|
| 29 |
|
Reader r; |
| 30 |
|
|
| 31 |
|
Replacer rp; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
int nmax = 2 * 1024; |
| 35 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 36 |
0 |
public RegexReader(Regex rex, Reader r)... |
| 37 |
|
{ |
| 38 |
0 |
this.r = r; |
| 39 |
0 |
rp = rex.getReplacer(); |
| 40 |
|
} |
| 41 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 42 |
0 |
public RegexReader(Transformer tex, Reader r)... |
| 43 |
|
{ |
| 44 |
0 |
this.r = r; |
| 45 |
0 |
rp = tex.getReplacer(); |
| 46 |
|
} |
| 47 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 48 |
0 |
public void reset() throws IOException... |
| 49 |
|
{ |
| 50 |
0 |
r.reset(); |
| 51 |
0 |
rb = new RBuffer(new StringBuffer()); |
| 52 |
0 |
wrap = new PartialBuffer(rb.sb); |
| 53 |
0 |
moreToRead = true; |
| 54 |
|
} |
| 55 |
|
|
| |
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
| 56 |
0 |
void readData() throws IOException... |
| 57 |
|
{ |
| 58 |
0 |
int c; |
| 59 |
0 |
int n = 0; |
| 60 |
0 |
while ((c = r.read()) != -1) |
| 61 |
|
{ |
| 62 |
0 |
rb.sb.append((char) c); |
| 63 |
0 |
if (n++ > nmax) |
| 64 |
|
{ |
| 65 |
0 |
break; |
| 66 |
|
} |
| 67 |
|
} |
| 68 |
0 |
if (c == -1 && n == 0) |
| 69 |
|
{ |
| 70 |
0 |
moreToRead = false; |
| 71 |
0 |
wrap.allowOverRun = false; |
| 72 |
|
} |
| 73 |
|
} |
| 74 |
|
|
| |
|
| 0% |
Uncovered Elements: 68 (68) |
Complexity: 15 |
Complexity Density: 0.34 |
|
| 75 |
0 |
void getMoreData() throws IOException... |
| 76 |
|
{ |
| 77 |
0 |
while (rb.pos >= rb.epos) |
| 78 |
|
{ |
| 79 |
0 |
wrap.overRun = false; |
| 80 |
0 |
if (rb.next != null) |
| 81 |
|
{ |
| 82 |
0 |
rb = rb.next; |
| 83 |
|
} |
| 84 |
0 |
else if (rb.done) |
| 85 |
|
{ |
| 86 |
0 |
break; |
| 87 |
|
} |
| 88 |
0 |
else if (rb.epos >= rb.sb.length() && rb.epos > nmax) |
| 89 |
|
{ |
| 90 |
0 |
rb.pos = 1; |
| 91 |
0 |
rb.epos = 1; |
| 92 |
0 |
rb.sb.setLength(1); |
| 93 |
0 |
readData(); |
| 94 |
|
} |
| 95 |
0 |
else if (rb.epos >= rb.sb.length() && moreToRead) |
| 96 |
|
{ |
| 97 |
0 |
readData(); |
| 98 |
|
} |
| 99 |
0 |
else if (rp.getRegex().matchAt(wrap, rb.epos)) |
| 100 |
|
{ |
| 101 |
0 |
if (wrap.overRun) |
| 102 |
|
{ |
| 103 |
0 |
readData(); |
| 104 |
|
} |
| 105 |
|
else |
| 106 |
|
{ |
| 107 |
0 |
StringBufferWrap sbw = new StringBufferWrap(); |
| 108 |
0 |
StringBufferLike sbl = new StringBufferLike(sbw); |
| 109 |
|
|
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
0 |
Regex rex = rp.getRegex(); |
| 114 |
0 |
int npos = rex.matchedTo(); |
| 115 |
0 |
rp.setBuffer(sbl); |
| 116 |
0 |
rp.setSource(wrap); |
| 117 |
0 |
rp.setPos(npos); |
| 118 |
0 |
rp.apply(rex, rex.getReplaceRule()); |
| 119 |
0 |
int opos = rb.epos; |
| 120 |
0 |
RBuffer rb2 = new RBuffer((StringBuffer) sbw.unwrap()); |
| 121 |
0 |
rb2.epos = rb2.sb.length(); |
| 122 |
0 |
RBuffer rb3 = new RBuffer(rb.sb); |
| 123 |
|
|
| 124 |
0 |
rb.next = rb2; |
| 125 |
0 |
rb2.next = rb3; |
| 126 |
|
|
| 127 |
0 |
if (npos == opos) |
| 128 |
|
{ |
| 129 |
0 |
rb3.epos = npos + 1; |
| 130 |
0 |
if (rb3.epos > rb3.sb.length()) |
| 131 |
|
{ |
| 132 |
0 |
if (rb.pos >= rb.epos) |
| 133 |
|
{ |
| 134 |
0 |
rb = rb.next; |
| 135 |
|
} |
| 136 |
0 |
rb3.pos = rb3.epos = 0; |
| 137 |
0 |
rb3.done = true; |
| 138 |
|
|
| 139 |
|
} |
| 140 |
0 |
rb3.pos = npos; |
| 141 |
|
} |
| 142 |
|
else |
| 143 |
|
{ |
| 144 |
0 |
rb3.pos = rb3.epos = npos; |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
} |
| 148 |
|
} |
| 149 |
|
else |
| 150 |
|
{ |
| 151 |
0 |
if (wrap.overRun) |
| 152 |
|
{ |
| 153 |
0 |
readData(); |
| 154 |
|
} |
| 155 |
0 |
else if (rb.epos < rb.sb.length()) |
| 156 |
|
{ |
| 157 |
0 |
rb.epos++; |
| 158 |
|
} |
| 159 |
|
else |
| 160 |
|
{ |
| 161 |
0 |
break; |
| 162 |
|
} |
| 163 |
|
} |
| 164 |
|
} |
| 165 |
|
} |
| 166 |
|
|
| |
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 167 |
0 |
public int read() throws IOException... |
| 168 |
|
{ |
| 169 |
0 |
if (rb.pos >= rb.epos) |
| 170 |
|
{ |
| 171 |
0 |
getMoreData(); |
| 172 |
0 |
if (rb.pos >= rb.epos) |
| 173 |
|
{ |
| 174 |
0 |
return -1; |
| 175 |
|
} |
| 176 |
|
} |
| 177 |
|
|
| 178 |
0 |
return rb.sb.charAt(rb.pos++); |
| 179 |
|
} |
| 180 |
|
|
| |
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
| 181 |
0 |
public int read(char[] buf, int off, int len) throws IOException... |
| 182 |
|
{ |
| 183 |
0 |
int c = -1; |
| 184 |
0 |
int end = off + len; |
| 185 |
0 |
for (int i = off; i < end; i++) |
| 186 |
|
{ |
| 187 |
0 |
c = read(); |
| 188 |
0 |
if (c < 0) |
| 189 |
|
{ |
| 190 |
0 |
if (i == off) |
| 191 |
|
{ |
| 192 |
0 |
return -1; |
| 193 |
|
} |
| 194 |
0 |
return i - off; |
| 195 |
|
} |
| 196 |
0 |
buf[i] = (char) c; |
| 197 |
|
} |
| 198 |
0 |
return len; |
| 199 |
|
} |
| 200 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 201 |
0 |
public void close() throws IOException... |
| 202 |
|
{ |
| 203 |
0 |
r.close(); |
| 204 |
|
} |
| 205 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 206 |
0 |
public boolean markSupported()... |
| 207 |
|
{ |
| 208 |
0 |
return false; |
| 209 |
|
} |
| 210 |
|
|
| 211 |
|
|
| 212 |
|
|
| 213 |
|
|
| 214 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 215 |
0 |
public int getBufferSize()... |
| 216 |
|
{ |
| 217 |
0 |
return nmax; |
| 218 |
|
} |
| 219 |
|
|
| 220 |
|
|
| 221 |
|
|
| 222 |
|
|
| 223 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 224 |
0 |
public void setBufferSize(int n)... |
| 225 |
|
{ |
| 226 |
0 |
nmax = n; |
| 227 |
|
} |
| 228 |
|
|
| 229 |
|
int max_lines = 2; |
| 230 |
|
|
| 231 |
|
|
| 232 |
|
|
| 233 |
|
|
| 234 |
|
@deprecated |
| 235 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 236 |
0 |
@Deprecated... |
| 237 |
|
public int getMaxLines() |
| 238 |
|
{ |
| 239 |
0 |
return max_lines; |
| 240 |
|
} |
| 241 |
|
|
| 242 |
|
|
| 243 |
|
|
| 244 |
|
|
| 245 |
|
@deprecated |
| 246 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 247 |
0 |
@Deprecated... |
| 248 |
|
public void setMaxLines(int ml) |
| 249 |
|
{ |
| 250 |
0 |
max_lines = ml; |
| 251 |
|
} |
| 252 |
|
|
| 253 |
|
char EOLchar = '\n'; |
| 254 |
|
|
| 255 |
|
|
| 256 |
|
|
| 257 |
|
|
| 258 |
|
@deprecated |
| 259 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 260 |
0 |
@Deprecated... |
| 261 |
|
public char getEOLchar() |
| 262 |
|
{ |
| 263 |
0 |
return EOLchar; |
| 264 |
|
} |
| 265 |
|
|
| 266 |
|
|
| 267 |
|
|
| 268 |
|
|
| 269 |
|
@deprecated |
| 270 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 271 |
0 |
@Deprecated... |
| 272 |
|
public void setEOLchar(char c) |
| 273 |
|
{ |
| 274 |
0 |
EOLchar = c; |
| 275 |
|
} |
| 276 |
|
|
| |
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 277 |
0 |
public long skip(long d) throws IOException... |
| 278 |
|
{ |
| 279 |
|
|
| 280 |
|
|
| 281 |
0 |
long n = 0; |
| 282 |
0 |
while (n < d && read() != -1) |
| 283 |
|
{ |
| 284 |
0 |
n++; |
| 285 |
|
} |
| 286 |
0 |
return n; |
| 287 |
|
} |
| 288 |
|
|
| 289 |
|
|
| 290 |
|
|
| 291 |
|
|
| 292 |
|
|
| 293 |
|
|
| 294 |
|
|
| 295 |
|
|
| 296 |
|
|
| 297 |
|
|
| 298 |
|
|
| 299 |
|
|
| 300 |
|
|
| 301 |
|
|
| 302 |
|
|
| 303 |
|
|
| 304 |
|
|
| 305 |
|
|
| 306 |
|
|
| 307 |
|
|
| 308 |
|
|
| 309 |
|
|
| 310 |
|
|
| 311 |
|
|
| 312 |
|
|
| 313 |
|
|
| 314 |
|
} |