Package net.sf.saxon.regex
Class ARegexIterator
java.lang.Object
net.sf.saxon.regex.ARegexIterator
- All Implemented Interfaces:
- Closeable,- AutoCloseable,- LastPositionFinder,- SequenceIterator,- RegexIterator
Class ARegexIterator - provides an iterator over matched and unmatched substrings.
 This implementation of RegexIterator uses the modified Jakarta regular expression engine.
- 
Constructor SummaryConstructorsConstructorDescriptionARegexIterator(UnicodeString str, UnicodeString regex, REMatcher matcher) Construct a RegexIterator.
- 
Method SummaryModifier and TypeMethodDescriptionstatic IntToIntHashMapcomputeNestingTable(UnicodeString regex) Compute a table showing for each captured group number (opening paren in the regex), the number of its parent group.intGet the last position (that is, the number of items in the sequence).intGet the number of captured groupsgetRegexGroup(int number) Get a substring that matches a parenthesised group within the regular expressionbooleanDetermine whether the current item is a matching item or a non-matching itemnext()Get the next item in the sequencevoidProcess a matching substring, performing specified actions at the start and end of each captured subgroup.booleanAsk whether this iterator supports use of theLastPositionFinder.getLength()method.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.sf.saxon.om.SequenceIteratorclose
- 
Constructor Details- 
ARegexIteratorConstruct 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:
- str- the string to be analysed
- matcher- a matcher for the regular expression
 
 
- 
- 
Method Details- 
supportsGetLengthpublic boolean supportsGetLength()Description copied from interface:LastPositionFinderAsk whether this iterator supports use of theLastPositionFinder.getLength()method. This method should always be called before callingLastPositionFinder.getLength(), because an iterator that implements this interface may support use ofLastPositionFinder.getLength()in some situations and not in others- Specified by:
- supportsGetLengthin interface- LastPositionFinder
- Returns:
- true if the LastPositionFinder.getLength()method can be called to determine the length of the underlying sequence.
 
- 
getLengthpublic int getLength()Description copied from interface:LastPositionFinderGet 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 theLastPositionFinder.supportsGetLength()has been called and has returned true.- Specified by:
- getLengthin interface- LastPositionFinder
- Returns:
- the number of items in the sequence
 
- 
nextGet the next item in the sequence- Specified by:
- nextin interface- RegexIterator
- Specified by:
- nextin interface- SequenceIterator
- Returns:
- the next item in the sequence
 
- 
isMatchingpublic boolean isMatching()Determine whether the current item is a matching item or a non-matching item- Specified by:
- isMatchingin interface- RegexIterator
- 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
 
- 
getRegexGroupGet a substring that matches a parenthesised group within the regular expression- Specified by:
- getRegexGroupin interface- RegexIterator
- 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
 
- 
getNumberOfGroupspublic int getNumberOfGroups()Get the number of captured groups- Specified by:
- getNumberOfGroupsin interface- RegexIterator
 
- 
processMatchingSubstringProcess 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 theRegexMatchHandlermethods onGroupStart() and onGroupEnd().- Specified by:
- processMatchingSubstringin interface- RegexIterator
- Parameters:
- action- defines the processing to be performed at the start and end of a group
- Throws:
- XPathException
 
- 
computeNestingTableCompute a table showing for each captured group number (opening paren in the regex), the number of its parent group. This is done by reparsing the source of the regular expression. This is needed when the result of a match includes an empty group, to determine its position relative to other groups finishing at the same character position.
 
-