-
-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements RFC 044 : https://github.com/ponylang/rfcs/blob/master/text/0044-match-iter.md Closes #2093
- Loading branch information
1 parent
4383c13
commit edb72c4
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class MatchIterator is Iterator[Match] | ||
""" | ||
MatchIterator allows for calling code to repeatedly perform the same match | ||
against a subject string as an iterator. This lets callers repeat the match | ||
until no more matches exist. | ||
""" | ||
let _regex: Regex box | ||
let _subject: String | ||
var _offset: USize = 0 | ||
|
||
new create(regex': Regex box, subject': String, offset': USize = 0) => | ||
""" | ||
Creates a new Match Iterator from a regular expression and a subject | ||
string. | ||
""" | ||
_regex = regex' | ||
_subject = consume subject' | ||
_offset = offset' | ||
|
||
fun has_next() : Bool => | ||
""" | ||
Indicates whether there is another match available. | ||
""" | ||
try | ||
let m = _regex(_subject, _offset)? | ||
true | ||
else | ||
false | ||
end | ||
|
||
fun ref next(): Match ? => | ||
""" | ||
Yields the next match to the regular expression or produces | ||
an error if there is no match. | ||
""" | ||
let m = _regex(_subject, _offset)? | ||
_offset = m.end_pos() + 1 | ||
m | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters