Created
February 24, 2013 12:27
-
-
Save FROGGS/5023634 to your computer and use it in GitHub Desktop.
patch for returning Nil for failed matches
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
diff --git a/src/core/Cursor.pm b/src/core/Cursor.pm | |
index 2654bfe..d6f81c8 100644 | |
--- a/src/core/Cursor.pm | |
+++ b/src/core/Cursor.pm | |
@@ -41,8 +41,11 @@ my class Cursor does NQPCursorRole { | |
method MATCH_SAVE() { | |
my $match := self.MATCH(); | |
- $last_match := $match if $match; | |
- $match; | |
+ if $match { | |
+ $last_match := $match; | |
+ return $match | |
+ } | |
+ Nil | |
} | |
# INTERPOLATE will iterate over the string $tgt beginning at position 0. | |
@@ -79,7 +82,7 @@ my class Cursor does NQPCursorRole { | |
$match := nqp::substr($tgt, $pos, $eos - $pos) ~~ $topic; | |
# In order to return the correct result we need to match from the | |
# current position only. | |
- next if $match.from; | |
+ next if !$match || $match.from; | |
$match := ~$match; | |
$len := nqp::chars( $match ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment