| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.regex; |
| 9 |
|
| 10 |
import net.sf.saxon.om.SequenceIterator; |
| 11 |
import net.sf.saxon.value.StringValue; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
public class ATokenIterator implements SequenceIterator<StringValue> { |
| 18 |
|
| 19 |
private UnicodeString input; |
| 20 |
private REMatcher matcher; |
| 21 |
private UnicodeString current; |
| 22 |
private int prevEnd = 0; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public ATokenIterator(UnicodeString input, REMatcher matcher) { |
| 30 |
this.input = input; |
| 31 |
this.matcher = matcher; |
| 32 |
prevEnd = 0; |
| 33 |
} |
| 34 |
|
| 35 |
public StringValue next() { |
| 36 |
if (prevEnd < 0) { |
| 37 |
current = null; |
| 38 |
return null; |
| 39 |
} |
| 40 |
|
| 41 |
if (matcher.match(input, prevEnd)) { |
| 42 |
int start = matcher.getParenStart(0); |
| 43 |
current = input.uSubstring(prevEnd, start); |
| 44 |
prevEnd = matcher.getParenEnd(0); |
| 45 |
} else { |
| 46 |
current = input.uSubstring(prevEnd, input.uLength()); |
| 47 |
prevEnd = -1; |
| 48 |
} |
| 49 |
return currentStringValue(); |
| 50 |
} |
| 51 |
|
| 52 |
private StringValue currentStringValue() { |
| 53 |
return StringValue.makeStringValue(current); |
| 54 |
} |
| 55 |
|
| 56 |
public void close() { |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
} |
| 61 |
|