Package net.sf.saxon.regex
Class JRegexIterator
- java.lang.Object
-
- net.sf.saxon.regex.JRegexIterator
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,LastPositionFinder
,SequenceIterator
,RegexIterator
public class JRegexIterator extends java.lang.Object implements RegexIterator, LastPositionFinder
Class JRegexIterator - provides an iterator over matched and unmatched substrings. This implementation of RegexIterator uses the JDK regular expression engine.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.sf.saxon.regex.RegexIterator
RegexIterator.MatchHandler
-
Nested classes/interfaces inherited from interface net.sf.saxon.om.SequenceIterator
SequenceIterator.Property
-
-
Constructor Summary
Constructors Constructor Description JRegexIterator(java.lang.String string, java.util.regex.Pattern pattern)
Construct a RegexIterator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getLength()
Get the last position (that is, the number of items in the sequence).int
getNumberOfGroups()
Get the number of captured groupsjava.util.EnumSet<SequenceIterator.Property>
getProperties()
Get properties of this iterator, as a bit-significant integer.java.lang.String
getRegexGroup(int number)
Get a substring that matches a parenthesised group within the regular expressionboolean
isMatching()
Determine whether the current item is a matching item or a non-matching itemStringValue
next()
Get the next item in the sequencevoid
processMatchingSubstring(RegexIterator.MatchHandler action)
Process a matching substring, performing specified actions at the start and end of each captured subgroup.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.om.SequenceIterator
close, forEachOrFail, materialize
-
-
-
-
Constructor Detail
-
JRegexIterator
public JRegexIterator(java.lang.String string, java.util.regex.Pattern pattern)
Construct a RegexIterator. Note that the underlying matcher.find() method is called once to obtain each matching substring. But the iterator also returns non-matching substrings if these appear between the matching substrings.- Parameters:
string
- the string to be analysedpattern
- the regular expression
-
-
Method Detail
-
getLength
public int getLength() throws XPathException
Description copied from interface:LastPositionFinder
Get the last position (that is, the number of items in the sequence). This method is non-destructive: it does not change the state of the iterator. The result is undefined if the next() method of the iterator has already returned null. This method must not be called unless the result of getProperties() on the iterator includes the bit settingSequenceIterator.Property.LAST_POSITION_FINDER
- Specified by:
getLength
in interfaceLastPositionFinder
- Returns:
- the number of items in the sequence
- Throws:
XPathException
- if an error occurs evaluating the sequence in order to determine the number of items
-
next
public StringValue next()
Get the next item in the sequence- Specified by:
next
in interfaceRegexIterator
- Specified by:
next
in interfaceSequenceIterator
- Returns:
- the next item in the sequence
-
getProperties
public java.util.EnumSet<SequenceIterator.Property> getProperties()
Get properties of this iterator, as a bit-significant integer.- Specified by:
getProperties
in interfaceSequenceIterator
- Returns:
- the properties of this iterator. This will be some combination of
properties such as
SequenceIterator.Property.GROUNDED
,SequenceIterator.Property.LAST_POSITION_FINDER
, andSequenceIterator.Property.LOOKAHEAD
. It is always acceptable to return the value zero, indicating that there are no known special properties. It is acceptable for the properties of the iterator to change depending on its state.
-
isMatching
public boolean isMatching()
Determine whether the current item is a matching item or a non-matching item- Specified by:
isMatching
in interfaceRegexIterator
- Returns:
- true if the current item (the one most recently returned by next()) is an item that matches the regular expression, or false if it is an item that does not match
-
getRegexGroup
public java.lang.String getRegexGroup(int number)
Get a substring that matches a parenthesised group within the regular expression- Specified by:
getRegexGroup
in interfaceRegexIterator
- Parameters:
number
- the number of the group to be obtained- Returns:
- the substring of the current item that matches the n'th parenthesized group within the regular expression
-
getNumberOfGroups
public int getNumberOfGroups()
Get the number of captured groups- Specified by:
getNumberOfGroups
in interfaceRegexIterator
-
processMatchingSubstring
public void processMatchingSubstring(RegexIterator.MatchHandler action) throws XPathException
Process a matching substring, performing specified actions at the start and end of each captured subgroup. This method will always be called when operating in "push" mode; it writes its result to context.getReceiver(). The matching substring text is all written to the receiver, interspersed with calls to the methods onGroupStart() and onGroupEnd().- Specified by:
processMatchingSubstring
in interfaceRegexIterator
- Parameters:
action
- defines the processing to be performed at the start and end of a group- Throws:
XPathException
-
-