1 | public int read() {↵ | | 1 | public int read() {↵
|
2 | // If we have buffered replace data, use it.↵ | | 2 | // If we have buffered replace data, use it.↵
|
3 | if ((buffer != null) && (bufpos < buffer.length())) {↵ | | 3 | if ((buffer != null) && (bufpos < buffer.length())) {↵
|
4 | return (int) buffer.charAt(bufpos++);↵ | | 4 | return (int) buffer.charAt(bufpos++);↵
|
5 | }↵ | | 5 | }↵
|
|
6 | // check if input is at a valid position↵ | | 6 | // check if input is at a valid position↵
|
7 | if (!stream.isValid()) return -1;↵ | | 7 | if (!stream.isValid()) return -1;↵
|
|
8 | REMatch mymatch = new REMatch(expr.getNumSubs(),offset,0);↵ | | 8 | REMatch mymatch = new REMatch(expr.getNumSubs(),offset,0);↵
|
9 | if (expr.match(stream, mymatch)) {↵ | | 9 | if (expr.match(stream,mymatch)) {↵
|
10 | mymatch.end[0] = mymatch.index;↵ | | 10 | mymatch.end[0] = mymatch.index;↵
|
11 | mymatch.finish(stream);↵ | | 11 | mymatch.finish(stream);↵
|
12 | stream.move(mymatch.toString().length());↵ | | 12 | stream.move(mymatch.toString().length());↵
|
13 | offset += mymatch.toString().length();↵ | | 13 | offset += mymatch.toString().length();↵
|
14 | buffer = mymatch.substituteInto(replace);↵ | | 14 | buffer = mymatch.substituteInto(replace);↵
|
15 | bufpos = 1;↵ | | 15 | bufpos = 1;↵
|
|
16 | // This is prone to infinite loops if replace string turns out empty.↵ | | |
|
17 | if (buffer.length() > 0) {↵ | | 16 | if (buffer.length() > 0) {↵
|
18 | return buffer.charAt(0);↵ | | 17 | return buffer.charAt(0);↵
|
19 | }↵ | | 18 | }↵
|
20 | }↵ | | 19 | }↵
|
21 | char ch = stream.charAt(0);↵ | | 20 | char ch = stream.charAt(0);↵
|
22 | if (ch == CharIndexed.OUT_OF_BOUNDS) return -1;↵ | | 21 | if (ch == CharIndexed.OUT_OF_BOUNDS) return -1;↵
|
23 | stream.move(1);↵ | | 22 | stream.move(1);↵
|
24 | offset++;↵ | | 23 | offset++;↵
|
25 | return ch;↵ | | 24 | return ch;↵
|
26 | }↵ | | 25 | }↵
|
|
27 | /** ↵ | | 26 | /** ↵
|
28 | * Returns false. REFilterInputStream does not support mark() and↵ | | 27 | * Returns false. REFilterReader does not support mark() and↵
|
29 | * reset() methods. ↵ | | 28 | * reset() methods. ↵
|
30 | */↵ | | 29 | */↵
|
31 | public boolean markSupported() {↵ | | 30 | public boolean markSupported() {↵
|
32 | return false;↵ | | 31 | return false;↵
|
33 | }↵ | | 32 | }↵
|
|
34 | /** Reads from the stream into the provided array. */↵ | | 33 | /** Reads from the stream into the provided array. */↵
|
35 | public int read(byte[] b, int off, int len) {↵ | | 34 | public int read(char[] b, int off, int len) {↵
|
36 | int i;↵ | | 35 | int i;↵
|
37 | int ok = 0;↵ | | 36 | int ok = 0;↵
|
38 | while (len-- > 0) {↵ | | 37 | while (len-- > 0) {↵
|
39 | i = read();↵ | | 38 | i = read();↵
|
40 | if (i == -1) return (ok == 0) ? -1 : ok;↵ | | 39 | if (i == -1) return (ok == 0) ? -1 : ok;↵
|
41 | b[off++] = (byte) i;↵ | | 40 | b[off++] = (char) i;↵
|
42 | ok++;↵ | | 41 | ok++;↵
|
43 | }↵ | | 42 | }↵
|
44 | return ok;↵ | | 43 | return ok;↵
|
45 | }↵ | | 44 | }↵
|
|
46 | /** Reads from the stream into the provided array. */↵ | | 45 | /** Reads from the stream into the provided array. */↵
|
47 | public int read(byte[] b) {↵ | | 46 | public int read(char[] b) {↵
|
48 | return read(b,0,b.length); | | 47 | return read(b,0,b.length);
|