1 | int read() {↵ | | 1 | 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.↵
|
16 | if (buffer.length() > 0) {↵ | | 17 | if (buffer.length() > 0) {↵
|
17 | return buffer.charAt(0);↵ | | 18 | return buffer.charAt(0);↵
|
18 | }↵ | | 19 | }↵
|
19 | }↵ | | 20 | }↵
|
20 | char ch = stream.charAt(0);↵ | | 21 | char ch = stream.charAt(0);↵
|
21 | if (ch == CharIndexed.OUT_OF_BOUNDS) return -1;↵ | | 22 | if (ch == CharIndexed.OUT_OF_BOUNDS) return -1;↵
|
22 | stream.move(1);↵ | | 23 | stream.move(1);↵
|
23 | offset++;↵ | | 24 | offset++;↵
|
24 | return ch;↵ | | 25 | return ch;↵
|
25 | }↵ | | 26 | }↵
|
|
26 | /** ↵ | | 27 | /** ↵
|
27 | * Returns false. REFilterReader does not support mark() and↵ | | 28 | * Returns false. REFilterInputStream does not support mark() and↵
|
28 | * reset() methods. ↵ | | 29 | * reset() methods. ↵
|
29 | */↵ | | 30 | */↵
|
30 | public boolean markSupported() {↵ | | 31 | public boolean markSupported() {↵
|
31 | return false;↵ | | 32 | return false;↵
|
32 | } | | 33 | }
|